Semester III
BCA311 JAVA Programming
Introduction
(Unit-1)
Harshita Mathur
Department of Computer Science
Email : [email protected]
What is JAVA
• Java is a programming language and a platform.
• Java is a high level, robust, object-oriented and
secure programming language.
• Java was developed by Sun Microsystems in the
year 1995. James Gosling is known as the father of
Java.
• Platform: Any hardware or software environment in
which a program runs, is known as a platform. Since
Java has a runtime environment (JRE) and API, it is
called a platform.
Object Oriented Concepts in JAVA
object
• Any entity that has state and behavior is known as
an object. For example, a chair, pen, table,
keyboard, bike, etc. It can be physical or logical.
• An Object can be defined as an instance of a class.
An object contains an address and takes up some
space in memory.
• Objects can communicate without knowing the
details of each other's data or code. The only
necessary thing is the type of message accepted
and the type of response returned by the objects.
class
• Collection of objects is called class. It is a logical
entity.
• A class can also be defined as a blueprint from
which you can create an individual object. Class
doesn't consume any space.
Inheritance
• When one object acquires all the properties and
behaviors of a parent object, it is known as
inheritance.
• It provides code reusability. It is used to achieve
runtime polymorphism.
Polymorphism
• If one task is performed in different ways, it is
known as polymorphism.
• In Java, we use method overloading and method
overriding to achieve polymorphism.
.
Abstraction
• Hiding internal details and showing
functionality is known as abstraction.
• In Java, we use abstract class and interface to
achieve abstraction.
Encapsulation
• Binding (or wrapping) code and data together into
a single unit are known as encapsulation.
• A java class is the example of encapsulation.
Comparison of JAVA and C++
Comparison Index C++ JAVA
Platform- C++ is platform- Java is platform-
independent dependent. independent.
Mainly used for C++ is mainly used Java is mainly used
for system for application
programming. programming. It is
widely used in
window, web-based,
enterprise and mobile
applications.
Goto C++ supports Java doesn't support
the goto statement. the goto statement.
Comparison of JAVA and C++
Comparison Index C++ JAVA
Multiple C++ supports Java doesn't support
inheritance multiple inheritance. multiple inheritance
through class. It can
be achieved
by interfaces in java.
Operator C++ Java doesn't support
Overloading supports operator operator overloading.
overloading.
Pointers C++ Java supports pointer
supports pointers. You internally. However,
can write pointer you can't write the
program in C++. pointer program in
java. It means java
has restricted pointer
support in java.
Comparison of JAVA and C++
Comparison Index C++ JAVA
Compiler and C++ uses compiler Java uses compiler
Interpreter only. C++ is compiled and interpreter both.
and run using the Java source code is
compiler which converted into
converts source code bytecode at
into machine code so, compilation time. The
C++ is platform interpreter executes
dependent. this bytecode at
runtime and produces
output. Java is
interpreted.
Call by Value and C++ supports both Java supports call by
Call by reference call by value and call value only. There is no
by reference. call by reference in
java.
Comparison of JAVA and C++
Comparison Index C++ JAVA
Structure and C++ supports Java doesn't support
Union structures and unions. structures and unions.
Thread Support C++ doesn't have Java has built-
built-in support for in thread support.
threads. It relies on
third-party libraries
for thread support.
Object-oriented C++ is an object- Java is also an object-
oriented language. oriented language.
Features of JAVA
• Simple
• Object-Oriented
• Portable
• Platform independent
• Secured
• Robust
• Architecture neutral
• Interpreted
• High Performance
• Multithreaded
• Distributed
• Dynamic
Features of java: Simple
• Java is very easy to learn, and its syntax is simple, clean
and easy to understand.
• Java syntax is based on C++ (so easier for programmers
to learn it after C++).
• Java has removed many complicated and rarely-used
features, for example, explicit pointers, operator
overloading, etc.
• There is no need to remove unreferenced objects because
there is an Automatic Garbage Collection in Java.
Features of java: Object Oriented
• Java is an object-oriented programming language.
Everything in Java is an object.
• Object-oriented means we organize our software
as a combination of different types of objects that
incorporates both data and behavior.
Features of java: Portable
• Java is portable because it facilitates you to carry
the Java bytecode to any platform. It doesn't
require any implementation.
Features of java: Platform Independent
• Java code can be run on multiple platforms, for
example, Windows, Linux, Sun Solaris, Mac/OS,
etc.
• Java code is compiled by the compiler and
converted into bytecode. This bytecode is a
platform-independent code because it can be run
on multiple platforms, i.e., Write Once and Run
Anywhere(WORA).
Features of java: Secured
• Java is best known for its security. With Java, we
can develop virus-free systems. Java is secured
because:
. No explicit pointer
. Java Programs run inside a virtual
machine sandbox
Features of java: Robust
• It uses strong memory management.
• There is a lack of pointers that avoids security problems.
• There is automatic garbage collection in java which runs on
the Java Virtual Machine to get rid of objects which are not
being used by a Java application anymore.
• There are exception handling and the type checking
mechanism in Java. All these points make Java robust.
Features of java: Architecture Neutral
• Java is architecture neutral because there are no
implementation dependent features, for example,
the size of primitive types is fixed.
• In C programming, int data type occupies 2 bytes
of memory for 32-bit architecture and 4 bytes of
memory for 64-bit architecture. However, it
occupies 4 bytes of memory for both 32 and 64-
bit architectures in Java.
Features of java: Distributed
• Java is distributed because it facilitates users to
create distributed applications in Java.
• RMI and EJB are used for creating distributed
applications. This feature of Java makes us able to
access files by calling the methods from any
machine on the internet.
Features of java: Multi-threaded
• A thread is like a separate program, executing
concurrently. We can write Java programs that
deal with many tasks at once by defining multiple
threads.
• The main advantage of multi-threading is that it
doesn't occupy memory for each thread. It shares
a common memory area. Threads are important
for multi-media, Web applications, etc.
Features of java: Dynamic
• Java is a dynamic language. It supports dynamic
loading of classes. It means classes are loaded on
demand. It also supports functions from its native
languages, i.e., C and C++.