Java Plus - accidentlywoo/sec GitHub Wiki
νμΌκ³Ό Overriding, Class class, IO
- ν΄λꡬ쑰 : META-INF(μ 보μ μ 보) > MANIFEST.MF λ΄μ©
λ²μ νμ λΌμΈ
μ§μ μ νμ : Main-Class : FQCN(com.my.gui.Horse)
- λΆλͺ¨μ λ©μλμ λμΌν 리ν΄νμ , λ©μλ μ΄λ¦, 맀κ°λ³μ 리μ€νΈλ₯Ό κ°μ ΈμΌνλ€.
- μ κ·Ό μ νμ λ κ°νκ² μ€λ²λΌμ΄λ© ν μ μλ€.
- μλ‘μ΄ μμΈλ₯Ό throwsν μ μλ€.
ex)
class P{
public void m() throws IOException{
}
}
class C extends P{
public void m() throws IOException{}
public void m() throws FileNotFoundException{} // IOExceptionμ νμ Exceptionμ΄λΌ μ¬μ©κ°λ₯
public void m(){}
// public void m() throws {} // μ»΄νμΌ μ€λ₯
// public void m() throws SQLException{}
}
JAVA SE
- Class : ν΄λμ€ μ 보 ( ν΄λμ€μ΄λ¦, λ©μλλ€, λ©€λ²νλλ€)
- Object : κ°μ²΄μ 보 ( hashCode(), toString())
- File : νμΌν¬κΈ°, μ°κΈ°/μ½κΈ° κ°λ₯, μ΅μ’ μ¬μ©μκ°
void m(Object o){
//o.a() Objectμ μλ λ©μλ νΈμΆ : μ»΄νμΌ μ€λ₯
if(o instanceof A){ // λ€μ΄μΊμ€ν
μ νκΈ°μ μ ν΄λμ€ μ²΄ν¬
A a = (A)o;
a.a();
}
}
void m(Object o){
Class clazz = o.getClass();
if(clazz.getName().getSimpleName().equals("A")){
A a = (A)o;
a.a();
}
}
java -cp bin A
class A{
psvm(String[] args){
syso("hello");
Class.forName("java.util.Date"); // λ°νμμμ ν΄λμ€ λ‘λ©
}
}
class DCL{
public static void test(String className) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Class claszz = Class.forName(className);
claszz.newInstance(); // 맀κ°λ³μμλ μμ±
// μλ°λΉμ¦μ 쑰건μ λ§μ‘±ν΄μΌ λ°νμ λ€μ΄λλ―Ή λ‘λλ₯Ό ν μ μλ€.
// -> public 맀κ°λ³μμλ μμ±μ
}
}
public class DynamicClassLoad {
public static void main(String[] args) {
System.out.println("hello");
Scanner sc = new Scanner(System.in);
String className = sc.next();
DCL.test(className);
}
}
μλ°μμ λ°μ΄ν°λ μ€νΈλ¦Ό(Stream)μ ν΅ν΄ μ μΆλ ₯λλ―λ‘ μ€νΈλ¦Όμ νΉμ§μ μ μ΄ν΄ν΄μΌνλ€.
Stream : μμ°¨λ¨λ°©ν₯ λ°μ΄ν° νλ¦ : ABC -C-B-A->
java.io μ μΆλ ₯ λΌμ΄λΈλ¬λ¦¬ μ¬μ© κ°λ₯.
ν€λ³΄λ : Stream - InputStream is = System.in;
νμΌ : - FileInputStream fis = new FileInputStream("a.txt");
νμΌ : Reader - FileReader fr = new FileReader("a.txt");
μμΌ : InputStream is = socket.getInputStream();
νλ‘μΈμ€ : InputStream is = process.getInputStream();
<>InputStream : λ°μ΄νΈλ¨μ μ λ ₯ : μ΄λ―Έμ§ νμΌ, λ©ν°λ―Έλμ΄, ν μ€νΈ νμΌ κ°λ₯
<>Reader : λ¬Έμλ¨μ μ λ ₯
int r = is.read();
int r = fis.read();
int r = fr.read();
int r = is.read();
<>OutputStream : λ°μ΄νΈλ¨μ μΆλ ₯ μ€νΈλ¦Ό - FileOutputStream
<>Writer : λ¬Έμλ¨μ μΆλ ₯ - FileWriter
Reader - Writer : λ¬Έμλ¨μμ μ λ ₯ -> λ¬Έμλ¨μμ μΆλ ₯
InputStream - OutputStream : λ°μ΄νΈλ¨μμ μ λ ₯ -> λ°μ΄νΈλ¨μμ μΆλ ₯
-> μ’ λ₯λ₯Ό λ§μΆμ§ μμΌλ©΄ λ¬ΈμκΉ¨μ§ λ°μ
writeInt(65);
λ¬Έμ μ : λ€μν νμ λ³λ‘ μ λ ₯λλ λ°μ΄ν°λ€μ μΆλ ₯μ κ·Έ νμ κ³Ό μμλ₯Ό μμμΌνλ€.
-> μ μ§λ³΄μμ±μ΄ λ¨μ΄μ§κ³ , 보μμ μ·¨μ½νλ€.
λν λ©μλ
writeObject(dt);
readObject();
- κ°μ²΄μ νλ(μΈμ€ν΄μ€ λ³μ)
- μ§λ ¬ν
- μ‘μ
--->
- μμ
- μμ§λ ¬ν
readObject(); // ClassNotFoundException dt = new Date();
- Date ν΄λμ€ μ°ΎκΈ°
- JVMμ΄ λ‘λ
- λ°μ΄νΈμ½λ κ²μ¦
- μΈν°ν리νΈ
-> Class clazz = Class.forName("Date");
ν΄λμ€ νμ μ κ°μ²΄μμ±
-> clazz.newInstance();
κ°μ²΄μΈμ€ν΄μ€λ³μλ₯Ό μ±μ : setter
νμ©? : λΆμ°μμ€ν μμ μ¬μ©νλ€!
RMI(Romote Method Invocation)
InputStream is = System.in; //-> νμ€ μ
λ ₯μμ€ν
μ InputStream νμ
InputStreamReader isr = new InputStreamReader(is); // μλ°μλ§ μλ μ°©ν λ
μ Byte -> Char
BufferedReader br = new BufferendReader(isr); //(νμ€ μ
λ ₯μ BufferedReader λ°μ μλΉ!)
String line = br.readLine();
--κ°λ¨νκ² κ΅¬νν κ²μ΄ λ°λ‘ Scanner!
Scanner sc - new Scanner(System.in);
sc.nextLine();
Java SE μ λ³΄μ© ν΄λμ€
- Object
- Class
- File