SlideShare a Scribd company logo
Contact Us On :
www.vibranttechnologies.co.in
Contact Us On :
www.vibranttechnologies.co.in
 What is Java?
 Features of Java
 How Will Java Change My Life?
 Java Applications and Java …
 Java Developer's Kit
 Prepare and Execute Java
 Write Once, Run Anywhere
 Byte Code: Food for the VM
 Java Application & Applet
Contact Us On :
www.vibranttechnologies.co.in
 A programming language
◦ Fully buzzword-compliant:
A simple, object oriented, distributed,
interpreted, robust, secure, architecture neutral,
portable, high performance, multithreaded,
dynamic language.
From: Java: An Overview
James Gosling, Sun Microsystems,
February 1995.
Contact Us On :
www.vibranttechnologies.co.in
 According to Gosling:
◦ “An environment”
◦ “A platform”
◦ “A way of thinking”
◦ …ok, whatever
 Java is a phenomenon
◦ Took the world by storm in 1995 when
introduced with the HotJava web Browser
◦ Quickly integrated with Netscape browser
Contact Us On :
www.vibranttechnologies.co.in
 1993 Oak project at Sun
◦ small, robust, architecture independent, Object-Oriented,
language to control interactive TV.
◦ didn’t go anywhere
 1995 Oak becomes Java
◦ Focus on the web
 1996 Java 1.0 available
 1997 (March) Java 1.1 - some language changes, much larger
library, new event handling model
 1997 (September) Java 1.2 beta – huge increase in libraries
including Swing, new collection classes, J2EE
 1998 (October) Java 1.2 final (Java2!)
 2000 (April) Java 1.3 final
 2001 Java 1.4 final (assert)
 2004 Java 1.5 (parameterized types, enum, …) (Java5!)
 2005 J2EE 1.5
Contact Us On :
www.vibranttechnologies.co.in
 Java is a general-purpose, high-level
programming language.
◦ The features of Java
 Java program is both compiled and interpreted.
 Write once, run anywhere
 Java is a software-only platform running on
top of other, hardware-based platforms.
◦ Java Virtual Machine (Java VM)
◦ The Java Application Programming Interface
(JAVA API)
Contact Us On :
www.vibranttechnologies.co.in
 Get started quickly
 Write less code
 Write better code
 Develop programs faster
 Avoid platform dependencies with 100% pure
Java
 Write once, run anywhere
 Distribute software more easily
Contact Us On :
www.vibranttechnologies.co.in
 Stand-alone Applications
◦ Just like any programming language
 Applet
◦ Run under a Java-Enabled Browser
 Midlet
◦ Run in a Java-Enabled Mobile Phone
 Servlet
◦ Run on a Java-Enabled Web Server
 Switchlet
◦ …
Contact Us On :
www.vibranttechnologies.co.in
 Java's programming environment
◦ Core Java API
◦ compiler
◦ interpreter
◦ debugger
◦ dis-assembler
◦ profiler
◦ more...
Contact Us On :
www.vibranttechnologies.co.in
 For most languages, compilation produces
machine code
 Java compilation produces “bytecode”
◦ Intermediate code readable by the VM
◦ Transferable across the Internet as applets
 VM interprets BC into instructions
◦ Partly responsible for performance lag
 ByteCode produced on any platform may
be executed on any other platform which
supports a VM
Contact Us On :
www.vibranttechnologies.co.in
virtual machine
Contact Us On :
www.vibranttechnologies.co.in
source
(text) compiler
CPU
bytecode
interpreter
dynamic
loading
JIT
compiler
compiled
code
JVML
verifier
bytecode
(aka. class file)
 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
Contact Us On :
www.vibranttechnologies.co.in
 JVM (J2EE & J2SE)
◦ Well-known Java Virtual Machine.
 CVM, KVM (J2ME)
◦ Small devices.
◦ Reduces some VM features to fit resource-
constrained devices.
 JCVM (Java Card)
◦ Smart cards.
◦ It has least VM features.
 And there are also lots of other JVMs
Contact Us On :
www.vibranttechnologies.co.in
Contact Us On :
www.vibranttechnologies.co.in
 Java API and Virtual
Machine insulate
the Java program
from hardware
dependencies.
 Java API
Contact Us On :
www.vibranttechnologies.co.in
Contact Us On :
www.vibranttechnologies.co.in
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Contact Us On :
www.vibranttechnologies.co.in
 Compile
◦ javac HelloWorld.java
 One file named HelloWorld.class is created if
the compilation is succeeds.
 Run
◦ java HelloWorld
Contact Us On :
www.vibranttechnologies.co.in
 Since Java is object-oriented, programs are organized into
modules called classes, which may have data in variables and
subroutines called methods.
class HelloWorld
{ public static void main (String[] args)
{ System.out.println(“Hello World!”);
}
}
Each program is enclosed in a class definition.
main() is the first method that is run.
The notation class.method or
package.class.method is how to refer
to a public method (with some
exceptions).
Syntax is similar to C - braces for
blocks, semicolon after each statement.
One difference: upper and lower case
matter!
Contact Us On :
www.vibranttechnologies.co.in
 import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorldApplet extends Applet {
public void paint(Graphics g) {
g.drawString(“Hello World!”, 5, 25);
}
}
Contact Us On :
www.vibranttechnologies.co.in
 javac HelloWorldApplet.java
 One file named HelloWorldApplet.class is
created if the compilation is succeeds.
Contact Us On :
www.vibranttechnologies.co.in
 Create an HTML file with an applet tag to display the results
of drawing the applet.
Contact Us On :
www.vibranttechnologies.co.in
<html><head>
<title>Simple Hello Page</title>
</head>
<body>
My Java applet says:
<applet code=“HelloWorldApplet.class” width=150 height=25>
</applet>
</body></html>
Name of your applet class.
The browser will use a rectangle of width 150 pixels and height 25
pixels to display the applet within the other html.
 Java applets are part of the class hierarchy that can call methods
to display on a screen (within the browser window). One way to
draw on the screen is to call the method drawString from the
standard method paint.
Contact Us On :
www.vibranttechnologies.co.in
import java.awt.Graphics;
public class HelloWorldApplet extends java.applet.Applet
{ public void paint (Graphics g)
{ g.drawString(“Hello World!”, 5, 25);
}
}
The import statement allows the use of methods from
the Graphics class without the dot notation .
The paint method displays a graphics object on the
screen - one of the standard methods that takes the place
of main for applets.
Puts this as a subclass of Applet.
 Yes, applets have a main method...
 ...but it's in the browser, not in your code!
 More about that later in the course …
Contact Us On :
www.vibranttechnologies.co.in
Contact Us On :
www.vibranttechnologies.co.in

More Related Content

professional core java trainer

  • 1. Contact Us On : www.vibranttechnologies.co.in
  • 2. Contact Us On : www.vibranttechnologies.co.in
  • 3.  What is Java?  Features of Java  How Will Java Change My Life?  Java Applications and Java …  Java Developer's Kit  Prepare and Execute Java  Write Once, Run Anywhere  Byte Code: Food for the VM  Java Application & Applet Contact Us On : www.vibranttechnologies.co.in
  • 4.  A programming language ◦ Fully buzzword-compliant: A simple, object oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high performance, multithreaded, dynamic language. From: Java: An Overview James Gosling, Sun Microsystems, February 1995. Contact Us On : www.vibranttechnologies.co.in
  • 5.  According to Gosling: ◦ “An environment” ◦ “A platform” ◦ “A way of thinking” ◦ …ok, whatever  Java is a phenomenon ◦ Took the world by storm in 1995 when introduced with the HotJava web Browser ◦ Quickly integrated with Netscape browser Contact Us On : www.vibranttechnologies.co.in
  • 6.  1993 Oak project at Sun ◦ small, robust, architecture independent, Object-Oriented, language to control interactive TV. ◦ didn’t go anywhere  1995 Oak becomes Java ◦ Focus on the web  1996 Java 1.0 available  1997 (March) Java 1.1 - some language changes, much larger library, new event handling model  1997 (September) Java 1.2 beta – huge increase in libraries including Swing, new collection classes, J2EE  1998 (October) Java 1.2 final (Java2!)  2000 (April) Java 1.3 final  2001 Java 1.4 final (assert)  2004 Java 1.5 (parameterized types, enum, …) (Java5!)  2005 J2EE 1.5 Contact Us On : www.vibranttechnologies.co.in
  • 7.  Java is a general-purpose, high-level programming language. ◦ The features of Java  Java program is both compiled and interpreted.  Write once, run anywhere  Java is a software-only platform running on top of other, hardware-based platforms. ◦ Java Virtual Machine (Java VM) ◦ The Java Application Programming Interface (JAVA API) Contact Us On : www.vibranttechnologies.co.in
  • 8.  Get started quickly  Write less code  Write better code  Develop programs faster  Avoid platform dependencies with 100% pure Java  Write once, run anywhere  Distribute software more easily Contact Us On : www.vibranttechnologies.co.in
  • 9.  Stand-alone Applications ◦ Just like any programming language  Applet ◦ Run under a Java-Enabled Browser  Midlet ◦ Run in a Java-Enabled Mobile Phone  Servlet ◦ Run on a Java-Enabled Web Server  Switchlet ◦ … Contact Us On : www.vibranttechnologies.co.in
  • 10.  Java's programming environment ◦ Core Java API ◦ compiler ◦ interpreter ◦ debugger ◦ dis-assembler ◦ profiler ◦ more... Contact Us On : www.vibranttechnologies.co.in
  • 11.  For most languages, compilation produces machine code  Java compilation produces “bytecode” ◦ Intermediate code readable by the VM ◦ Transferable across the Internet as applets  VM interprets BC into instructions ◦ Partly responsible for performance lag  ByteCode produced on any platform may be executed on any other platform which supports a VM Contact Us On : www.vibranttechnologies.co.in
  • 12. virtual machine Contact Us On : www.vibranttechnologies.co.in source (text) compiler CPU bytecode interpreter dynamic loading JIT compiler compiled code JVML verifier bytecode (aka. class file)
  • 13.  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 Contact Us On : www.vibranttechnologies.co.in
  • 14.  JVM (J2EE & J2SE) ◦ Well-known Java Virtual Machine.  CVM, KVM (J2ME) ◦ Small devices. ◦ Reduces some VM features to fit resource- constrained devices.  JCVM (Java Card) ◦ Smart cards. ◦ It has least VM features.  And there are also lots of other JVMs Contact Us On : www.vibranttechnologies.co.in
  • 15. Contact Us On : www.vibranttechnologies.co.in
  • 16.  Java API and Virtual Machine insulate the Java program from hardware dependencies.  Java API Contact Us On : www.vibranttechnologies.co.in
  • 17. Contact Us On : www.vibranttechnologies.co.in
  • 18. public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } Contact Us On : www.vibranttechnologies.co.in
  • 19.  Compile ◦ javac HelloWorld.java  One file named HelloWorld.class is created if the compilation is succeeds.  Run ◦ java HelloWorld Contact Us On : www.vibranttechnologies.co.in
  • 20.  Since Java is object-oriented, programs are organized into modules called classes, which may have data in variables and subroutines called methods. class HelloWorld { public static void main (String[] args) { System.out.println(“Hello World!”); } } Each program is enclosed in a class definition. main() is the first method that is run. The notation class.method or package.class.method is how to refer to a public method (with some exceptions). Syntax is similar to C - braces for blocks, semicolon after each statement. One difference: upper and lower case matter!
  • 21. Contact Us On : www.vibranttechnologies.co.in
  • 22.  import java.applet.Applet; import java.awt.Graphics; public class HelloWorldApplet extends Applet { public void paint(Graphics g) { g.drawString(“Hello World!”, 5, 25); } } Contact Us On : www.vibranttechnologies.co.in
  • 23.  javac HelloWorldApplet.java  One file named HelloWorldApplet.class is created if the compilation is succeeds. Contact Us On : www.vibranttechnologies.co.in
  • 24.  Create an HTML file with an applet tag to display the results of drawing the applet. Contact Us On : www.vibranttechnologies.co.in <html><head> <title>Simple Hello Page</title> </head> <body> My Java applet says: <applet code=“HelloWorldApplet.class” width=150 height=25> </applet> </body></html> Name of your applet class. The browser will use a rectangle of width 150 pixels and height 25 pixels to display the applet within the other html.
  • 25.  Java applets are part of the class hierarchy that can call methods to display on a screen (within the browser window). One way to draw on the screen is to call the method drawString from the standard method paint. Contact Us On : www.vibranttechnologies.co.in import java.awt.Graphics; public class HelloWorldApplet extends java.applet.Applet { public void paint (Graphics g) { g.drawString(“Hello World!”, 5, 25); } } The import statement allows the use of methods from the Graphics class without the dot notation . The paint method displays a graphics object on the screen - one of the standard methods that takes the place of main for applets. Puts this as a subclass of Applet.
  • 26.  Yes, applets have a main method...  ...but it's in the browser, not in your code!  More about that later in the course … Contact Us On : www.vibranttechnologies.co.in
  • 27. Contact Us On : www.vibranttechnologies.co.in