1 BasicJava
1 BasicJava
Heart of the
processor :
Which does
all thinking
for the
computer
How does it
understand
this media ??
It only knows
the 0’s and 1’s
Most
elementary
form of
language for
software
development
Convert C code into assembly code Convert assembly code to machine code
Operating
+ Processor = Platform
System
2) Web Application
An application that runs on the server side and creates dynamic page, is called
web application. Currently, servlet, jsp, struts, jsf etc. technologies are used for
creating web applications in java.
4) Mobile Application
An application that is created for mobile devices. Currently Android and Java ME
are used for creating mobile applications.
22
History of Java
• Java history is interesting to know.
• The history of java starts from Green Team. Java team members (also known
as Green Team), initiated a revolutionary task to develop a language for digital
devices such as set-top boxes, televisions etc.
• For the green team members, it was an advance concept at that time. But, it was
suited for internet programming. Later, Java technology as incorporated by
Netscape.
• Currently, Java is used in internet programming, mobile devices, games, e-
business solutions etc. There are given the major points that describes the history
of java.
• Originally designed for small, embedded systems in electronic appliances like set-
top boxes.
• Firstly, it was called "Greentalk" by James Gosling and file extension was .gt.
• After that, it was called Oak and was developed as a part of the Green project.
• Why Oak? : Oak is a symbol of strength and chosen as a national tree of many
countries like U.S.A., France, Germany, Romania etc.
• In 1995, Oak was renamed as "Java" because it was already a trademark by Oak
Technologies.
• 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.
• According to James Gosling "Java was one of the top choices along with Silk".
• Since java was so unique, most of the team members preferred java.
• Java is an island of Indonesia where first coffee was produced (called java coffee).
Source: Wikipedia
• Multi-platform
• It can run on almost any computer platform
• Network-centric
• Designed with network in mind – “the network is the computer”
• Designed for building applications for the Internet
• Object-oriented
• It incorporates object-oriented programming model
§ The Java API is a set of libraries that you can use to accomplish tasks like
creating graphical user interfaces (GUIs), performing file input/output (I/O),
or establishing network communication.
JDK
JRE
MyProgram.java
Java API
Java Virtual Machine
Hardware - Based Platform
Hello
Hello Hello
World!
World! World!
• Porting the java system to any new platform involves writing an interpreter that
supports the Java Virtual Machine
• The interpreter will figure out what the equivalent machine dependent code to
run
Dr. KRUNAL N. PATEL (IT DEPARTMENT), MBIT 42
Java as High Performance
• JVM uses bytecodes
• Small binary class files
• Just-in-time Compilers
• Multithreading
• Native Methods
Just in
Java
Time
Interpreter
Java Compiler
Bytecodes
Java
move locally Virtual
Java
Compiler or through machine
network
Runtime System
Java
Operating System
Bytecode
(.class )
Dr. KRUNAL N. PATEL (IT DEPARTMENT), MBIT Hardware 49
Bytecode Verifier
• Called when class is first loaded in runtime environment
• Verifies bytecodes meet certain set of properties
• Verified code runs faster
• After verification, interpreter defines memory layout
• In C or C++, a program can walk off the edge of an array and invade
the memory space beyond.
• In this attack, the Hacker floods too much data into a buffer and
whatever overflows it is turned loose on the system.
All Code , both Local and Remote, Must Pass Security Policy
SANDBOX
Applications
Applets
We have added the method “main”. All methods are lower case. main is a special method--
it actually runs the program.
In any application, you are always guaranteed that method main will run.
Dr. KRUNAL N. PATEL (IT DEPARTMENT), MBIT 78
Compiling and Running a Java Program
To Compile:
C:>javac HelloWorld.java
To Run:
C:>java HelloWorld
O/P:
Hello World!
\t Horizontal tab
\r Carriage return
\n New line
\” Double quote
\\ Backslash
Example Formatting Codes
• Name of the online example: FormattingExample.java
• Example:
char myFirstInitial;
• All are binary operators, i.e., they work with two numbers. They are
executed according to the rules for operator precedence.
int x = 2;
double y = 3.889, sum = 0.000;
sum = y * x;
• The integer will be temporarily converted to a double and two doubles will
be multiplied.
• Afterwards, the original integer is unchanged.
Dr. KRUNAL N. PATEL (IT DEPARTMENT), MBIT 96
Java Math Operators
• Rules for Temporary Conversions
1st Priority: If either of the operands is of type double, then the other one is converted
to double for the calculation.
2nd Priority: Otherwise, if either of the operands is of type float, then the other one is
converted to float for the calculation.
3rd Priority: Otherwise, if any of the operands is of type long, then the other one is
converted to long for the calculation.
Note: these conversions are automatic because none of them result in a loss of accuracy.
Dr. KRUNAL N. PATEL (IT DEPARTMENT), MBIT 97
Java Math Operators
• Static Casts
So, what happens when you desire to convert a double to a float? Information will inevitably be
lost.
• You accomplish this using a cast.
Therefore: 17/3 = 5
Dr. KRUNAL N. PATEL (IT DEPARTMENT), MBIT 99
Java Math Operators
Modulus %
equality ==
not equal !=
greater than >
less than <
greater than or equal >=
less than or equal <=
num1 = 33;
Syntax:
import <Full library name>;
• Example:
import java.util.Scanner;