[Java] JAVA1 ~11

더미·2023년 3월 2일

JAVA

목록 보기
1/2

생활코딩 JAVA1 강의
노션에 정리한 거 다시 옮기기

처음 ~ 11강?까지 들었고 대충 C랑 비슷한 내용이라서 쉬엄쉬엄 들었다. 객지 내용은 다음 번에 배울 때 나올 거 같네


jdk / ecplise download

Hello World

public class HelloWorldApp {
	public static void main(String[] args) {
		System.out.println("Hello World!!");
	}
}

Java 동작원리

Java Source code(.java) —compile(컴퓨터가 이해 가능하도록)—> Java Application(.class) —Run—> Java Virtual Machine —Run—> computer

Java 사용

데스크탑 애플리케이션 ex>GUI | 사물인터넷 ex>라즈베리파이 | 안드로이드 애플리케이션

Datatype

public class Datatype{
	public static void main(String[] args) {
		System.out.println(6); // Number
		System.out.println("six"); // String
		
		System.out.println("6"); // String 6
		System.out.println(6+6); // 12
		System.out.println("6"+"6"); // 66
		
		System.out.println(6*6); // 36
//		System.out.println("6"*"6");
		
		System.out.println("1111".length()); // 4
//		System.out.println(1111.length());
	}
}
public class Number {

	public static void main(String[] args) {
		// Operator
		System.out.println(6 + 2); // 8
		System.out.println(6 - 2); // 4
		System.out.println(6 * 2); // 12
		System.out.println(6 / 2); // 3
		
		System.out.println(Math.PI); // 3.141592653589793
		System.out.println(Math.floor(Math.PI)); // 3.0
		System.out.println(Math.ceil(Math.PI)); // 4.0
	}

}
public class StringApp {

	public static void main(String[] args) {
		
		// Character VS String
		System.out.println("Hello World"); // String
		System.out.println('H'); // Character
		System.out.println("H"); // String

		System.out.println("Hello "
				+ "World");
		
		//new line
		System.out.println("Hello \nWorld");
		
		// escape
		System.out.println("Hello \"World\""); // Hello "World"
	}

}
public class StringOperation {

	public static void main(String[] args) {
		
		System.out.println("Hello World".length()); // 11
		System.out.println("Hello, [[[name]]] ... bye.".replace("[[[name]]]", "egoing"));
		
	}

}

Variable

public class Variable {

	public static void main(String[] args) {
		
		int a = 1; // Number -> integer
		System.out.println(a);
		
		double b = 1.1; // real number
		System.out.println(b);
		
		String c = "Hello World";
		System.out.println(c);
	}

}

casting(명시적 형변환)

public class Casting {

	public static void main(String[] args) {
		
		double a = 1.1;
		double b = 1;
		double b2 = (double) 1;
		System.out.println(b);
		
//		int c= 1.1;
		double d= 1.1;
		int e= (int) 1.1;
		System.out.println(e);
		
		// 1 to String
		String f = Integer.toString(1);
		System.out.println(f.getClass());
	}

}

디버거

대충 c랑 비슷함

step into → 제공 method로 이동 가능 — step return : 빠져나오기

우측 상단 perspective 이용

입출력

import javax.swing.JOptionPane;

public class InputOutput {

	public static void main(String[] args) {
		
		String id = JOptionPane.showInputDialog("Enter a ID");
		System.out.println(id);
		
		String bright = JOptionPane.showInputDialog("Enter a Bright level");
		double moodLamp = Double.parseDouble(bright); // string -> double
		System.out.println(moodLamp);

	}

}

입출력 - arguments & parameter

Run → Run configurations에서 argumets “” “” 로 지정하고 args[0]으로 입력

목록 즐찾 하려면 Organize Run Favorites에서 add


sysout → Ctrl + Space

  • error: Editor dose not contain a main type Project Layout에서 bin, src 따로인데 메인 밑에 코드 파일 만들 경우
    1. src에 소스코드 넣기

    2. properties → Java Build Path의 Source에서 기존 src 폴더 삭제 후 최상위 폴더 add && default 폴더도 최상위로 변경

      추가

      src1과 src2로 소스코드 폴더를 나눌 경우 위의 properties 설정에서 소스를 src1,2 둘 다 체크 && 실행 파일 bin으로 저장하도록 default 변경 ⇒ class 파일이 bin에 생성됨

project 이름 우클릭 → class ⇒ 틀 자동 생성

폰트 확대 Ctrl + shift + ‘+’/’-’

Run 실행 Ctrl + F11

다음
JAVA1 ~끝(15)

0개의 댓글