본문 바로가기

학과 공부/컴퓨터프로그래밍2(자바)13

6/11 equals: basic method in class Object class Class{String getName(){}} //Integer x = new Integer(1); Integer x = 1; 두줄은 같은 일 system.out.println(x+1) 불가능 15번째 페이지 왜냐하면 x는 Object 대신 Integer y=(Integer)x;sysout(y+1) 2018. 6. 11.
4/30 garbage collectionaliasing 2018. 4. 30.
4/16 dangling else problem package javaclass0416;//data field는 두개 method는 1개, 여기서 method는 constructorpublic class Point {double x,y;static int s;Point(double initx, double inity){x=initx;y=inity;s=5;}double distance(Point other) {double dx=x-other.x;double dy=y-other.y;return Math.sqrt(dx*dx+dy*dy);}public static void main(String[] args) {// TODO Auto-generated method stubPoint p=new Point(1,2);Point.. 2018. 4. 16.
4/11 static variable메모리에->name, type, extra space for value directly instance variable메모리에->name type, 실제 값은 적혀있지 않아 constructor->initialize int [] ary={3,2,1};code simpler no index 2018. 4. 11.
4/9 class public class 차이점: javac는 public class와 파일명이 같은지 본다! private -> should be used inside the class 에러가 나지 않는다!class Sample{private int data_field;void foo() {data_field=1;}public int data_field() {return data_field;//private int data_field를 가리킨다}}다른 클래스에서 Sample x = new Sample();System.out.println(x.data_field()); getter와 setter class Sample{private int data_field;void foo() {data_field=1;} //.. 2018. 4. 9.
4/4 Overlapping segments boolean isHit(Rectangle r){return isOverlapping(x, x+w, r.x, r.x+r.w)&&isOverlapping(y, y+h, r.y, r.y+r.j) } java knows the type of variable parameter는 다르게 같은 이름으로 method를 만들 수 있따! public static void test(Rectangle r) {System.out.println("Rectangle");}public static void test(Rectangle c) {System.out.println("Circle");} parameter의 type이 같은 같은 이름의 method -> 에러 parameter갯수 달라도 .. 2018. 4. 4.
4/2 compile->statement that creates instance->find for source file inside the directory->compile name of source file을 name of the class해야하는 이유이다! look for source file to compile! Test01.java에는 circle이 없지만rectangle.java에는 그런 내용이 있고Test01.java에서는 Circle이 컴파일 되지 않지만, rectangle.java에 명시되어 있기 때문에Test01.java가 컴파일될때 Circle.java도 컴파일된다! class method instance method 차이 class method: static이라는 keyword로 선언된 메소.. 2018. 4. 2.
3/28 int x = 1; for(int i = 0; i < 16; i++) { x *= 2; } char c = (char)x; int y = c; System.out.println(y); 한글자에 16비트!이므로 16번 *2를 하면 더 커지면 오버플로우 char: 16비트int: 32비트long: 64비트 `Scanner in a package!!` 패키지가 다르면 클래스 이름이 같을 수 있다. system.in.read()가 없는 이유는? 디바이스 has to wait until the user press enter1 9 3 을 해석할 수 있는 방법이 매우 다양하다.그래서 Scanner input=new Scanner(System.in)을 사용해서input.nextInt()이런식으로 method를 활용! .. 2018. 3. 28.
3/26 static variable applies all the instances if문에는 불린만 들어가야 한다if(x=3)하면 에러! dangling if onsider the following scenario :if(x > 0)// first/outer unmatched ifif(x 0){if(x 0)// first/outer ifif(x "false"를 출력한다. public class Exercise{ public static void main (String[] args){ int x=1; for (int i=0;i 2018. 3. 26.