Archive for the ‘ bitacademy ’ Category

Java-13강

2010년 1월 11일 월요일 13강

Object Class

finalize() – 소멸자

Wrapper class

primitive data type을 object로. 8개가 존재.
stack에 올라온 것을 heap으로

Math Class

round() 반올림
floor() 무조건 자름
ceil() 무조건 올림

String Class

  • Strings are constant.
getByte()
length() – 문자갯수(o), 문자길이(x)
substring() – 문자열을 뽑아낼 때, javascript와 동일

StringBuffer class

Is final class
string 수정가능.
속도때문에 string 대신 stringbuffer를 사용.
string은 주소를 새로 할당해야하므로 느림.
StringBuilder (x) = v1.5이후 나옴
StringBuffer (o)
차이는 thread의 synchronization을 하느냐의 차이
동기화

System class

플랫폼과 밀접한관계를 맺고있다.
os의 정보를 읽어온다.

Java.util Package

1. Utility class (ch13)
2. Collection Framework (자바의 자료구조) (ch15)
Generic (ch14)

Utility

Enumeration<E> interface
Stack<E> class
Queue interface – LinkedList를 써야함

StringTokenizer class

/*
* String parsing 방법 3가지
*
* 1. String 클래스의 split()
* 2. java.util.StringTokenizer 객체이용하기
* 3. java.util.Scanner 객체이용하기
*
*/
부모는 Enumeration<E>

Random class

is used to generate a stream fo pseudorandom numbers

Date class

represents a specific instant in time, with millisecond precision.

Calendar class

시작일이 무슨 요일인가와
이 달의 마지막 날짜
gregorianCalendar 년월일 세팅할때
getActualMaxium

Locale class

a locale object represents a specific geographical, political, or cultural

Formatter class

an interpreter for printf-style
java.util.formatter

Java-12강

2010년 1월 8일 12강

Event Model
What is an Event?
  • Events – Objects that describe what happened.
  • Events Source – The generator of an event
  • Events handlers – A method that receives an event object, deciphers it, and processes the user’s interaction
  • Events Listener

이벤트 객체 – 클래스

이벤트 리스너 – 인터페이스
이벤트 핸들러 – 메소드

Even Adapter

class

Exceptions and Assertions

assertions은 개발자용, 안씀, 툴이 없는 환경에서 디버깅을 위해 사용, 이클립스에 디버깅 기능을 사용하므로 필요없다.
exception은 사용자용, 예외처리,
The Exception class defines mild error conditions that your program encounters.
The Error class defines  serious error conditions.

checked exception

General Exception
try-catch 반드시 써야함

unchecked exception

RuntimeException, error
try-catch 써도되고 안써도되고

Throwable class

JSP에서 exception 객체는 Throwable class.
  • catch하는 방법
  • exception 던지는 방법
  • exception 선언하는 방법

Throwing Exceptions

  • Throw an appropriate exception
  • give the exception a meaningful message
exception을 개발자가 의도적으로 발생시킬 때
“throw new 예외”

throws

메소드 안에서 예외 사용을 알림
access modifier 일반 modifier 리턴타입 이름() throws 예외이름{}

Printing information about exceptions

- The printStackTrace() method
returns a detailed message string about the exception
- The toString() method
returns a detailed message string about the exception

The finally Statement

try-catch-finally
try-finally
  • The finally statement defines a block of code that always executes, regardless of whether an exception was caught.
  • the catch block may be omitted when the finally clause is used.

Creating your own Exception

  1. 내가 만든 exception의 부모가 checked exception or unchecked exception 될지 고려.
  2. 메시지 처리를 어떻게 할건지..

Assertions

툴없이 디버깅을..
assert logical_expression;
assert logical_expression : message;
조건에 안맞으면 assertion 에러가 발생
command option
>java -ea 클래스명
하면 assertion 검사.

Java Graphics

JFC (Java Foundation Class)
  1. AWL
  2. Swing
  3. Drag&Drop
  4. Accessibility
  5. Java 2D
자바 그래픽은 생산성이 떨어짐.
요즘은
flex(client) + Java(server)

Java-11강

2010년 1월 7일 11강


Class(static) Variable

Are shared among all instances of a class
static – 공유변수

Class(static) Methods

주소없이 접근하기 위해
new 없이 접근하기 위해 static을 쓴다.

static Initializers 스태틱 초기화 블럭

  • static block code executes only once, when the class is loaded
  • static block is usually used to initialize static attributes
ex)
private final int YEAR; – final이 붙은 멤버변수는 초기화는 생성자에서..
private static final int DAY; – static final 의 초기화는 static 초기화 블록에서 초기화..
변수의 초기화는 생성자나 초기화블록을 통해서..
클래스에 static을 사용하려면 내부클래스여야만 사용가능

The final Keywords

class 앞에 쓸 수 있는 (access) modifier : public, [default], abstract, final class Demo

variable 앞에 : public, private, protected, [default] int su;

method 앞에 : public, private, protected, [default], final, static, abstract, int method()
멤버, 스태틱, 지역 상수

Deprecation

//…

Inner Class

allow a class definition to be placed inside another class definition.
  • Nested Class
  • Member Class
  • Local Class
  • Anonymous Class
1.why?
2.생성방법
3.제한사항

Nested Class

/*
* static class(Nested Class)
* 1. why: class를 packaging 하기 위해
* 2. 생성방법: Outer.Inner in = new Outer.Inner();
* 즉 바깥클래스의 주소 필요하지 않다.
* 3. 제한사항: outer class의 멤버변수, 멤버메소드 접근 불가
*
*/
packaging..하기위한..
class com{
static class javasoft{
static class lib{
static class Test{}
}
}
static class jspsoft{
static class lib{}
}
}
com.javasoft.lib.Test t = new com.javasoft.lib.Test();
Member class
/*
* member class
* 1. why?: 다중상속가능
* 2. 생성방법: 바깥쪽 클래스의 주소가 필요하다.
* Outer.Inner in = out.new Inner();
* 3. 제한사항: static 변수나 static method를 가질 수 없다.
*/
static variable, method 를 가질 수 없다.
다중상속 가능.

Local Class

/*
* Local class
* 1. why?: scope를 가장 짧게하기 위해서, 메소드가 실행되는 동안만 가능
* 2. 생성방법: 자기가 속한 메소드를 호출해야만 생성가능
* 3. 제한사항: 1) 자기가 속한 메소드의 순서를 지켜야한다.
* 2) access modifier 사용할 수 없다.
* 3) static 사용할 수 없다
* 4) 바깥 클래스의 멤버변수, 스태틱변수 접근가능
* 자기가 속한 메소드, 지역변수 접근 불가능
* 자기가 속한 지역 상수만 접근가능
*
*/

Anonymous Class

local class의 제한사항과 똑같음

enum type

(실제 필드에서는 잘 안쓴다..)
class Weekend{
public static final int SUN = 0;
public static final int MON = 1;
}
interface Weekend{
int SUN = 0;
int MON = 1;
}
enum Weekend{
SUN, MON;
}
enum에는 data type을 입력하지 않음
// 상수들만 되어있기 때문에 new를 쓸 필요없다.
// 클래스가 아니므로
//Weekend w = new Weekend();
Java API

java.lang.Enum<E>

switch문에 사용한다.
values()를 이용해서 for each를 이용 배열로 뽑아낼 수 있다.
SCJP에서는 enum 알아야함