SlideShare a Scribd company logo
1 of 29
Getting Started
What is Java?
• 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.
What Else is Java?
• 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
Some History
• 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
What is Java?
• 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)
Features of Java
• Simple
• Architecture-neutral
• Object-Oriented
• Distributed
• Compiled
• Interpreted
• Statically Typed
• Multi-Threaded
• Garbage Collected
• Portable
• High-Performance
• Robust
• Secure
• Extensible
• Well-Understood
How Will Java Change My Life?
• 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
Java Applications and Java … lets
• 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
– …
Java Developer's Kit (I)
• Java's programming environment
– Core Java API
– compiler
– interpreter
– debugger
– dis-assembler
– profiler
– more...
Java Developer's Kit (II)
Java
Compiler
Java
Interpreter
Java Source Java Bytecode
Compile
Run
<file>.java <file>.class
Java
Dis-assembler
Prepare and Execute Java
Source Computer
Java Program Compilation Java ByteCode
Your computer
Java ByteCode Execution Restricted Env.
Verification
Internet
Write Once, Run Anywhere
ByteCode: Food for the VM
• 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
virtual machine
execution model of Java
source
(text) compiler
CPU
bytecode
interpreter
bytecode
interpreter
dynamic
loading
JIT
compiler
JIT
compiler
compiled
code
compiled
code
JVML
verifier
bytecode
(aka. class file)
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
• 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
Java Platform & VM & Devices
Java VM and API
• Java API and Virtual
Machine insulate the
Java program from
hardware
dependencies.
• Java API
Java API
• Collection of ready-
made software
components that
provide many useful
capabilities.
• Grouped into libraries
(packages) of related
components.
• Core API
– Essentials: Object,
String, Input and
Output...
– Applets
– Networking
– Internationalization
– Security
– Software Components
– Object Serialization
– Java Database
Connectivity (JDBC)
The “Hello World” Application
Create a Java Source File
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Compile and Run
• Compile
– javac HelloWorld.java
• One file named HelloWorld.class is
created if the compilation is succeeds.
• Run
– java HelloWorld
The Simplest Java Application:
Hello,World!
• 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.Each program is enclosed in a class definition.
main() is the first method that is run.main() is the first method that is run.
The notation class.method orThe notation class.method or
package.class.method is how topackage.class.method is how to
refer to a public method (withrefer to a public method (with
some exceptions).some exceptions).
Syntax is similar to C - braces forSyntax is similar to C - braces for
blocks, semicolon after eachblocks, semicolon after each
statement. One difference: upperstatement. One difference: upper
and lower case matter!and lower case matter!
The “Hello World” Applet
Create a Java Source File
HelloWorldApplet.java
• import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorldApplet extends
Applet {
public void paint(Graphics g) {
g.drawString(“Hello World!”, 5, 25);
}
}
Compile the Source File
• javac HelloWorldApplet.java
• One file named HelloWorldApplet.class is
created if the compilation is succeeds.
Displaying your applet from a Web page.
• Create an HTML file with an applet tag to display the results of
drawing the applet.
<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 andThe browser will use a rectangle of width 150 pixels and
height 25 pixels to display the applet within the other html.height 25 pixels to display the applet within the other html.
The Simplest Java Applet: Hello, World!
• 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.
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 methodsThe import statement allows the use of methods
from the Graphics class without the dot notation .from the Graphics class without the dot notation .
The paint method displays a graphics object on theThe paint method displays a graphics object on the
screen - one of the standard methods that takes thescreen - one of the standard methods that takes the
place of main for applets.place of main for applets.
Puts this as a subclass of Applet.Puts this as a subclass of Applet.
No main method
• Yes, applets have a main method...
• ...but it's in the browser, not in your code!
• More about that later in the course …

More Related Content

What's hot

Basic javaprogramming(session1)
Basic javaprogramming(session1)Basic javaprogramming(session1)
Basic javaprogramming(session1)
Barm Bannasan
 

What's hot (19)

Laravel introduction
Laravel introductionLaravel introduction
Laravel introduction
 
Laravel
LaravelLaravel
Laravel
 
Hire laravel-php-developers- Hire Laravel Programmers
Hire laravel-php-developers- Hire Laravel ProgrammersHire laravel-php-developers- Hire Laravel Programmers
Hire laravel-php-developers- Hire Laravel Programmers
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
Social Connections 2015 CrossWorlds and Domino
Social Connections 2015 CrossWorlds and DominoSocial Connections 2015 CrossWorlds and Domino
Social Connections 2015 CrossWorlds and Domino
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Getting started with laravel
Getting started with laravelGetting started with laravel
Getting started with laravel
 
Projects In Laravel : Learn Laravel Building 10 Projects
Projects In Laravel : Learn Laravel Building 10 ProjectsProjects In Laravel : Learn Laravel Building 10 Projects
Projects In Laravel : Learn Laravel Building 10 Projects
 
Advanced JAVA
Advanced JAVAAdvanced JAVA
Advanced JAVA
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Basic javaprogramming(session1)
Basic javaprogramming(session1)Basic javaprogramming(session1)
Basic javaprogramming(session1)
 
Georgia Tech Drupal Users Group - Local Drupal Development
Georgia Tech Drupal Users Group - Local Drupal DevelopmentGeorgia Tech Drupal Users Group - Local Drupal Development
Georgia Tech Drupal Users Group - Local Drupal Development
 
Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]Java script nirvana in netbeans [con5679]
Java script nirvana in netbeans [con5679]
 
PROGRAMMING IN JAVA- unit 5-part II
PROGRAMMING IN JAVA- unit 5-part IIPROGRAMMING IN JAVA- unit 5-part II
PROGRAMMING IN JAVA- unit 5-part II
 
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
S313265 - Advanced Java API for RESTful Web Services at JavaOne Brazil 2010
 
Java 8 in Anger (JavaOne)
Java 8 in Anger (JavaOne)Java 8 in Anger (JavaOne)
Java 8 in Anger (JavaOne)
 
Developing in the Cloud
Developing in the CloudDeveloping in the Cloud
Developing in the Cloud
 
Using Apache Camel as AKKA
Using Apache Camel as AKKAUsing Apache Camel as AKKA
Using Apache Camel as AKKA
 
Introduction to Node (15th May 2017)
Introduction to Node (15th May 2017)Introduction to Node (15th May 2017)
Introduction to Node (15th May 2017)
 

Similar to Java1

JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentation
juliasceasor
 

Similar to Java1 (20)

Java1 in mumbai
Java1 in mumbaiJava1 in mumbai
Java1 in mumbai
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentation
 
1 java intro
1 java intro1 java intro
1 java intro
 
Introduction to Java Programming.pdf
Introduction to Java Programming.pdfIntroduction to Java Programming.pdf
Introduction to Java Programming.pdf
 
MWLUG - Universal Java
MWLUG  -  Universal JavaMWLUG  -  Universal Java
MWLUG - Universal Java
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Bn1005 demo ppt core java
Bn1005 demo ppt core javaBn1005 demo ppt core java
Bn1005 demo ppt core java
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
JAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptxJAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptx
 
j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.ppt
 
CS8392 OOP
CS8392 OOPCS8392 OOP
CS8392 OOP
 
Java introduction
Java introductionJava introduction
Java introduction
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
oop unit1.pptx
oop unit1.pptxoop unit1.pptx
oop unit1.pptx
 
Advance java prasentation
Advance java prasentationAdvance java prasentation
Advance java prasentation
 
JAVA INTRODUCTION - 1
JAVA INTRODUCTION - 1JAVA INTRODUCTION - 1
JAVA INTRODUCTION - 1
 
Dr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to javaDr. Rajeshree Khande :Intoduction to java
Dr. Rajeshree Khande :Intoduction to java
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 

Java1

  • 2. What is Java? • 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.
  • 3. What Else is Java? • 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
  • 4. Some History • 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
  • 5. What is Java? • 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)
  • 6. Features of Java • Simple • Architecture-neutral • Object-Oriented • Distributed • Compiled • Interpreted • Statically Typed • Multi-Threaded • Garbage Collected • Portable • High-Performance • Robust • Secure • Extensible • Well-Understood
  • 7. How Will Java Change My Life? • 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
  • 8. Java Applications and Java … lets • 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 – …
  • 9. Java Developer's Kit (I) • Java's programming environment – Core Java API – compiler – interpreter – debugger – dis-assembler – profiler – more...
  • 10. Java Developer's Kit (II) Java Compiler Java Interpreter Java Source Java Bytecode Compile Run <file>.java <file>.class Java Dis-assembler
  • 11. Prepare and Execute Java Source Computer Java Program Compilation Java ByteCode Your computer Java ByteCode Execution Restricted Env. Verification Internet
  • 12. Write Once, Run Anywhere
  • 13. ByteCode: Food for the VM • 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
  • 14. virtual machine execution model of Java source (text) compiler CPU bytecode interpreter bytecode interpreter dynamic loading JIT compiler JIT compiler compiled code compiled code JVML verifier bytecode (aka. class file)
  • 15. 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
  • 16. Not just one JVM, but a whole family • 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
  • 17. Java Platform & VM & Devices
  • 18. Java VM and API • Java API and Virtual Machine insulate the Java program from hardware dependencies. • Java API
  • 19. Java API • Collection of ready- made software components that provide many useful capabilities. • Grouped into libraries (packages) of related components. • Core API – Essentials: Object, String, Input and Output... – Applets – Networking – Internationalization – Security – Software Components – Object Serialization – Java Database Connectivity (JDBC)
  • 20. The “Hello World” Application
  • 21. Create a Java Source File public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } }
  • 22. Compile and Run • Compile – javac HelloWorld.java • One file named HelloWorld.class is created if the compilation is succeeds. • Run – java HelloWorld
  • 23. The Simplest Java Application: Hello,World! • 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.Each program is enclosed in a class definition. main() is the first method that is run.main() is the first method that is run. The notation class.method orThe notation class.method or package.class.method is how topackage.class.method is how to refer to a public method (withrefer to a public method (with some exceptions).some exceptions). Syntax is similar to C - braces forSyntax is similar to C - braces for blocks, semicolon after eachblocks, semicolon after each statement. One difference: upperstatement. One difference: upper and lower case matter!and lower case matter!
  • 25. Create a Java Source File HelloWorldApplet.java • import java.applet.Applet; import java.awt.Graphics; public class HelloWorldApplet extends Applet { public void paint(Graphics g) { g.drawString(“Hello World!”, 5, 25); } }
  • 26. Compile the Source File • javac HelloWorldApplet.java • One file named HelloWorldApplet.class is created if the compilation is succeeds.
  • 27. Displaying your applet from a Web page. • Create an HTML file with an applet tag to display the results of drawing the applet. <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 andThe browser will use a rectangle of width 150 pixels and height 25 pixels to display the applet within the other html.height 25 pixels to display the applet within the other html.
  • 28. The Simplest Java Applet: Hello, World! • 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. 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 methodsThe import statement allows the use of methods from the Graphics class without the dot notation .from the Graphics class without the dot notation . The paint method displays a graphics object on theThe paint method displays a graphics object on the screen - one of the standard methods that takes thescreen - one of the standard methods that takes the place of main for applets.place of main for applets. Puts this as a subclass of Applet.Puts this as a subclass of Applet.
  • 29. No main method • Yes, applets have a main method... • ...but it's in the browser, not in your code! • More about that later in the course …