JAVA PROGRAMMING - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

JAVA PROGRAMMING

Description:

???? 'JAVA' ??????????????????????????????????????????????????????? ... Group ???????? 1991 ?? James Gosling ???????????????????????????????????????? ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 31
Provided by: kratcha
Category:

less

Transcript and Presenter's Notes

Title: JAVA PROGRAMMING


1
JAVA PROGRAMMING
  • PART I

2
?????????????
  • ???????????????????????????????????????????(Sun
    Microsystems)
  • ???? JAVA ??????????????????????????????????????
    ?????????????????
  • ??????????????????????????????????????????????????
    ????
  • ?????????????? ???????????????????????????????????
    ???????????????????????????????????
  • ???????????????????????????????
    ??????????????????????????????????????????????????
    ? ????????????????????????????????????????????????

3
Sun Microsystems
????????? 1990 ???????????????????
??????????????????????????????????????????????????
??????????????????????????? ? ?????? Sun
Microsystems ?????????????????????????????????????
????????????????????????????? ????????????????????
??????????????? ??????????????????
??????????????????????????????????????????????????
?????????? ????????? Green Group ???????? 1991 ??
James Gosling ????????????????????????????????????
?????????????????????????????????
???????????????????????????????????? Star7
???????? remote control ?????????? ????????? C
???????????? Star7 ???????????????????????????????
?????????????????????? ? ????????? C
????????????????? ???????????????????????? ????
????????????????????????????????
?????????????????????? ???????????????????????????
???????????????? ??????????????????????????
????????????????????????????????? ???? Oak
?????????????????????????????????????????
4
???????????????????
????????????? java 1.0 ???????? JDK 1.0
(??????????????????????????????????????)
?????????????????? C ?????? 20 ???? ??? java 1.1
???????????????????? ????????????? 2 ??????? java
1.0 ??????????? JDK 1.2 ??????????????????????
Java 2 SDK 1.2 (Software Development Kit)
?????????????????????????? Java 2 SDK 1.4
???????????????????????? Java ????????????????????
???? ?????????????????????????????????????????????
?????????? ???????????????????? ????????? Just in
Time (JIT) compiler ??????????????????
????????????? ????????????????????????????????????
?????????????? ??????????????? ???????????????????
???????????????????, Java HotSpot (??????????
java 2 SDK 1.3) ??????????????????????????????????
?????????????? Java chip ???????????????
5
??????????????????
  • ??????????????????????? ??????????????????????????
    ??????????? (OOP Object Oriented Programming)
  • Java ??? platform independence ???????????????????
    ???????????????????????? java ????????????????????
    ???????????????????? ??????????????????????
  • Java ?? garbage collector ???????????? robust
  • Java ????????????????????? C ???????????????????
    ????? 4 ???? ???????????????????????????(developme
    nt time) ???????? C ???????????????????????? 2
    ????
  • Java ????????????????????????????????????????
    ?????? electronic signature, public and private
    key management, access control ??? certificates

6
Definition of JAVA
  • 2 appropriate definition for java
  • Java is programming language
  • Java is platform
  • 2 forms of java
  • Java application
  • Java applet
  • Java script is not java, it is developed by
    Netscape that used in web and base on java.

7
Platform
  • Platforms like Operating System
  • All application must depend on platform
  • Platform use for communicating with computer
    machine directly.

Example Microsoft Word run on Microsoft Window
8
Java is Platform
  • Java have own platform, named java virtual
    machine
  • So, java can run on any OS because of java
    virtual machine.

Write Once, Run anywhere
9
Java platform
10
??????????????????
11
??????????????????????
  • Java program ?????????????????????????????????????
    ?? ????????????????? (text) ????????????????
    ?????????????????????? .java ???????????
    ????????? (Source code) ??????????????????????????
    ??? java class file ???? ????????
    ??????????????????? .class ???????????????????????
    ?? java virtual Machine ??????
  • API ????????????????????? ????????????????????????
    ????? system services ????????????????? ???? Java
    API ??????????? ready-made software components
    ???????????????????????? Java Virtual Machine
    ?????? Java API ??????????????????????

12
??????????????????????
Java Program
C Program
compile
compile
Byte code
Machine code
Java Virtual Machine
Computer
interpret
Computer
13
Java Virtual Machine
  • ????????????????????????????????????????
    ??????????????? class loader ??? Execution engine
  • Class loader ????????????? class ????????????????
    java API ?????? class loader ????????????????
  • bootstrap class loader ???? system class loader
    ????????????????? java virtual machine ???
  • User-defined class loader
  • Execution Engine ???????????? ???? just in time,
    Adaptive optimizer

14
Java Virtual Machine
Java Virtual Machine
Class loader
Java APIs class
User-defined Class
Byte code
Execution Engine
Native method
Operating System
15
Starting with JAVA2
  • Download java compiler from web
  • Double click this icon to install java.

http//java.sun.com/j2se
Java virtual machine JRE (Java Runtime
Environment) Java Developer Kit JDK

16
Java step
  • Java compiler is required

Edit source code on textfile
ltFile-namegt.java
Compile source code
Run on Java Virtual Machine
ltFile-namegt.class
17
How to install
  • Double click icon of file that download
  • Fill folder to install name C\java

18
Your First Program in JAVA
  • Edit file name Welcome1.java at C\Myjava

// A first program in Java. public class Welcome1
/ main method begins execution of
Java application / public static void main (
String args ) System.out.println(Welcom
e to Java Programming!) // end method
main // end class Welcome1
19
Compile Run
  • Go to DOS
  • Go to directory C\Myjava
  • Type command for compile java program
  • Type command for run java

javac ltfile-namegt.java
java ltfile-namegt
20
Compile Run (contd)
21
Write Once Run Anywhere
22
Java Application
  • What name of this application is ?

// Printing multiple lines of text with a single
statement. public class Welcome_mline //
main method bigins execution of Java application
public static void main ( String args )
System.out.println(Welcome\nto\nJava\nProgrammin
g) // end method main // end class
Welcome_mline
23
Java Application
// Printing multiple lines in a dialog box //
Java extension packages import javax.swing.JOption
Pane // import class JOptionPane public class
Welcome_dialog // main method begins
execution of Java application public static
void main ( String args )
JOptionPane.showMessageDialog( null,
Welcome to Java Programming)
System.exit(0) // terminate application //
end method main // end class Welcome_dialog
24
Java Application
// An addition program. // Java extension
packages import javax.swing.JOptionPane //
import class JOptionPane public class Addition
// main method begins execution of Java
application public static void main( String
args ) String firstNumber // first
string entered by user String secondNumber
// second string entered by user int number1
// first number to add int number2
// second number to add int sum
// sum of number1 and number2 // read in
first number from user as a String
firstNumber JOptionPane.showInputDialog(Enter
Number1) // read in second number from
user as a String secondNumber
JOptionPane.showInputDialog(Enter Number2)
// convert numbers from type String to type int
number1 Integer.parseInt(firstNumber)
number2 Integer.parseInt(secondNumber) sum
number1 number2 // add two numbers
JOptionPane.showMessageDialog(null, the sum is
sum, Results, JOptionPane.PLAIN_MESSA
GE) System.exit(0) // terminate
application // end method main // end class
Addition
25
Message Dialog types
  • JOptionPane.ERROR_MESSAGE
  • JOptionPane.INFORMATION_MESSAGE
  • JOpitonPane.WARNING_MESSAGE
  • JOpitonPane.QUESTION_MESSAGE
  • JOptionPane.PLAIN_MESSAGE

26
Java applet
  • Java language that must perform under web browser
  • There are 2 ways to run applet
  • Command appletviewer
  • HTML page

27
Java applet
  • Go to c\java\demo\applets
  • Enter director TicTacToe
  • You can see file-name example1.html
  • Type command

Appletviewer ltfilenamegt
Example appletviewer example1.html
28
Create Java applet
  • Edit file-name HelloA.java

//HelloA.java // java core packages import
java.awt. // import all class public class
HelloA extends java.applet.Applet // draw
text on Applet's background public void
paint(Graphics g) // draw a String at x
25 and y 50 g.drawString("Hello",25,50)
// end method paint // end class HelloA
29
Create Java applet
  • Edit file-name HelloA.html
  • Type command appletviewer HelloA.html

lt! HelloA.htmlgt lthtmlgt ltbodygt This is my
first Applet. ltapplet code"HelloA.class"
width200 height200gt lt/appletgt
lt/bodygt lt/htmlgt
30
Java Applet
Write a Comment
User Comments (0)
About PowerShow.com