1 Java Introduction
1 Java Introduction
Language
Lory Al Moakar
Modified By: Manishkumar R Solanki 1-1
Topic Outcomes
1-2
Outline
History of Java
Magic of “Bytecode”
Java Buzzwords
Downloading, Installing and Configuring Java
Writing, Compiling and Executing Hello World
Program
1-3
Java History
Intel microprocessor
1-5
Java History
It was believed that the logical next step for
microprocessors was to have them run
intelligent consumer electronics
1-6
Java History
A platform-independent language that could be used to
create software to be embedded in various consumer
electronic devices, such as microwave ovens and remote
controls
C and C++ is that they are designed to be compiled for a
specific target
A full C++ compiler targeted for a particular CPU was
required
The compilers are expensive and time-consuming to create
An easier—and more cost-efficient—solution was needed.
Gosling and others began work on a portable, platform-
independent language that could be used to produce code
that would run on a variety of CPUs under differing
environments.
This effort ultimately led to the creation of Java
1-7
Java History
Sun Microsystems funded an internal research project
“Green” to investigate opportunity to create general
language for Embedded Systems in 1991
Result: After 18 months, first working version - “Oak”
1-8
Java History(Twist)
With the advent of the Internet and the Web, the problem
of portability returned.
The Internet consists of a diverse, distributed universe
populated with various types of computers, operating systems,
and CPUs.
Even though many kinds of platforms are attached to the
Internet, users would like them all to be able to run the
same program.
What was once an irritating but low priority problem had
become a high-profile necessity.
1-9
Java History(Twist)
In 1993, this realization caused the focus of Java to switch
from consumer electronics to Internet programming
In 1995, the team gathered to choose a new name.
The suggested words were "dynamic", "revolutionary", "Silk",
"jolt", "DNA" etc.
They wanted something that reflected the essence of the
technology: revolutionary, dynamic, lively, cool, unique, and
easy to spell and fun to say.
Final decision was : “Java”
Java is an island of Indonesia where first coffee was produced
(called java coffee)
1-
10
How Java Changed Internet?
Java Applets:
An applet is a special kind of Java program that is designed
to be transmitted over the Internet (downloaded) at client side
and automatically executed by a Java-compatible web
browser.
They are typically used to display data provided by the server,
handle user input, or provide simple functions, such as a loan
calculator, that execute locally, rather than on the server
1-11
Outline
History of Java
Magic of “Bytecode”
Java Buzzwords
Downloading, Installing and Configuring Java
Writing, Compiling and Executing Hello World
Program
1-
12
Java’s Magic: The Bytecode
The output of a Java compiler is not executable
code but a bytecode i.e. .class file.
Bytecode is a highly optimized set of instructions
designed to be executed by the Java run-time
system, which is called the Java Virtual Machine
(JVM)
The original JVM was designed as an interpreter for
bytecode.
Translating a Java program into bytecode makes it
executable on a wide variety of environments. (only
the JVM needs to be implemented for each
platform.)
Java’s Magic: The Bytecode
1-
14
Java’s Magic: The Bytecode
1-
15
Outline
History of Java
Magic of “Bytecode”
Java Buzzwords
Downloading, Installing and Configuring Java
Writing, Compiling and Executing Hello World
Program
1-
16
Java Buzzwords
Simple
Object-oriented
Robust
Portable
Secure
Architecture-neutral
Multithreaded
Interpreted & High performance
Distributed
Dynamic
1-
17
Java Buzzwords
Simple:
If you have some programming experience, you will not find
Java hard to master
If you are an experienced C++ programmer, moving to Java
will require very little effort.
Because Java inherits the C/C++ syntax and many of the object
oriented features of C++, most programmers have little trouble
learning Java.
1-
18
Java Buzzwords
Object Oriented:
Encapsulation
Abstraction
Inheritance
Polymorphism
1-
19
Java Buzzwords
Robust:
Java is a strictly typed language, it checks your code at compile
time as well at run time.
Memory management can be a difficult, tedious task in
traditional programming environments.
For example, in C/C++, the programmer will often manually
allocate and free all dynamic memory. This sometimes leads to
problems, if programmer forgets to free memory that has been
previously allocated.
Deallocation is completely automatic, because Java provides
garbage collection for unused objects.
Java provides object-oriented exception handling.
1-
20
Java Buzzwords
Portability:
Portability refers to the ability to run a program on different
machines.
1-
21
Java Buzzwords
Security:
Downloading Internet resources are prone to virus, Trojan
horse, or other harmful code.
1-
22
Java Buzzwords
Multithreaded:
Multithreading means dividing a program into executable sub
programs(threads) which can run concurrently. (parallelly)
Examples:
1. On a mobile home screen : wall paper, battery level,
signal strength, location, time, etc.
2. In a browser window: different tabs
3. In a word document: writing process, printing process,
spell check process, etc.
Applications: Gaming, Animation, Networking programs
1-
23
Java Buzzwords
Architecture-Neutral:
Operating system upgrades, processor upgrades, and changes in
core system resources do not affect the Java program
execution.
1-
24
Java Buzzwords
Distributed:
Java is designed for the distributed environment of the Internet
because it handles TCP/IP protocols. Accessing a resource
using a URL is not much different from accessing a file.
1-
25
Java Buzzwords
Dynamic:
It supports dynamic loading of classes.(classes are loaded on
demand.)
1-
26
Outline
History of Java
Magic of “Bytecode”
Java Buzzwords
Downloading, Installing and Configuring Java
Writing, Compiling and Executing Hello World
Program
1-
27
Downloading Java
URL: : http://www.oracle.com/technetwork/java/javase/downloads/index.html
1-
28
Downloading Java
1-
29
Installing Java
1-
30
Installing Java
https://www.guru99.com/install-java.html
1-
31
Installing Java
1-
32
Configuring Java [Setting PATH]
Step 1) Right Click on the My Computer and Select the properties
1-
33
Configuring Java [Setting PATH]
Step 2) Click on advanced system settings
1-
34
Configuring Java [Setting PATH]
Step 3) Click on Environment Variables
1-
35
Configuring Java [Setting PATH]
Step 4) Click on new Button of User variables
1-
36
Configuring Java [Setting PATH]
Step 5) Type PATH in the Variable name
1-
37
Configuring Java [Setting PATH]
Step 7) Paste Path of bin folder in Variable value and click on OK
Button.
1-
38
Configuring Java [Setting PATH]
Step 8) Click on OK button
1-
39
Configuring Java [Setting PATH]
Step 9) Go to command prompt and type javac commands.
If you see a screen like below, Java is installed and PATH is set
1-
40
Configuring Java
To see the version of Java installed : java -version
1-
41
Outline
History of Java
Magic of “Bytecode”
Java Buzzwords
Downloading, Installing and Configuring Java
Writing, Compiling and Executing Hello World
Program
1-
42
Java Program Structure
1-
43
Text Editors to write a Java Program
1-
44
IDEs to write a Java Program
1-
45
Writing “Hello World” Java Program
HelloWorld.java
class HelloWorld
{
public static void main (String args[])
{
System.out.println (“Hello World");
}
}
Note: Save the file with the name of class inside which
main( ) resides
1-
46
Java Program Structure
class body
1-
47
Java Program Structure
class HelloWorld
{
1-
48
Comments
Comments in a program are called inline
documentation
They should be included to explain the purpose
of the program and describe processing steps
They do not affect how a program works
Java comments can take three forms:
1-
49
Compiling “Hello World” Java Program
Open Command Prompt
Make a directory (inside which java programs
are residing) as working/present directory
Compile the program with javac program.java
1-
50
Executing “Hello World” Java Program
After successfully compilation of
program .class file (bytecode) is generated
To execute, we have to write : java
filename command
1-
51
Java Ecosystem
https://www.geeksforgeeks.org/differences-jdk-jre-jvm/
1-
52
JVM
JVM (Java Virtual Machine) is an abstract
machine. It is called virtual machine because it
doesn't physically exist.
It is a specification that provides runtime
environment in which java bytecode can be
executed
JVMs are available for many hardware and
software platforms. JVM, JRE and JDK are
platform dependent because configuration of
each OS are different from each other
Functions of JVM:
Loads code
Verifies code
Executes code
Provides runtime environment 1-
53
JRE
JRE is an acronym for Java Runtime
Environment
It is also written as Java RTE.
The Java Runtime Environment is a set of
software tools which are used for developing
java applications
It is used to provide runtime environment. It is
the implementation of JVM
It physically exists.
It contains set of libraries + other files that
JVM uses at runtime
1-
54
JDK
The Java Development Kit (JDK) is a software
development environment which is used to
develop java applications and applets.
It physically exists.
It contains JRE + development tools(i.e.
javac,java,jar,etc.)
JDK is an implementation of any one of the
below given Java Platforms released by Oracle
corporation:
Standard Edition Java Platform
Enterprise Edition Java Platform
Micro Edition Java Platform
1-
55
Credits
1-
56
You can find me at:
[email protected]
m