Lecture-1 Java SE
Lecture-1 Java SE
Lecture-1
Today’s Agenda
01 Necessity Of Programming
02 What Is Java ?
02
03 Important Features
03
04 History Of Java
04
05 Where Java stands today ?
05
06 Java Ecosystem
Why Do We Need Programming ?
•To remove security problems with “C” language , C++ language was designed.
•It is an Object Oriented Language which provides data security and can be used to
solve real world problems.
•Platform Independence
•Technology
Platform Independence
• PLATFORM
• A Platform is an environment in which a program runs.
• In simple terms it is combination of Operating system and
Processor.
Platform Operating
Processor
System
Windows Windows(3
Mac Linux
(32 bit) 2 bit)
Windows Linux
(64 bit) Mac Linux
Windows(3 Windows
Mac (64 bit) Linux
2 bit)
How many platforms are there in the figure ?
Answer:
Only 4
Windows
Windows Windows(3
Windows(
Mac Linux
Linux
(32 bit) 32
2 bit)
bit)
Windows
Windows
Linux
Linux Mac Linux
Linux
(64 bit)
bit)
Windows(3
Windows( Windows
Mac Linux
32
2 bit)
bit) (64 bit)
What makes it platform Independent?
• Program Execution in C/C++
Source
Code
Com-
piler
Win-
Linux
dows
Machine
Code
Program Execution in JAVA
Source Code
Compiler
Generates bytecode
True
False
QUIZ 5
• The JVM for every platform is different
True
False
Important Features
Platform Independent
Secure
Robust
Simple
Multithreaded
Distributed
Important Features
•Platform Independent
A platform is the environment in which an application runs.
And , Java has this capability using the concept of “bytecode” and “JVM”
Important Features
• Whenever we compile a java program , the compiler never generates
machine code.
Compiler
•This is how java makes itself “Platform Independent” and it also truly justifies
java’s slogan of “WORA”(Write Once Run Anywhere)
Important Features
•Automatic Memory Management
In languages like C and C++ any dynamic memory which the programmer
allocates using malloc( ) or new has to be deallocated by himself using free( ) or
delete
But Java uses runtime automatic garbage collection feature where the JVM itself
deallocates any dynamic memory which our program allocated.
Important Features
•Secure
Moreover all the programs in java are run under an area known as the
sand box.
This sandbox uses a bytecode verification process to ensure that code loade
does not violate Java security
constraints.
Important Features
Important Features
Robust
Java has very strict rules which every program must compulsorily follow and if these
rules are
violated then JVM kills/terminates the code by generating “Exception”
Important Features
int arr[5];
int i;
for(i=0;i<=9;i++)
{
arr[i]=i+1; // Unpredictable, after i is 5
}
Important Features
The previous code might show uncertain behaviour in C/C++ i.e. if memory is available
after arr[4] , then the code will run , otherwise it will generate error at runtime.
On the other hand if in java this code is executed, the JVM will kill the application
as soon as it finds the statement arr[5]=. . .
Reason is that in java we are not allowed to access any array beyond it’s
upper/lower index
Important Features
•Simple
Like it has removed pointers, multiple inheritance etc as developers of java language
found these features to be security threat and confusing.
Thus if we have basic understanding of C/C++ languages it is very easy to learn Java
Important Features
•Object Oriented
Encapsulation
Inheritance
Polymorphism
Abstraction
Important Features
•Multithreaded
In simple terms it means that we can execute more than one part of the same program
parallelly/simultaneously.
QUIZ 6
•Can we say that if we are surfing the internet using our browser and at the same time
we are listening to song in winamp, the it is multithreading ?
True
False
main()
{
clrscr();
factorial(5);
prime(8);
evenodd(4);
}
.
.
.
Important Features
•In the previous sample code all 4 functions clrscr(),factorial(),prime() and evenodd()
are independent of each other but still they will run sequentially i.e. one after the other.
•This can be improved in java by using multithreading feature so that each one of
these functions can run together.
When we use a media player to listen to a song , then there are multiple activities which
take place parallely like moving of a slider, elapsed time being shown, volume
adjustment , ability to add or remove songs from the playlist , playing of the song etc
Important Features
•Distributed
That is, different parts of the same program run on different computers and
communicate over a network.
Important Features
•In Java, this is made possible by a technique called RMI(Remote Method Invocation)
•RMI allows a method that is running on one computer to call a method in an object
that is on another computer.