6장.key

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

<4D F736F F F696E74202D205B4A415641C7C1B7CEB1D7B7A1B9D65D36C0E5C6D0C5B0C1F6>

Microsoft PowerPoint - java2-lecture5.ppt [호환 모드]

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

Microsoft PowerPoint - java1-lecture6.ppt [호환 모드]

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

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

5장.key

02 C h a p t e r Java

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

PowerPoint Presentation

(Microsoft PowerPoint - java2-lecture2.ppt [\310\243\310\257 \270\360\265\345])

12-file.key

PowerPoint Presentation

JAVA PROGRAMMING 실습 08.다형성

비긴쿡-자바 00앞부속

Microsoft PowerPoint - java1-lecture5.ppt [호환 모드]

PowerPoint 프레젠테이션

Microsoft PowerPoint - Java7.pptx

09-interface.key

Java

rmi_박준용_final.PDF

05-class.key

01-OOPConcepts(2).PDF

03-JAVA Syntax(2).PDF

PowerPoint 프레젠테이션

자바 프로그래밍

Chap12

슬라이드 1

Java ...

슬라이드 1

Microsoft PowerPoint - lec7_package [호환 모드]

PowerPoint Presentation

12-file.key

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

PowerPoint Presentation

JAVA PROGRAMMING 실습 02. 표준 입출력

PowerPoint Presentation

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

Microsoft PowerPoint - 04-UDP Programming.ppt

Microsoft PowerPoint - java1-lecture5.ppt [호환 모드]

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

Modern Javascript

Interstage5 SOAP서비스 설정 가이드

쉽게 풀어쓴 C 프로그래밍

PowerPoint Presentation

untitled

슬라이드 1

JavaGeneralProgramming.PDF

C프로-3장c03逞풚

10장.key

1

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

MasoJava4_Dongbin.PDF

PowerPoint Presentation

K&R2 Reference Manual 번역본

Connection 8 22 UniSQLConnection / / 9 3 UniSQL OID SET

PowerPoint Presentation

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

Java XPath API (한글)

A Tour of Java III

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

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

Network Programming

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

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

Microsoft Word - java18-1-final-answer.doc

11장.key

JAVA PROGRAMMING 실습 09. 예외처리

9장.key

쉽게 풀어쓴 C 프로그래밍

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

Microsoft PowerPoint - 14주차 강의자료

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

PowerPoint Presentation

03장.스택.key

자바-11장N'1-502

Microsoft Word - java19-1-final-answer.doc

교육2 ? 그림

쉽게 풀어쓴 C 프로그래밍

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

( )부록

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

Design Issues

Microsoft PowerPoint - 2강

PowerPoint Presentation

java_jungsuk3_슰ì−µë¬¸ì€œì€—ì²´_ hwp

4장.문장

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

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

Microsoft PowerPoint - Lect04.pptx

PowerPoint 프레젠테이션

Microsoft Word - PJ_scjp_9_0_1-lang.doc

<4A DC1DFBFE4C5ACB7A1BDBA2E687770>

Microsoft PowerPoint - 03-TCP Programming.ppt

Transcription:

JAVA Programming 1

2 3, ->

() 3 Project FileIO WebFile.class FileCopy.class FileRW.class Tools.class Graphic DObject.class Line.class Rect.class Circle.class Project/FileIO/Tools.class Project/UI/Tools.class UI Main.class GUI.class EventHandler.class Tools.class

(package) 4!!! (.) Project.FileIO.Tools.class Project.UI.Tools.class jar! ) JDK rt.jar

JDK 5 () java.awt.color : java.awt java.awt

, import 6! import! Import import java.util.scanner; import java.util.*; *. public class ImportExample { public static void main(string[] args) { java.util.scanner scanner = new java.util.scanner(system.in); System.out.println(scanner.next()); import java.util.scanner; public class ImportExample { public static void main(string[] args) { Scanner scanner = new Scanner(System.in); import java.util.*; public class ImportExample { public static void main(string[] args) { Scanner scanner = new Scanner(System.in);

7 ()! 2 : CLASSPATH java classpath C:> java -classpath "C:\Programs Files\java\jdk1.8.0_131\jre\lib" ImportExample -classpath

8! package ; package UI; // Tools UI public class Tools {... // UI.Tools. Tools UI.Tools Tools import UI.Tools package Graphic; // Line Graphic import UI.Tools; // Tools public class Line { public void draw() { Tools t = new Tools();

9! (5 5-7) abstract class Calculator { public abstract int add(int a, int b); public abstract int subtract(int a, int b); public abstract double average(int[] a); public class GoodCalc extends Calculator { public int add(int a, int b) { return a+b; public int subtract(int a, int b) { return a - b; public double average(int[] a) { double sum = 0; for (int i = 0; i < a.length; i++) sum += a[i]; return sum/a.length; public static void main(string [] args) { Calculator c = new GoodCalc(); System.out.println(c.add(2,3)); System.out.println(c.subtract(2,3)); System.out.println(c.average(new int [] {2,3,4 ));

10 ( : PackageEx)

11 lib, app

app lib. 12

Calculator Calculator public abstract. 13

Calculator, app public. 14

GoodCalc.java import. Calculator. 15

Run Configurations. main(). 16

17 PackageEx

18! package!!!!!

JDK 19 JDK!! C! JDK rt.jar C:\Program Files\Java\jdk1.8.0_131\jre\lib\rt.jar rt.jar java.awt.

java applet awt beans io lang math net nio rmi security sql text util beancontext spi color datatransfer dnd event font geom im image print channels charset spi renderable spi spi annotation instrument management ref reflect activation dgc registry server acl cert spec interfaces concurrent jar logging prefs regex spi zip 20 atomic locks

21 java.lang! language,,! import - import java.util!,,, java.io!,,, java.awt! GUI javax.swing! GUI

API 22 API! Oracle Technology Network(http://docs.oracle.com/javase/8/docs/api/)

Object 23! java.lang!

6-1 : Object 24,, class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; public class ObjectPropertyEx { public static void print(object obj) { System.out.println(obj.getClass().getName()); // System.out.println(obj.hashCode()); // System.out.println(obj.toString()); // System.out.println(obj); // public static void main(string [] args) { Point p = new Point(2,3); print(p); Point 366712642 Point@15db9742 Point@15db9742

25 String tostring()!! Object tostring() public String tostring() { return getclass().getname() +"@" + Integer.toHexString(hashCode()); + ->.tostring() + Point p = new Point(2,3); System.out.println(p); String s = p + ""; System.out.println(p.toString()); String s = p.tostring()+ ""; Point@15db9742 tostring()! Object tostring()

6-2 : Point tostring() 26 Point Point tostring(). class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; public String tostring() { return "Point(" + x + "," + y + ")"; Point tostring() public class ToStringEx { public static void main(string [] args) { Point p = new Point(2,3); System.out.println(p.toString()); System.out.println(p); // p p.tostring() System.out.println(p + "."); // p.tostring() + "" Point(2,3) Point(2,3) Point(2,3).

equals() 27 == boolean equals(object obj)!! class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; Point a = new Point(2,3); Point b = new Point(2,3); Point c = a; if(a == b) // false System.out.println("a==b"); if(a == c) // true System.out.println("a==c"); a==c class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; public boolean equals(object p) { Point p = (Point)obj; if(x == p.x && y == p.y) return true; else return false; Point a = new Point(2,3); Point b = new Point(2,3); Point c = new Point(3,4); if(a == b) // false System.out.println("a==b"); if(a.equals(b)) // true System.out.println("a is equal to b"); if(a.equals(c)) // false System.out.println("a is equal to c"); a is equal to b

6-3 : Point equals() 28 Point true equals(). class Point { int x, y; public Point(int x, int y) { this.x = x; this.y = y; public boolean equals(object obj) { Point p = (Point)obj; if(x == p.x && y == p.y) return true; else return false; public class EqualsEx { public static void main(string[] args) { Point a = new Point(2,3); Point b = new Point(2,3); Point c = new Point(3,4); if(a == b) // false System.out.println("a==b"); if(a.equals(b)) // true System.out.println("a is equal to b"); if(a.equals(c)) // false System.out.println("a is equal to c"); a is equal to b

6-4 : Rect equals() 29 int width() height() Rect, Rect equals(). width, height. class Rect { int width; int height; public Rect(int width, int height) { this.width = width; this.height = height; public boolean equals(object obj) { Rect p = (Rect)obj; if (width*height == p.width*p.height) return true; else return false; public class EqualsEx { public static void main(string[] args) { Rect a = new Rect(2,3); Rect b = new Rect(3,2); Rect c = new Rect(3,4); if(a.equals(b)) System.out.println("a is equal to b"); if(a.equals(c)) System.out.println("a is equal to c"); if(b.equals(c)) System.out.println("b is equal to c"); a is equal to b

Wrapper 30 8! Wrapper!

Wrapper 31 Wrapper Integer i = new Integer(10); Character c = new Character( c ); Double f = new Double(3.14); Boolean b = new Boolean(true); Wrapper Integer I = new Integer( 10 ); Double d = new Double( 3.14 ); Boolean b = new Boolean( false ); Float double Float f = new Float((double) 3.14);

32! Wrapper, static! Integer

Wrapper 33 Wrapper Integer i = new Integer(10); int ii = i.intvalue(); // ii = 10 Character c = new Character('c' ); char cc = c.charvalue(); // cc = c Double f = new Double(3.14); double dd = d.doublevalue(); // dd = 3.14 Boolean b = new Boolean(true); boolean bb = b.booleanvalue(); // bb = true int i = Integer.parseInt("123"); // i = 123 boolean b = Boolean.parseBoolean("true"); // b = true double f = Double.parseDouble("3.14" ); // d = 3.14 String s1 = Integer.toString(123); String s2 = Integer.toHexString(123); String s3 = Double.toString(3.14); String s4 = Charater.toString('a'); String s5 = Boolean.toString(true); // 123 "123" // 123 16 "7b" // 3.14 "3.14" // a "a" // true "true"

6-5 : Wrapper 34 Wrapper.? public class WrapperEx { public static void main(string[] args) { System.out.println(Character.toLowerCase('A')); // 'A' char c1='4', c2='f'; if(character.isdigit(c1)) // c1 true System.out.println(c1 + " "); if(character.isalphabetic(c2)) // c2 true System.out.println(c2 + " "); System.out.println(Integer.parseInt("-123")); // "-123" 10 System.out.println(Integer.toHexString(28)); // 28 2 System.out.println(Integer.toBinaryString(28)); // 28 16 System.out.println(Integer.bitCount(28)); // 28 2 1 Double d = new Double(3.14); System.out.println(d.toString()); // Double "3.14" System.out.println(Double.parseDouble("3.14")); // 3.14 boolean b = (4>3); // b true System.out.println(Boolean.toString(b)); // true "true" System.out.println(Boolean.parseBoolean("false")); // false 4 F -123 1c 11100 3 3.14 3.14 true false

35 (boxing)! Wrapper (unboxing)! Wrapper JDK1.5 Integer ten = 10; int n = ten; //. Integer ten = new Integer(10); //. int n = ten.intvalue();

6-6 : 36? public class AutoBoxingUnBoxingEx { public static void main(string[] args) { int n = 10; Integer intobject = n; // auto boxing System.out.println("intObject = " + intobject); int m = intobject + 10; // auto unboxing System.out.println("m = " + m); intobject = 10 m = 20

String 37 String - java.lang.string! String // String str1 = "abcd"; // String char data[] = {'a', 'b', 'c', 'd'; String str2 = new String(data); String str3 = new String("abcd"); // str2 str3 "abcd"! String

new String() 38!, String s = "Hello"; JVM,! String, String t = new String("Hello"); String

39 equals()! equals()

40

41! int compareto(string anotherstring) 0 anotherstring anotherstring String java= "Java"; String cpp = "C++"; int res = java.compareto(cpp); if(res == 0) System.out.println("the same"); else if(res <0) System.out.println(java + " < " + cpp); else System.out.println(java + " > " + cpp); "Java" "C++" Java > C++! ==

42 +!.tostring() System.out.print("abcd" + 1 + true + 3.13e-2 + 'E'+ "fgh" ); // abcd1true0.0313efgh String concat(string str) "I love ".concat("java.") "I Love Java."! String

concat() 43 String s1 = "abcd"; String s2 = "efgh"; s1 = s1.concat(s2); s1.concat(s2) abcdefgh s1 abcd s1 abcd s2 efgh s2 efgh

, 44! String trim() (tab, enter, space) String a = " abcd def "; String b = " xyz\t"; String c = a.trim(); // c = "abcd def". String d = b.trim(); // d = "xyz". '\t' "! char charat(int index) String a = "class"; char c = a.charat(2); // c = 'a' // "class" s int count = 0; String a = "class"; for(int i=0; i<a.length(); i++) { // a.length() 5 if(a.charat(i) == 's') count++; System.out.println(count); // 2

6-7 : String 45 String. public class StringEx { public static void main(string[] args) { String a = new String(" C#"); String b = new String(",C++ "); System.out.println(a + " " + a.length()); // ( ) System.out.println(a.contains("#")); // a = a.concat(b); // System.out.println(a); a = a.trim(); // System.out.println(a); a = a.replace("c#","java"); // System.out.println(a); String s[] = a.split(","); // for (int i=0; i<s.length; i++) System.out.println(" " + i + ": " + s[i]); a = a.substring(5); // 5 System.out.println(a); char c = a.charat(2); // 2 System.out.println(c); C# 3 true C#,C++ C#,C++ Java,C++ 0: Java 1: C++ C++ +

46

StringBuffer 47! Java.lang.StringBuffer! String! StringBuffer StringBuffer sb = new StringBuffer("java");

48

49 StringBuffer

6-8 : StringBuffer 50 StringBuffer? public class StringBufferEx { public static void main(string[] args) { StringBuffer sb = new StringBuffer("This"); sb.append(" is pencil"); // System.out.println(sb); sb.insert(7, " my"); // "my" System.out.println(sb); sb.replace(8, 10, "your"); // "my" "your" System.out.println(sb); sb.delete(8, 13); // "your " System.out.println(sb); sb.setlength(4); // System.out.println(sb); sb.tostring() This is pencil This is my pencil This is your pencil This is pencil This

StringTokenizer 51 java.util.stringtokenizer! : (delimiter) & String query = "name=kitae&addr=seoul&age=21"; StringTokenizer st = new StringTokenizer(query, "&"); (token)! String split()

52 StringTokenizer

53

6-9 : StringTokenizer 54 //// /. import java.util.stringtokenizer; public class StringTokenizerEx { public static void main(string[] args) { StringTokenizer st = new StringTokenizer("////", "/"); while (st.hasmoretokens()) System.out.println(st.nextToken());

Math 55, java.lang.math! static :

Math 56! static double random() 0.0 1.0 double 0 100 10 for(int x=0; x<10; x++) { int n = (int)(math.random()*100 + 1); // n [1~100] System.out.println(n); Math.random()*100 0.0~99.99.. Math.random()*100+1 1.0~100.99.. (int)(math.random()*100 + 1) 1~100 java.util.random!

6-10 : Math 57 Math. public class MathEx { public static void main(string[] args) { System.out.println(Math.PI); // System.out.println(Math.ceil(a)); // ceil() System.out.println(Math.floor(a)); // floor() System.out.println(Math.sqrt(9)); // System.out.println(Math.exp(2)); // e 2 System.out.println(Math.round(3.14)); // // [1, 45] 5 System.out.print(" "); for(int i=0; i<5; i++) System.out.print((int)(Math.random()*45 + 1) + " "); 3.141592653589793 4.0 3.0 3.0 7.38905609893065 3 15 31 9 7 5

Calendar 58 Calendar! java.util!,,,,,,,, Calendar

Calendar 59 Calendar,! Calendar now = Calendar.getInstance(); now Calendar new Calendar() int year = now.get(calendar.year); // now int month = now.get(calendar.month) + 1; // now! Calendar Calendar // Calendar firstdate = Calendar.getInstance(); firstdate.clear(); //. firstdate.set(2016, 11, 25); // 2016 12 25. 12 11 firstdate.set(calendar.hour_of_day, 20); // 8 firstdate.set(calendar.minute, 30); // 30

6-11 : Calendar / 60 import java.util.calendar; public class CalendarEx { public static void printcalendar(string msg, Calendar cal) { int year = cal.get(calendar.year); // get() 0~30. int month = cal.get(calendar.month) + 1; int day = cal.get(calendar.day_of_month); int dayofweek = cal.get(calendar.day_of_week); int hour = cal.get(calendar.hour); int hourofday = cal.get(calendar.hour_of_day); int ampm = cal.get(calendar.am_pm); int minute = cal.get(calendar.minute); int second = cal.get(calendar.second); int millisecond = cal.get(calendar.millisecond); public static void main(string[] args) { Calendar now = Calendar.getInstance(); printcalendar(" ", now); Calendar firstdate = Calendar.getInstance(); firstdate.clear(); // 2016 12 25. 12 month 11 firstdate.set(2016, 11, 25); firstdate.set(calendar.hour_of_day, 20); // 8 firstdate.set(calendar.minute, 30); // 30 printcalendar(" ", firstdate); System.out.print(msg + year + "/" + month + "/" + day + "/"); switch(dayofweek) { case Calendar.SUNDAY : System.out.print(""); break; case Calendar.MONDAY : System.out.print(""); break; case Calendar.TUESDAY : System.out.print(""); break; case Calendar.WEDNESDAY : System.out.print(""); break; case Calendar.THURSDAY : System.out.print(""); break; case Calendar.FRIDAY: System.out.print(""); break; case Calendar.SATURDAY : System.out.print(""); break; System.out.print("(" + hourofday + ")"); if(ampm == Calendar.AM) System.out.print(""); else System.out.print(""); System.out.println(hour + " " + minute + " " + second + " + millisecond +""); 2017/3/29/(19)7 59 51 892 2016/12/25/(20)8 30 0 0

61