import java.io.*; public class _4_1 { public static void main(String[] args) throws Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int su1 = 0; System.out.print("su1 = "); su1 = Integer.parseInt(in.readLine()); if(su1 > 100){ // 강제적으로 예외 발생 System.out.println("예외 발생 :"); Exception ex = new Exception(">100"); throw ex; } } }
// 여러개의 쓰레드가 한꺼번에 동작할 때... 발생하는 문제의 해결.... // 하나의 데이터 처리에 대해 쓰레드가 설정되어 있다면, 그 데이터를 관리하는 메소드는 동기화 할것.. // 하나의 메소드 내에서는 지역적으로 동기화... class K extends Thread{ private int x = 100; public void setX(int x){ this.x +=x; } public int getX(){ return x; } public synchronized void run(){ // 한사람이 이 메소드를 호출하면 다른이가 호출하지 못하도록 Lock(메소드 전체의 동기화) setX(200); System.out.println("x = " + getX()); } /* public synchro..
import java.util.*; import java.text.*; class AAA extends Thread{ public void run(){ while(true){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date d = new Date(); String str = sdf.format(d); try { Thread.sleep(1000); System.out.println("현재시간 : "+str); } catch (InterruptedException e) {} } } } public class _3_1 { public static void main(String[] args) { System.out.println(..
class TTT extends Thread{ public void run(){ System.out.println("\nTTT start!!"); // currentThread() : 현재 돌아가는 쓰레드의 이름 System.out.println("현재 Thread = " +Thread.currentThread()); System.out.println("\nTTT end!!"); } } public class __2_1 { public static void main(String[] args) { System.out.println("Main Start!"); // active Thread() : 현재 돌아가는 쓰레드 개수 System.out.println("현재 수행중인 전체 쓰레드 개수 = " + Thr..
// Thread 만들기 기본... // 2가지 방법이 있다. 그냥 두번째 방법으로 쓰는게 좋을듯.. ㅎㅎ class A extends Thread{ // 단일상속 public void run(){ // 쓰레드의 메인 메소드... System.out.print("A"); } } class B implements Runnable{ // 다중상속.. 다른 클래스로부터의 상속이 필요하면 써야징.... public void run(){ // 쓰레드의 메인 메소드... System.out.print("B"); } } public class _1_1 { public static void main(String[] args) { System.out.println("main start!"); new A().start()..
## 1바이트 입력 1 ## import java.io.*; public class _2_3 { public static void main(String[] args) throws IOException{ // 콘솔모드 FileInputStream fis1 = new FileInputStream(FileDescriptor.in); System.out.print("문자는? "); char ch = (char)fis1.read(); // 입력받은 값(문자 1개)의 아스키 값 int -> char System.in.read(); // 엔터키 처리... System.out.print("문자열은?"); byte[] by = new byte[1024]; fis1.read(by); // read()의 매개변수로 배열을 ..
## 1바이트 출력 1 ## import java.io.*; public class _2_1 { public static void main(String[] args) throws IOException{ byte[] by = new byte[]{'R', 'a', 'i', 's', 'o', 'n'}; // 콘솔모드..... FileDescriptor.out: 콘솔에 출력 FileOutputStream fos1 = new FileOutputStream(FileDescriptor.out); fos1.write(by); fos1.write(by,2,1); fos1.write(65); fos1.close(); // 파일 모드..... true : 기존 내용에 추가 FileOutputStream fos2 = new ..
class Outer { // outer class private int x = 100; public void aaa(){} class Inner { // inner class private int y = 200; public void bbb(){ // Outer의 멤버를 사용할 수 있다. aaa(); System.out.println("x = " + x); System.out.println("y = " + y); } } } public class Test { public static void main(String[] args) { // Outer o = new Outer(); // Outer.Inner i = o.new Inner(); Outer.Inner i = new Outer().new Inner..
1. 중첩 클래스 - 클래스의 효율적인 관리를 위한 하나의 형식 - Outer class의 멤버를 Inner class가 직접 접근 가능, 반대는 불가 (scope) - Outer class에서 Inner class를 접근하기 위해 instance 생성 - Inner class static 멤버 사용 불가 class Outer { // outer class private int x = 100; public void aaa(){} class Inner { // inner class private int y = 200; public void bbb(){ // Outer의 멤버를 사용할 수 있다. aaa(); System.out.println("x = " + x); System.out.println("y = ..
var su=false; document.write(!su+" "); su=1; document.write(~su+" "); // 000 0001 => 1111 1110=>-2 su=10; document.write(++su+" "); document.write(--su+" "); a_1=10; b_1=++a_1; document.write("a_1="+a_1+", b_1="+b_1+" "); a_2=10; b_2=a_2++; document.write("a_2="+a_2+", b_2="+b_2+" ");