Sesion 1
Sesion 1
AND PROGRAMMING
4
Need for Java
• Many different types of controllers with different set of CPU are used in electronic
devices.
• The problem with C and C++ is that designed to be compiled for a specific target.
• An attempt to solve these problems, Gosling and others began work on a portable,
platform-independent language that on a variety of CPUs under differing
environments.
• Second force was the introduction of World wide web demand a language that
could useful in creating portable application.
5
Java Environment
JDK - Java Development Kit ( Program enable users to create java applications)
Setting Path
MyComputer -> Environment Variables ->Advanced -> Path -> C:\Jdk1.7\bin
OR
C:\mywork> set path=%path%;C:\Program Files\Java\jdk1.8.0_51\bin
6
Sample Helloworld application
/* Simple Helloworld Java application */
class test
{
public static void main(String[] args)
{
System.out.println(“Helloworld Java”);
}
}
// save it as test.java
Compile : javac test.java //new class file will be created in the name test.class
7
Sample Java Execution
8
Platform Independency
9
Java Features
• Simple & Familiar
• Object oriented
• Interpreted
• Portable
• Reliable
• Secure
• Multithreaded
• Dynamic
• Platform Independent
• Robust
• architecture-neutral
• Distributed
Java Features
• Simple & Familiar
– fixes some clumsy features of C++
– no pointers
– automatic garbage collection
– rich pre-defined class library
http://java.sun.com/j2se/1.4.2/docs/api/
• Java programming is easy to learn, easy to develop, easy to
execute. Never you will find java hard to master.
Robust
• Java has strict compile time and runtime checking for data
types.
Architecture-neutral
• Java is architecture-neutral:
Java Java
l e Compiler Interpreter
pi
m
n
Co
Ru
Java Source Java Bytecode
<file>.java <file>.class
Java
Dis-assembler
Prepare and Execute Java
Source Computer
Internet
Verification
Your computer
This machine is called the Java Virtual Machine and it exists only
inside the computer memory.
The interface that the JVM has to the .class file remains the same
irrespective of the underlying platform .
source bytecode
(text) compiler (aka. class file)
JVML
dynamic
loading
verifier
virtual machine
JIT compiled
bytecode code
compiler
interpreter
CPU
The JIT
• Just-In-Time compiler
• Translates bytecode into machine code at runtime
– 1-time overhead when run initiated
– Performance increase 10-30 times
• Now the default for most JVM’s
– Can be turned off if desired
– JIT can apply statistical optimizations based on runtime
usage profile
Not just one JVM, but a whole family
1. Application program
2. Applet program
Application programs are called console program, and
applet program is called web based program.
Difference between Application and Applet
Java technologies-JCP,JSR
What is JCP?
• The Java Community Process (JCP), established in 1998, is
a formalized mechanism that allows interested parties to
develop standard technical specifications for Java technology.