SlideShare uma empresa Scribd logo
1 de 30
Getting Started with JAVA
Vibrant Technology & Computers
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.
Vibrant Technology & Computers
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
Vibrant Technology & Computers
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
Vibrant Technology & Computers
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) Vibrant Technology & Computers
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
Vibrant Technology & Computers
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
Vibrant Technology & Computers
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
– …
Vibrant Technology & Computers
Java Developer's Kit (I)
• Java's programming environment
– Core Java API
– compiler
– interpreter
– debugger
– dis-assembler
– profiler
– more...
Vibrant Technology & Computers
Java Developer's Kit (II)
Java
Compiler
Java
Interpreter
Java Source Java Bytecode
Compile
Run
<file>.java <file>.class
Java
Dis-assembler
Vibrant Technology & Computers
Prepare and Execute Java
Source Computer
Java Program Compilation Java ByteCode
Your computer
Java ByteCode Execution Restricted Env.
Verification
Internet
Vibrant Technology & Computers
Write Once, Run Anywhere
Vibrant Technology & Computers
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
Vibrant Technology & Computers
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)
Vibrant Technology & Computers
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
Vibrant Technology & Computers
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
Vibrant Technology & Computers
Java Platform & VM & Devices
Vibrant Technology & Computers
Java VM and API
• Java API and Virtual
Machine insulate the
Java program from
hardware
dependencies.
• Java API
Vibrant Technology & Computers
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)
Vibrant Technology & Computers
The “Hello World” Application
Vibrant Technology & Computers
Create a Java Source File
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Vibrant Technology & Computers
Compile and Run
• Compile
– javac HelloWorld.java
• One file named HelloWorld.class is
created if the compilation is succeeds.
• Run
– java HelloWorld
Vibrant Technology & Computers
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!Vibrant Technology & Computers
The “Hello World” Applet
Vibrant Technology & Computers
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);
}
}
Vibrant Technology & Computers
Compile the Source File
• javac HelloWorldApplet.java
• One file named HelloWorldApplet.class is
created if the compilation is succeeds.
Vibrant Technology & Computers
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.
Vibrant Technology & Computers
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.
Vibrant Technology & Computers
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 …
Vibrant Technology & Computers
Thank You…
Vibrant Technology & Computers

Mais conteúdo relacionado

Mais procurados (15)

Introduction to Java
Introduction to Java Introduction to Java
Introduction to Java
 
Programming in java ppt
Programming in java  pptProgramming in java  ppt
Programming in java ppt
 
Java introduction
Java introductionJava introduction
Java introduction
 
Lec 1-of-oop2
Lec 1-of-oop2Lec 1-of-oop2
Lec 1-of-oop2
 
Lec 3 01_aug13
Lec 3 01_aug13Lec 3 01_aug13
Lec 3 01_aug13
 
Javantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin ToshevJavantura v4 - JVM++ The GraalVM - Martin Toshev
Javantura v4 - JVM++ The GraalVM - Martin Toshev
 
core java
core javacore java
core java
 
Lesson1 intro
Lesson1 introLesson1 intro
Lesson1 intro
 
L1 basics
L1 basicsL1 basics
L1 basics
 
Java Tutorial to Learn Java Programming
Java Tutorial to Learn Java ProgrammingJava Tutorial to Learn Java Programming
Java Tutorial to Learn Java Programming
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Sadiq786
Sadiq786Sadiq786
Sadiq786
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Features of java
Features of javaFeatures of java
Features of java
 
A tour of Java and the JVM
A tour of Java and the JVMA tour of Java and the JVM
A tour of Java and the JVM
 

Semelhante a Java1 in mumbai

MWLUG - Universal Java
MWLUG  -  Universal JavaMWLUG  -  Universal Java
MWLUG - Universal JavaPhilippe Riand
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentationjuliasceasor
 
j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.pptSmitaBorkar9
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsQUONTRASOLUTIONS
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept Prakash Poudel
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introductionjyoti_lakhani
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operatorkamal kotecha
 
Lecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 FastLecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 FastUzairSaeed18
 
J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01Jay Palit
 
Java basics notes
Java basics notesJava basics notes
Java basics notesNexus
 

Semelhante a Java1 in mumbai (20)

Java1
Java1Java1
Java1
 
Java1
Java1Java1
Java1
 
MWLUG - Universal Java
MWLUG  -  Universal JavaMWLUG  -  Universal Java
MWLUG - Universal Java
 
JavaClassPresentation
JavaClassPresentationJavaClassPresentation
JavaClassPresentation
 
j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.ppt
 
Core java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutionsCore java over view basics introduction by quontra solutions
Core java over view basics introduction by quontra solutions
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
 
Java Programming concept
Java Programming concept Java Programming concept
Java Programming concept
 
1 java intro
1 java intro1 java intro
1 java intro
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
basic core java up to operator
basic core java up to operatorbasic core java up to operator
basic core java up to operator
 
Java Introduction
Java IntroductionJava Introduction
Java Introduction
 
Lecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 FastLecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 Fast
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
unit1.pptx
unit1.pptxunit1.pptx
unit1.pptx
 
J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01J2ee strutswithhibernate-140121221332-phpapp01
J2ee strutswithhibernate-140121221332-phpapp01
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Comp102 lec 3
Comp102   lec 3Comp102   lec 3
Comp102 lec 3
 

Último

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 

Último (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Java1 in mumbai

  • 1. Getting Started with JAVA Vibrant Technology & Computers
  • 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. Vibrant Technology & Computers
  • 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 Vibrant Technology & Computers
  • 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 Vibrant Technology & Computers
  • 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) Vibrant Technology & Computers
  • 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 Vibrant Technology & Computers
  • 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 Vibrant Technology & Computers
  • 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 – … Vibrant Technology & Computers
  • 9. Java Developer's Kit (I) • Java's programming environment – Core Java API – compiler – interpreter – debugger – dis-assembler – profiler – more... Vibrant Technology & Computers
  • 10. Java Developer's Kit (II) Java Compiler Java Interpreter Java Source Java Bytecode Compile Run <file>.java <file>.class Java Dis-assembler Vibrant Technology & Computers
  • 11. Prepare and Execute Java Source Computer Java Program Compilation Java ByteCode Your computer Java ByteCode Execution Restricted Env. Verification Internet Vibrant Technology & Computers
  • 12. Write Once, Run Anywhere Vibrant Technology & Computers
  • 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 Vibrant Technology & Computers
  • 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) Vibrant Technology & Computers
  • 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 Vibrant Technology & Computers
  • 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 Vibrant Technology & Computers
  • 17. Java Platform & VM & Devices Vibrant Technology & Computers
  • 18. Java VM and API • Java API and Virtual Machine insulate the Java program from hardware dependencies. • Java API Vibrant Technology & Computers
  • 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) Vibrant Technology & Computers
  • 20. The “Hello World” Application Vibrant Technology & Computers
  • 21. Create a Java Source File public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } Vibrant Technology & Computers
  • 22. Compile and Run • Compile – javac HelloWorld.java • One file named HelloWorld.class is created if the compilation is succeeds. • Run – java HelloWorld Vibrant Technology & Computers
  • 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!Vibrant Technology & Computers
  • 24. The “Hello World” Applet Vibrant Technology & Computers
  • 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); } } Vibrant Technology & Computers
  • 26. Compile the Source File • javac HelloWorldApplet.java • One file named HelloWorldApplet.class is created if the compilation is succeeds. Vibrant Technology & Computers
  • 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. Vibrant Technology & Computers
  • 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. Vibrant Technology & Computers
  • 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 … Vibrant Technology & Computers