목록JAVA (15)
유디의 공간정보·개발일기
import com.lx.Car; public class CarTest { public static void main(String[] args) { Car car1 = new Car(); car1.setName("Doc Hudson"); car1.setSpeed(300); String name1 = car1.getName(); int speed1 = car1.getSpeed(); System.out.println(name1 + "의 스피드 : " + speed1); Car car2 = new Car(); car2.setName("Sally Carrera"); car2.setSpeed(200); String name2 = car2.getName(); int speed2 = car2.getSpeed(); S..
class Person { public class PersonTest { public static void main(String[] args) { int age = 12; String name = "Anonymous"; selfIntroduce(); getPopulation(); } private static void selfIntroduce() { int age = 3; String name = "철수"; System.out.printf("내 이름은 %d이며, 나이는 %d살 입니다.", name, age); } private static void getPopulation() { int numberOfPersons = 0; Person persons = new Person(); int result = n..
public class MyClassTest_0720 { public static void main(String[] args) { //class : 변수와 함수들의 집합 MyClass_0716 my = new MyClass_0716(); //my : myclass 타입의 로컬변수 //new MyClass : 생성자를 호출한 것이며, 힙에 객체가 생성된다. // = 이라는 할당연산자로 인해 힙에 생성된 객체의 주소가 my변수에 저장된다. int count = 500; //얘는 Stack영역에 direct로 바로 값이 할당(assign)되는데 my.count = 1000; //Myclass는 Stack영역에는 주소만 저장되고, Heap영역에 생성된 객체가 활용됨 //Heap 내부에 할당된 메모리 공간의 co..
import java.util.ArrayList; import java.util.Calendar; public class myjava_0719 { public static void main(String[] args) { //java기본, SQL --> 둘을 연결함 //Compile, Execute, //Data Type, Variable, Method //타입은 크기가 있다. 한정적인 메모리공간을 효율적으로 사용하기 위해 변수의 크기를 적절히 지정할 필요가 있다. //메모리, 메인메모리, 디스크 //nano sec, milli sec //int, long, double, char, byte, boolean, float //int count = 500; // int-->4bytes, long-->8byte..
public class MyClass_0716 { public static void main(String[] args) { int ran = (int) (Math.random()*100); //랜덤하게 만들어진 숫자는 실수형이므로 100을 곱해서 int형(정수)으로 변환 if(ran%2 != 0) { //나머지 값이 홀수인지를 물어보는 것(ran을 2로 나눈 나머지가 0이 아니라면) System.out.println("Wow"); } else if(ran%2 == 0) { //나머지 값이 짝수라면 } else if(ran%2 == 1) { //나머지 값이 홀수라면 } //로또번호를 생성하여 출력한다. //로또번호를 만들어서 리턴하는 함수를 정의하고 호출 int[] list = makeLotto(); //..
- House class 에 Dog와 Cat 의 ArrayList를 각각 만들고 dogs =, cats = 초기값을 줌 [House] package com.lx.animal; import java.util.ArrayList; public class House { public ArrayList dogs = new ArrayList(); public ArrayList cats = new ArrayList(); } [Cat] package com.lx.animal; public class Cat { public String name; public Cat() { } public Cat(String name) { this.name = name; } } [Test1] package com.lx; import jav..
- 인터페이스 : 통로 프로토콜 : 약속 - implements Calc : 인터페이스 Calc를 지키겠다는 의미 - abstract class : 추상클래스, 미완성이라 실제 객체를 못 만듦, 아직 사용할 수 없는 틀 Calculator (abstract class) implements Calc Calculator2 (class, Calculator를 상속) extends Calculator Calc (interface) [Calc interface] package com.lx.calc; public interface Calc { public int add(int a, int b); public int subtract(int a, int b); public int multiply(int a, int b..

- try-catch절로 어떤 코드를 잡아두면 에러가 생기더라도 비정상종료되지 않고 다음 코드를 실행함 (단 결과는 이상하게 나올 수 있다.) - try-catch { } 안에 들어간 변수는 { } 밖에서 쓰지 못하므로 미리 위에서 적는다. { } 안에는 변수타입 안적고 변수만 적으면 됨 try { a = Integer.parseInt(inputA); b = Integer.parseInt(inputB); } catch (Exception e) { e.printStackTrace(); } [Test1] import com.lx.person.Baby; import com.lx.person.Leg; import com.lx.person.Person; public class Test1 { public stati..