1 / 31

Basic Java Seminar 2/2

Seminars on 4th SPARCS Exhibition - The second one. Basic Java Seminar 2/2. Novemberr 5, 1997 SPARCS Nam Sedong dgtgrade@sparcs.kaist.ac.kr. What is Java?. A way to make Web pages sexy? A language like C++, Smalltalk? Computing Platform Java Programming Language

hong
Télécharger la présentation

Basic Java Seminar 2/2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Seminars on 4th SPARCS Exhibition - The second one Basic Java Seminar 2/2 Novemberr 5, 1997 SPARCS Nam Sedong dgtgrade@sparcs.kaist.ac.kr

  2. What is Java? • A way to make Web pages sexy? • A language like C++, Smalltalk? • Computing Platform • Java Programming Language • Java (Virtual) Machine (JVM) • Java API (Application Programmers’ Interface) • MFC

  3. C++ -- +++ Object Oriented no multiple inheritance no operator overloading No pointer Secure Thread-safe Exception Handling Architecture Neutral Internationalization Unicode, 2 byte char Garbage Collection Standardization sizeof( int ) Packages Network Oriented Class loading Java Language

  4. Java Virtual Machine • The engine that actually executes a Java program • key to many of Java’s features • portability (Write once, run anywhere) • efficiency • security (Sandbox) • virtual processor, virtual memory… • Used in JDK, JRE, browsers

  5. package java.awt package java.awt.datatransfer package java.awt.event package java.awt.image package java.beans package java.io package java.lang package java.lang.reflect package java.math package java.net package java.rmi package java.rmi.dgc package java.rmi.registry package java.rmi.server package java.security package java.security.acl package java.security.interfaces package java.sql package java.text package java.util package java.util.zip Java API

  6. Application & Applets • Application • standalone programs • HotJava browser • Applet • a Java program to be included in HTML pages and executed in a Java-compatible browser.

  7. How Applet Run? Compile Java Source Code Java Class File Network Web Browser

  8. Before You go on • JDK(Java Development Kit) • Java-compatible browser • References • Java Tutorial HTML format • Java API Documentation • You can find many resources about Java at http://www.javasoft.com

  9. Hello World Application /** * The HelloWorldApp class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorldApp { public static void main(String[] args) { System.out.println("Hello World!"); //Display the string. } }

  10. Compiling • JDK: • UNIX: • javac HelloWorld.java • DOS shell (Windows 95/NT): • javac HelloWorld.java • Other Visual Development Tools: • Maybe, you can find “Compile” button, or etc. • Output:HelloWorld.class

  11. Running • Run the program using the Java interpreter. • JDK • java HelloWorldApp • Other Visual Development Tools: • Maybe, you can find “Compile” button, or etc.

  12. Variables and Data Types • Primitive Type • char • 2byte, UNICODE • boolean • true or false • Reference Type • C data types Not supported • pointer, struct, union

  13. Class java.lang.String String a = new String( “abc” ); String b; b = new String( “def” ); String c = “abc”; System.out.println( a.length( ) ); System.out.println( a.substring( 5, 10 ) ); System.out.println( a + b ); System.out.println( a == “abc” ); System.out.println( a.equals( “abc” ) ); System.out.println( c == “abc” ); String d = “This is”.concat( “String” );

  14. Class java.lang.Math int a; a = Math.max( -5, -10 ); a = Math.abs( a ); int pi = Math.PI; a = ( int )Math.max( -9.0, -10.2 );

  15. java.util.Vector Vector() Vector(int) Vector(int, int) addElement(Object) capacity() contains(Object) copyInto(Object[]) elementAt(int) elements() firstElement() indexOf(Object) ...

  16. Class java.util.Stack public class Stack extends Vector { public Object push(Object item); public Object pop() throws EmptyStackException; public Object peek() throws EmptyStackException; public boolean empty(); public int search(Object o); }

  17. Abstract Window Toolkit(AWT) • GUI, Look and Feel • Components • Button, Frame, Panel, TextField, ... • Event Handling • MouseListener, ComponentListener, ... • Layout • GridLayout, FlowLayout, …

  18. AWT Component Hierarchy

  19. HelloSPARCS Application • A button turn in to red when pressed • Add components to a container • Add a listener to a component • Multiple class in a file

  20. HelloSPARCS.java 1/3 import java.awt.*; import java.awt.event.*; public class HelloSPARCS { public static void main( String[] args ) { Frame f = new Frame( "HelloSPARCS" ); f.add( new SPARCSButton( ) ); f.pack(); f.show(); } }

  21. Hello SPARCS.java 2/3 class SPARCSButton extends Button { public SPARCSButton( ) { this.setLabel( "SPARCS" ); this.addMouseListener( new SPARCSButtonAdapter( ) ); } public SPARCSButton( Color argC ) { this.setBackground( argC ); this.addMouseListener( new SPARCSButtonAdapter( ) ); } }

  22. Hello SPARCS.java 3/3 class SPARCSButtonAdapter extends MouseAdapter { public void mouseClicked( MouseEvent argME ) { if ( argME.getSource( ) instanceof SPARCSButton ) { ( ( SPARCSButton )argME.getSource( ) ).setBackground( Color.red ); } else { System.err.println( "ERROR: ... " ); } } }

  23. Hello World Applet import java.applet.Applet; import java.awt.Graphics; public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); } }

  24. Class java.awt.Graphics • Various devices, as well as onto off-screen images. • Component.getGraphics( ) • origin • clip • color • font. • XOR

  25. repaint( ) • Another Thread for AWT • repaint( ) • may not be called • final state • update( Graphics g) • paint( Graphics g)

  26. HW.html(Calling an Applet) <HTML> <HEAD> <TITLE> A Simple Program </TITLE> </HEAD> <BODY> <APPLET CODE="HelloWorld.class" WIDTH=150 HEIGHT=25> </APPLET> </BODY> </HTML>

  27. The Life Cycle of an Applet public class Simple extends Applet { . . . public void init() { . . . } public void start() { . . . } public void stop() { . . . } public void destroy() { . . . } . . . }

  28. 한글? Unicode? • char • 2byte • String • Unicode 2.0 • 2 byte • 한글로 된 변수이름을 쓸 수 있다.

  29. Java의 미래? • Today, 5 times slower than C++ • Just In-Time(JIT) compiler • JAR • Write Once, Run Anywhere? • Java Foundation Class • Assembly  C • JavaBeans - Software Component • JavaStation - (Not Virtual)Machine

  30. References • http://www.javasoft.com/docs/books/tutorial/index.html • http://www.javasoft.com/products/jdk/1.1/docs/api/packages.html • http://www.javasoft.com/docs/books/jls/html/index.html • 전문가로 큰다, 김도형(dynaxis), 마이크로소프트웨어 • Java Unleashed, Sams net • Java Virtual Machine, Jon Meyer&Troy Downing, O’Reilly

  31. Contact Information • dgtgrade@sparcs.kaist.ac.kr • dgtgrad@ara.kaist.ac.kr • dgtgrade@csqueen.kaist.ac.kr • dgtgrade@noah.kaist.ac.kr • dgtgrade@neowiz.com • Office: 869-5400 • Off-line: SPARCS room

More Related