Java Lab Lecture-1
Java Lab Lecture-1
JAVA
History of Java
With the invention of internet and world
wide web there is need of a language that
should be platform independent.
On internet we don't know in advance at what
platform our code or program /application
will be executed as all over the world there
are heterogeneous systems.
JAVA was developed by Sun
Microsystems in 1991.earlier it
was called “Oak” but was
renamed Java in 1995
Compiler
For UNIX we can use CC/GCC compiler
In case of platform independent
compilation(NO DEPENDENCY ON
OS) user don't know at what
platform his code is going to
compile
JAVA VIRTUAL MACHINE is the
solution for platform independent
compilation
WHAT IS JVM?
Specification designed by SUN Microsystems
1. Instruction set
2. File format
Either it is on ,off,dim,bright
Light is on
Light is off
Light is bright
Light is Dim
Here Light is class
lt is object
the name of the type/class is Light,
the name of this particular Light object is lt,
and the requests that you can make of a Light object
are to turn it on,
turn it off,
make it brighter,
or make it dimmer.
You
create a Light object by defining a “reference” (lt) for that
object and calling new to request a new object of that type.
Object orientation
it is the way of thinking in terms of object on
the basis of this thinking a programming
model created by sun micro system in known
as object oriented programming structure
SUN MicroSystem is a microelectronics
and microprocessor?
Why they need platform independent
language?
Java's main features are
1. Platform independent.
2. Security
If any language is platform
dependent then
For each platform we have to write a new
code.
If a company is making 100 microcontroller
3. Object-Oriented
4. Robust(Java is robust because it is highly supported language, meaning that unlike C
you cannot crash your computer with a bad program)
5. Multithreaded
6. Architectural Neutral
(binary code format" that's independent of hardware
architectures, operating system interfaces, and window systems)
7. Interpreted.
8. High-performance
(Just in time compilation)
9. Distributed (development of application to run over network always
need distributed languages)
10. Dynamic (During the execution of a program, Java can dynamically
load class libraries )
Limitation of Java
It is slow in comparison of C/C++.because it is
both compiled and interpreted language.
Applet cannot access local data. Only download
the data from site where applet is located.
No use of pointer so we cannot do flexible data
structure design.
Need different JVM for different platform.
It is strictly types language (every variable have
type, every expression has type) so there is no
flexibility in programming.
Difference between C ++ and Java
JAVA C++
1 Java is completely object oriented C++ is extension of C with object oriented
language behavior
2 Java does not support multiple C++ support multiple inheritance
inheritances. But it can be achieved
using interface if needed.
3 Java does not support global Global variable can be declared in C++
variable
4 Java does not support pointer. C++ support pointers.
5 In Java there is no destructor. In C++ there is use of destructor
6 Java does not provide header file C++ has header file.
7 Java code run on Virtual machine C++ code runs on actual machine
(JVM)
8 In java automatic memory Memory management is done manually by
management and garbage collection new/delete.
9 Write once run any where Write once compile anywhere
Types of Inheritance in Java
1 Single Inheritance
2 Multiple Inheritance
3 Multilevel Inheritance
4 Hierarchical Inheritance
5 Hybrid Inheritance
Single Inheritance