목록Programming/Java (8)
개발동
1. src.java (소스코드) ->프로그래머가 작성한 코드 2. src.class : java파일을 컴파일했을때 생성되는 코드 [명령어] javac src.java > [출력결과] src.class 3. src.bc : 바이트코드를 메모장으로 열 수 있는 파일형식으로 class파일(바이트코드)을 디스어셈블했을때 생성되는 코드 [명령어] javap src.class > [출력결과] src.bc 바이트 코드는 jvm에서만 실행되는 기계어로서 binary code(이진 코드)이다.
class Product{ int price; Product(int price){ this.price = price; } } class Tv extends Product{ Tv(){ super(100); } public String toString() { return "Tv"; } } class Computer extends Product{ Computer(){ super(200); } public String toString() { return "Computer"; } } class Audio extends Product{ Audio(){ super(50); } public String toString() { return "Audio"; } } class Buyer{ int money = 600; st..
부모클래스 타입의 참조변수가 자식 클래스의 인스턴스를 참조했을때, 부모&자식 내에 이름이 같은 멤버변수나 함수가 있을 경우 멤버함수의 경우 : 참조변수는 자식 인스턴스의 함수를 따라감 (Overriding 되어, 무조건 참조한 자식 인스턴스의 메서드로 적용됨) 멤버변수의 경우 : 참조변수의 데이터 타입을 따라감 (참조변수의 데이터 타입에 따라 달라짐) class Parent { int x = 100; void method() { System.out.println("Parent"); } } class Child extends Parent { int x = 200; void method() { System.out.println("Child"); } } public class BindingTest { publ..
상속이란, 기존 클래스의 코드를 재사용하여 새로운 클래스를 생성하는 것으로 자식클래스는 부모클래스의 멤버를 상속받는다. (초기화 블럭과 생성자는 상속 받지 아니함) ※상속이외에도 클래스간에 포함관계를 맺음으로써 클래스 재사용이 가능하다. class Point { int x, y; } class Circle0 extends Point { int r; } class Circle { Point p = new Point(); int r; } public class ExtendsEx { public static void main(String[] args) { // TODO Auto-generated method stub Circle c = new Circle(); c.p.x = 10; c.p.y = 10; c.r..
Calendar 클래스 - Calendar 클래스는 추상 클래스이기 때문에 new Calendar();로 직접 객체를 생성할 수 없고, getInstance(); 메서드를 통해 구현된 인스턴스를 반환해 사용해야한다.
1. Math클래스의 static double random() 함수 static double random() 0.0이상 1.0미만의 난수를 double값으로 반환 public class RandomSample { public static void main(String[] args) { // TODO Auto-generated method stub for (int i =0; i
public class StringSample { public static void main(String[] args) { // TODO Auto-generated method stub String fileName = "2021.report.hwp"; System.out.println(fileName.indexOf(".")); int positionOfDot = fileName.indexOf("."); System.out.println(fileName.substring(positionOfDot+1)); System.out.println(fileName.lastIndexOf(".")); positionOfDot =fileName.lastIndexOf("."); System.out.println(fileNa..
숫자야구게임 1. 정답을 난수로 구한다. - 1~ 9까지 3개의 수. 중복되면 안됨. 2. 사용자의 입력을 받는다. - 1~9까지의 3개의 수. 중복되면 안됨. 3. 판정 - 볼: 자리가 다르고, 값이 일치 - 스: 자리가 같고, 값도 일치 4. 3스트라이크 이면 종료. ============================================= *추가 1. 새게임기능 2. 종료기능 import java.util.Scanner; import java.util.Random; class Game{ final int arr_SIZE = 3; int [] arr= new int[arr_SIZE]; int [] arr_sort= new int[arr_SIZE]; int [] arrInput= new int[..