Skip to content

Instantly share code, notes, and snippets.

@falsy
Last active June 6, 2017 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save falsy/69b410abd490d04ad4c2103aa7d6ee01 to your computer and use it in GitHub Desktop.
Save falsy/69b410abd490d04ad4c2103aa7d6ee01 to your computer and use it in GitHub Desktop.
하나씩 해보는 처음 해보는 자바

하나씩 해보는, 처음 해보는 자바

이클립스 설치

  1. 이클립스 홈페이지 에서 다운로드를 받아서 설치
  2. 뭐가 뭔지 모르니까 그냥 기본 값으로 '다음' 연타
  3. 본능적으로 뭔가 모르게 java EE 설치
  4. 프로젝트 만들기

hello world

//Hello.java
public class Hello {
  public static void main(String[] args) {
    System.out.println("hello world");
  }
}

감격! console 에 hello world가 찍혔다. 이렇게 나는 1시간만에 자바에 대해 반이나 알아 버렸다.

시작이 반이니까...

클래스 명과 파일명이 같아야 하고 기본적으로 하나의 파일에 하나의 클래스, 두개 이상의 클래스가 있다면 main() 이 들어있는 클래스 명과 같아야 한다고 함.
참고: http://luckyyowu.tistory.com/190

클래스 명의 첫글자를 대문자로 하는건 대부분 언어의 암묵적 규칙인듯.

1. main()

php: __construct(), js: constructor() 같은 생성자 같은 메서드 인듯??

2. void

리턴 없음을 의미한다.

//eg.
public int getAge() {
  return age;
}
//리턴이 있다면 이렇게 리턴 타입을 명시

3. public

접근제어자 라고 부르나보다, default(명시하지 않았을때), private, protected, public 이렇게 총 4가지 권한이 있다.
public 은 전부다 접근이 가능하고 protected는 같은 패키지 안에서 가능하고 defualt는 동일 패키지 안에서 가능하지만 하위 클래스에서는 접근이 안되고 private는 클래스 내부에서만 접근이 가능하다.
참고: http://hyeonstorage.tistory.com/176

4. (String[] args) ???

이건 뭔지 모르겠다. 스트링 배열의 아귀먼트????
커맨드 라인에서 자바를 실행시킬때 매개변수를 전달할 수있게 지원해주기 위해서 사용되는 것이라고 하는데 하다보면 나중에 이해할 거 같으니 패스.
참고: http://hashcode.co.kr/questions/972/%EC%9E%90%EB%B0%94%EC%97%90%EC%84%9C-main%ED%95%A8%EC%88%98%EC%97%90-string-args%EB%9D%BC%EB%8A%94-%EB%A7%A4%EA%B0%9C%EB%B3%80%EC%88%98%EB%8A%94-%EB%AD%90%ED%95%98%EB%8A%94%EA%B1%B4%EA%B0%80%EC%9A%94

값 입력 받기와 연산

//ScannerAndSum.java

import java.util.Scanner;

public class ScannerAndSum {
  public static void main(String[] args) {
    
    Scanner input = new Scanner(System.in);
    int x;
    int y;
    int sum;
    
    System.out.print("첫번째 숫자 입력 : ");
    x = input.nextInt();
    
    System.out.print("두번째 숫자 입력 : ");
    y = input.nextInt();
    
    sum = x + y;
    
    System.out.println(sum);
  }
}

참고: http://luckyyowu.tistory.com/177

자바도 명명 규칙으로 낙타 표기를 하려나?? ... 아직 잘모르겠다.

1. System

java에서 스크린과 키보드를 통한 표준 입출력 제공 클래스라고 한다.
System.in, System.out, System.err가 있는듯 하다
참고: http://hyeonstorage.tistory.com/235

2. 데이터타입 속성

  1. 정수형
  • byte (8 bit)
  • short (16 bit)
  • int (32 bit)
  • long (64 bit)
  1. 문자형
  • char (16 bit)
  1. 실수형
  • float (32 bit)
  • double (64 bit)
  1. 논리형
  • boolean (1 bit)

데이터 타입 long은 리터널 뒤에 L을 명시해야한다.

참고: http://yun4794.blog.me/220987237677

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment