Getting Started What is Java?


Java Developer's Kit (II)


Download 264.5 Kb.
bet3/3
Sana08.01.2022
Hajmi264.5 Kb.
#250343
1   2   3
Bog'liq
Java1 (1)

Java Developer's Kit (II)

  • Java
  • Compiler
  • Java
  • Interpreter
  • Java Source
  • Java Bytecode
  • Compile
  • Run
  • .java
  • .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”
  • 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

execution model of Java

  • virtual machine
  • source
  • (text)
  • compiler
  • CPU
  • bytecode
  • interpreter
  • dynamic
  • loading
  • JIT
  • compiler
  • compiled
  • code
  • JVML
  • verifier
  • bytecode
  • (aka. class file)

The JIT

  • Just-In-Time compiler
  • Translates bytecode into machine code at runtime
  • 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

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.
  • 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!

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.
  • Simple Hello Page
  • My Java applet says:

  • Download 264.5 Kb.

    Do'stlaringiz bilan baham:
1   2   3




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling