Presentation is loading. Please wait.

Presentation is loading. Please wait.

Basic Java Seminar 2/2 Novemberr 5, 1997 SPARCS Nam Sedong Seminars on 4th SPARCS Exhibition - The second one.

Similar presentations


Presentation on theme: "Basic Java Seminar 2/2 Novemberr 5, 1997 SPARCS Nam Sedong Seminars on 4th SPARCS Exhibition - The second one."— Presentation transcript:

1

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

3 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

4 Java Language 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

5 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

6 Java API 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

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

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

9 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

10 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. }

11 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

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

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

14 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” );

15 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 );

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

17 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); }

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

19 AWT Component Hierarchy

20 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

21 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(); }

22 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( ) ); }

23 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:... " ); }

24 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); }

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

26 repaint( ) Another Thread for AWT repaint( ) –may not be called –final state update( Graphics g) paint( Graphics g)

27 HW.html(Calling an Applet) A Simple Program

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

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

30 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

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

32 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


Download ppt "Basic Java Seminar 2/2 Novemberr 5, 1997 SPARCS Nam Sedong Seminars on 4th SPARCS Exhibition - The second one."

Similar presentations


Ads by Google