Java는 대중적인 프로그래밍 언어이며, 모바일 앱, 웹 앱, 데스크탑 앱, 게임 등의 개발을 위해 사용된다.
Java는 객체지향(object-oriented programming, OOP) 언어이다.
C/C++의 컴파일러가 소스코드-기계어를 직접 컴파일하여 링크하는 것과 달리,
JVM이 소스코드-바이트코드인 클래스파일(.class)-기계어를 실행한다.
캡슐화 (Encapsulation)
클래스(class)를 통해 변수와 함수를 하나의 단위로 묶는 것(bundling)이다. 이러한 정보은닉(information hiding)은 접근자을 통해 프로그래밍한 정보가 외부러 드러나지 않도록 모듈(module) 내부 응집도(cohesion)를 높이고, 모듈 간 결합도(coupling)를 낮춰 유연한 유지보수가 가능하다.
상속성 (Inheritance)
재사용성 부모 클래스(상위 클래스)가 자식 클래스(하위)에게 속성을 물려주어, 코드를 재사용한다.
추상화 (Abstraction)
객체의 공통된 속성과 행위를 추출하여, 불필요한 공통점을 제거한다.
다형성 (Polymorphism)
오버라이딩, 오버로딩 특성을 통해 같은 형태이지만 다른 기능을 하도록 정의한다.
Main 함수
static : 메서드에 static 키워드가 붙으면 클래스 메서드가 되어 객체를 만들지 않아도 ‘클래스명.메서드명’ 형태로 호출할 수 있다.void : 메서드의 리턴 자료형으로, void는 리턴값이 없음을 의미한다.String[] args : 메서드의 매개 변수로, args 변수는 String[] 배열 자료형임을 의미한다. args는 argument의 줄임말로, 인수를 의미한다. args 대신 다른 이름을 사용해도 상관없다.Method
메서드(method)는 호출된 코드 블록으로, 파라미터(parameters)를 통해 데이터를 메소드에 넘길 수 있다. 이때, 메서드는 함수(functions)를 통해 특정 행위/행동을 수행 한다.
Class
클래스(class)는 객체(objects), 특성(attributes), 메서드(methods)를 담고 있다.
예를 들면, 자동차(object)는 색깔, 모델, 브랜드 등의 특성(attributes)를 갖고 있다. 그리고 자동차를 1)시동을 걸고, 2)핸들로 방향을 조절하고, 3)가속하거나 4)브레이크를 주면서 (methods) 운전을 할수 있다.
public class Car
{
private String carModel; //Model
private String carTrim; //normal, advanced, premium
private String carColor;
protected int speed; // protected : 스피드 변경 시 수정
public Car() {}
public Car(String carmodel) //생성자
{
this.carModel = "carmodel"; //자동차 모델
this.carTrim = "normal"; //자동차 모델 버전
this.carColor = "white"
this.speed = 60; //자동차 기본 속도 설정
}
public String getModel(int speed){
return this.carModel;
}
public int getSpeed(int speed){
return this.speed;
}
public void setAccelertor(Event e){
for (int i=0; i>0;i++){
speed -=0;
}
}
public void setBreak(Event e){
for (int i=0; i>0;i++){
speed -=1;
}
}
}
public class Main {
public static void main(String[] args) {
System.out.println("Hello Jasmine");
}
//etc...
[1] https://www.w3schools.com/java/
[2] https://s-bug.tistory.com/57#1.%20%EC%9E%90%EB%B0%94(Java)%EB%9E%80%20%EB%AC%B4%EC%97%87%EC%9D%B8%EA%B0%80%3F%E2%9C%85-1
[3] https://ko.wikipedia.org/wiki/%EC%9E%90%EB%B0%94_(%ED%94%84%EB%A1%9C%EA%B7%B8%EB%9E%98%EB%B0%8D_%EC%96%B8%EC%96%B4)
[4] https://wikidocs.net/199