0% found this document useful (0 votes)
14 views

Lecture 1

Uploaded by

Khushi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lecture 1

Uploaded by

Khushi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Introduction To Java Programming Language

(Elective-1)

Lecture 1
Today’s Agenda

An Introduction to JAVA

• Necessity Of Programming

• What Is Java ?

• Important Features

• History Of Java

• Where Java stands today ?

• Java Ecosystem
Why Do We Need Programming ?

• To communicate with digital machines and make them


work accordingly

• Today in the programming world , we have more than


750 languages available.

• And every language is designed to fulfill a particular


kind of requirement
Brief History Of Prog. Lang

 C language was primarily designed to develop “System


Softwares” like Operating Systems, Device Drivers etc .

 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.

 Many popular softwares like Adobe Acrobat , Winamp Media


Player,Internet Explorer,Mozilla Firefox etc were designed in
C++
Courtsey:http://www.stroustrup.com/applications.html
What is JAVA???...

 JAVA is a Technology(not only a programming


language) to develop Object oriented and
Platform Independent applications.

 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
System Processor

 Example:- Windows+Intel(i5), Ubuntu+AMD


How many physical machines are there in
the figure ? Answer:
12 Physical
Machines

Windows Windows(32
Mac Linux
(32 bit) bit)

Windows (64
Linux Mac Linux
bit)

Windows(3 Windows (64 Linux


Mac bit)
2 bit)
How many platforms are there in the figure ?
Answer:
Only 4

Windows Windows(32
Mac Linux
(32 bit) bit)

Windows (64
Linux Mac Linux
bit)

Windows(3 Windows (64 Linux


Mac bit)
2 bit)
What makes it platform
Independent?
 Program Execution in C/C++

Source Code

Compiler

Machine
Code Windows Linux
Program Execution in JAVA

Source Code

Compiler

Byte Code
JVM JVM JVM
MacOS
Windows Ubuntu
QUIZ 3

 What does JVM(Java Virtual Machine) do?

❑ Compiles the Java Source Code

❑ Generates bytecode

❑ Converts bytecode to underlying machine’s instruction set.

❑ Checks for error


QUIZ 4

 Java Compiler for every platform is different

❑ True

❑ False
QUIZ 5

 The JVM for every platform is different

❑ True

❑ False
Important Features

 Platform Independent

 Automatic Memory Management

 Secure

 Robust

 Simple

 Multithreaded

 Distributed
Important Features

 Platform Independent
A platform is the environment in which an application
runs.

In other words it is the combination of an OS and a CPU.

For example:
Windows 8+Intel - Core i5 (is a diff. platform)
Linux + AMD -A6(is another diff platform)
Mac + Intel -Core i3(is yet another diff
platform)
Important Features

 Now being platform independent means that an


application developed and compiled over one
platform can be executed over any other platform
without any change in the code.

 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.

 Rather it gnerates a machine independent code called the


“bytecode”.

 This bytecode is not directly understandable by the


platform(OS & CPU).

 So another special layer of software is required to convert


these bytecode instructions to machine dependent form
Important Features

 This special layer is the JVM , that converts the


bytecode to underlying machine instruction set and
runs it.
Important Features

class HelloWorld {
public static void main(String args[ ]) {
System.out.println(“Hello World!”);
} Java Program
}

Compiler

Interpreter Interpreter Interpreter

Hello
Hello Hello
World!
World! World!

Win32 Solaris MacOS 19


Important Features

 Thus any such platform for which a JVM is available


can be used to execute a Java application irrespective
of where it has been compiled.

 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

Java does not use pointers explicitly.

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 loaded 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

To understand java’s robustness , guess the output of


the following C/C++ code:

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

Java borrows most of it’s syntax from C/C++ languages.


Moreover it has inherited best points from these
languages and dropped others.

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

Java supports all important concepts of OOPs, like

Encapsulation
Inheritance
Polymorphism
Abstraction
Important Features

 Multithreaded

Multithreading means concurrent execution.

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

It is mutlitasking not multithreading


Important Features

 To understand this feature consider the code given below:

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.

 Benefits: Reduced execution time , full utilization of CPU


Important Features

 Some practical examples where multithreading is used


are:

 We can open multiple tabs in the same browser window

 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

Distributed programming a program uses more than


one computer.

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.

 Benefits: Programmers working on same project may


be required to be physically present at the same
location
Important Features

 Benefits: Programmers working on same project may


be required to be physically present at the same
location
History

 Developed By: James Gosling

 Company Name: Sun Microsystems,


now known as Oracle Sun.

 Original Name: Oak.


James Gosling
 First release: 23rd January 1996 and called
JDK(Java Development kit) 1.0
 Latest version : JDK 22 released on March, 19th
2024
Where Java Stands Today ?

https://softjourn.com/insights/is-java-still-used
Where Java Stands Today ?

 Do you know how many devices use Java ?

 3 Billion devices run Java as per Oracle. (1 Billion=


100Crores)
 1 Billion Java downloads per year.
JAVA Ecosystem
End Of Lecture 1

You might also like