Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

Similar documents
Microsoft PowerPoint - JavaPrimer.ppt [호환 모드]

01-OOPConcepts(2).PDF

1

02 C h a p t e r Java

PowerPoint 프레젠테이션

자바 프로그래밍

5장.key

PowerPoint 프레젠테이션

rmi_박준용_final.PDF

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint Presentation

Chap12

07 자바의 다양한 클래스.key

09-interface.key

05-class.key

chap10.PDF

03-JAVA Syntax(2).PDF

쉽게 풀어쓴 C 프로그래밍

비긴쿡-자바 00앞부속

12-file.key

예제 2) Test.java class A intvar= 10; void method() class B extends A intvar= 20; 1"); void method() 2"); void method1() public class Test 3"); args) A

MasoJava4_Dongbin.PDF

JMF3_심빈구.PDF

ch09

Microsoft PowerPoint - 04-UDP Programming.ppt

gnu-lee-oop-kor-lec06-3-chap7

歯Writing_Enterprise_Applications_2_JunoYoon.PDF

신림프로그래머_클린코드.key

쉽게 풀어쓴 C 프로그래밍

Java

fundamentalOfCommandPattern_calmglow_pattern_jstorm_1.0_f…

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

Microsoft PowerPoint - RMI.ppt

Network Programming

Interstage5 SOAP서비스 설정 가이드

자바GUI실전프로그래밍2_장대원.PDF

Contents Contents 2 1 Abstract 3 2 Infer Checkers Eradicate Infer....

Spring Boot/JDBC JdbcTemplate/CRUD 예제

untitled

PowerPoint Presentation

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

PowerPoint Presentation

11 템플릿적용 - Java Program Performance Tuning (김명호기술이사)

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

교육자료

ilist.add(new Integer(1))과 같이 사용하지 않고 ilist.add(1)과 같이 사용한 것은 자바 5.0에 추가된 기본 자료형과 해당 객체 자료 형과의 오토박싱/언박싱 기능을 사용한 것으로 오토박싱이란 자바 컴파일러가 객체를 요구하는 곳에 기본 자료형

초보자를 위한 자바 2 21일 완성 - 최신개정판

10-Java Applet

6주차.key

Modern Javascript

교육2 ? 그림

歯JavaExceptionHandling.PDF

제11장 프로세스와 쓰레드

자바-11장N'1-502

Spring Data JPA Many To Many 양방향 관계 예제

6자료집최종(6.8))

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

[ 정보 ] 과학고 R&E 결과보고서 Monte Carlo Method 를이용한 고교배정시뮬레이션 연구기간 : ~ 연구책임자 : 강대욱 ( 전남대전자컴퓨터공학부 ) 지도교사 : 최미경 ( 전남과학고정보 컴퓨터과 ) 참여학생 : 박진명 ( 전

PowerPoint Presentation

PowerPoint Presentation

Secure Programming Lecture1 : Introduction

@OneToOne(cascade = = "addr_id") private Addr addr; public Emp(String ename, Addr addr) { this.ename = ename; this.a

PowerPoint Presentation

Microsoft PowerPoint - 2강

int total = 0; for( int i=1; i<=5; i++ ) { for( int j=1; j<=i; i++ ) { total ++; System.out.println( total ); 대구분 : 객체와 Class 소구분 : 객체생성과사용 / Class 선언

FileMaker ODBC and JDBC Guide

JMF2_심빈구.PDF

PowerPoint Presentation

14-Servlet

초보자를 위한 C# 21일 완성

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

슬라이드 1

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

No Slide Title

쉽게 풀어쓴 C 프로그래밍

Design Issues

JAVA PROGRAMMING 실습 08.다형성

C# Programming Guide - Types

PowerPoint 프레젠테이션

Microsoft PowerPoint - chap11

Microsoft PowerPoint - java2 [호환 모드]

FileMaker ODBC and JDBC Guide

Chap7.PDF

Something that can be seen, touched or otherwise sensed

<4D F736F F F696E74202D20C1A63236C0E520BED6C7C3B8B428B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Microsoft PowerPoint - lec2.ppt

class Sale void makelineitem(productspecification* spec, int qty) SalesLineItem* sl = new SalesLineItem(spec, qty); ; 2. 아래의액티비티다이어그램을보고 Java 또는 C ++,

thesis

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

13주-14주proc.PDF

PowerPoint Presentation

Microsoft PowerPoint - lec7_package [호환 모드]

JAVA PROGRAMMING 실습 09. 예외처리

Microsoft PowerPoint - Supplement-03-TCP Programming.ppt [호환 모드]

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå

PowerPoint Presentation

Microsoft Word - EEL2 Lab5 예외처리와 스레드.docx

자바로

Transcription:

Linux JAVA 1. http://java.sun.com/j2se/1.4.2/download.html J2SE 1.4.2 SDK 2. Linux RPM ( 9 ) 3. sh j2sdk-1_4_2_07-linux-i586-rpm.bin 4. rpm Uvh j2sdk-1_4_2_07-linux-i586-rpm 5. PATH JAVA 1. vi.bash_profile 2. PATH /usr/java/j2sdk1.4.2_07/bin 3...bash_profile ( ) 4. javac

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class First public static void main(string args[]) //output a message to the screen System.out.println( Java Primer Now Brewing ); : $ javac First.java» First.class : $ java First

Java ~ (Methods) public class Second public static void printit(string message) System.out.println(message); public static void main(string args[]) printit( Java Primer Now Brewing ); (Operators)» : + - * / ++(autoincrement) --(autodecrement)» : ==(equality)!=(inequality) &&(and) (or)» : +(concatenate) (Statements): C» for» while» if» primitive data types: boolean, char, byte, short, int, long, float, double» reference data types: objects, arrays

Java ~ (Classes and Objects) class Point // constructor to initialize the object public Point(int i, int j) xcoord = i; ycoord = j; public Point() xcoord = 0; ycoord = 0; // exchange the values of xcoord and ycoord public void swap() int temp; temp = xcoord; xcoord = ycoord; ycoord = temp; public void printit() System.out.println( X coordinate = + xcoord); System.out.println( Y coordinate = + ycoord); // class data private int xcoord; //X coordinate private int ycoord; //Y coordinate

Java ~ Point pta» constructor Point no return value» ( ) Point pta = new Point(0, 15); method overloading: (, )» ( ) Point pta = new Point(); static method instance method» static: class Second printit();» instance: instance pta.swap(); pta.printit(); public private» public: class constant static final public static final double PI = 3.14159;» private: class By reference» instance reference( )» reference» this: (self-referential object)

Java ~ Objects as references Object parameters are passed by reference public class Third public static void change(point tmp) tmp.swap(); public static void main(string args[]) //create 2 points and initialize them Point pta = new Point(5, 10); Point ptb = new Point(-15, -25); Point ptd = new Point(0,1); // output their values change(ptd); pta.printit(); ptd.printit(); ptb.printit(); // now exchange values for first point pta.swap(); pta.printit(); //ptc is a reference to ptb; Point ptc = ptb; //exchange the values for ptc ptc.swap(); //output the values ptb.printit(); ptc.printit();

Java ~ (Arrays)» 10 byte[] numbers = new byte[10];» int[] primenums = 3,4,7,11,13;» : new new 5 references Point[] pts = new Point[5]; reference for (int i = 0; I < 5; I++) pts[i] = new Point(i,i); pts[i].printit(); Java default initialization» primitive numeric data: zero» arrays of objects: null

Java (Packages): class» core Java application programming interface(api) http://www.javasoft.com http://java.sun.com/j2se/1.4.2/docs/api/ core java package : java.<package name>.<class name> java.lang» java.lang.string, java.lang.thread» class full name java.util.vector items = new java.util.vector();» import java.util.vector; Vector items = new Vector();» import java.util.*;

(Exception Handling) Public final void wait() throws public class TestExcept InterruptedException;» wait() public static void main(string args[]) InterruptedException int num,recip; //generate a random number 0 or 1 try-catch //random() returns a double,type-cast to int try num=(int)(math.random()*2); try //call some method(s) that recip=1/num; //may result in an exception. System.out.println( The reciprocal is +recip); catch(theexception e) catch(arithmeticexception e) //now handle the exception //output the exception message System.out.println(e); finally finally //perform this whether the System.out.println( The number was +num); //excepiton occurred or not.

Inheritance class derived-class extends base-class public class Person public Person(String n,int a,string s) name=n; age=a; ssn=s; public void printperson() System.out.println( Name: + name); System.out.println( Age: +age); System.out.println( Social Security: +ssn); private String name; private int age; private String ssn; public class Student extends Person public Student(String n,int a,string s, String m,double g) //call the constructor in the //parent (Person) class super(n,a,s); major=m; GPA=g; public void studentinfo() //call this method in the parent class printperson(); System.out.println( Major: +major); System.out.println( GPA: +GPA); private String major; private double GPA;

Class Object (java.lang.object ) class Object Public class Object» Constructor : public Object()» Method Summary protected Object clone() : Creates and returns a copy of this object. boolean equals(object obj) :Indicates whether some other object is "equal to" this one. protected void finalize() : Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. Class getclass() : Returns the runtime class of an object. int hashcode() : Returns a hash code value for the object. void notify() : Wakes up a single thread that is waiting on this object's monitor. void notifyall() : Wakes up all threads that are waiting on this object's monitor. String tostring() : Returns a string representation of the object. void wait() : Causes current thread to wait until another thread invokes the notify() method or the notifyall() method for this object. void wait(long timeout) : Causes current thread to wait until either another thread invokes the notify() method or the notifyall() method for this object, or a specified amount of time has elapsed. void wait(long timeout, int nanos) : Causes current thread to wait until another thread invokes the notify() method or the notifyall() method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.

Interfaces Interface : class» method method Polymorphism: Polymorphic reference public class Circle implements Shape //initialize the radius of the circle public interface Shape public Circle(double r) radius=r; public double area(); public double circumference(); public static final double PI=3.14159; //calculate the area of a circle public double area() return PI*radius*radius; //calculate the circumference of a circle public double circumference() return 2*PI*radius; private double radius;

Interfaces public class Rectangle implements Shape public Rectangle(double h,double w) height=h; width=w; //calculate the area of a rectangle public double area()return height*width; //calculate the circumference of a rectangle public double circumference() return 2*(height + width); private double height; private double width; Public class TestShapes public static void display(shape figure) System.out.println( The area is + figure.area()); System.out.println( The circumference is figure.circumference()); public static void main(string args[]) Shape figone=new Circle(3.5); display(figone); figone=new Rectangle(3,4); display(figone);

Abstract Classes Shape Interface method (abstract) ( )» abstract : optional, implied Abstract class: (abstract method) (defined method) Interface abstract class instance Public abstract class Employee public Employee(String n,string t,double s) name=n; title=t; salary=s; public void printinfo() System.out.println( Name: +name); System.out.println( Title: +title); System.out.println( Salary : $ +salary); public abstract void computeraise(); private String name; private String title;» private : class protected double salary;» protected : class» public : class (derived) sub class

Abstract Classes A manager A developer public class Manager extends Employee public Manager(String n, String t, double s) super(n,t,s); Public void computeraise() salary+=salary *.05+BONUS; private static final double BONUS=2500; Public class Developer extends Employee public Developer(String n, String t, double s, int np) super(n,t,s); numofprograms=np; public void computeraise() salary+=salary *.05 +numofprograms*25; private int numofprograms;

Abstract Classes Manager class Developer class public static void main(string arg[]) Employee[] worker = new Employee[3]; worker[0] = new Manager( Pat, Supervisor,30000); worker[1] = new Developer( Tom, Java Tech,28000,20); worker[2] = new Developer( Jay, Java Intern,26000,8); for(int i = 0; i < 3; i++) worker[i].computeraise(); worker[i].printinfo();

Applet standalone application : applet : web page» No main()» Constructor: init() AppletViewer FirstApplet.html FirstApplet.java Import java.applet.*; Import java.awt.*; public class FirstApplet extends Applet public void init() //initialization code goes here FirstApplet.html <applet Code = FirstApplet.class Width = 400 Height = 200> </applet> public void paint(graphics g) g.drawstring( Java Primer Now Brewing!,15,15);

P918 java.lang.arrayindexoutofboundsexception TestArrayException.java P920 Vector 3 TestVector.java Unix 211.119.245.68 ~mysung/2004os/class?/.