ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [Java 기본 02] Java file, java 프로그래밍 특징 및 작성법
    컴퓨터/Java 2019. 11. 20. 10:52

    -> 들여쓰기 제대로 하기!

    -> 들여쓰기 제대로 안돼 있을 때 메뉴바의 source -> correct indentaion (ctrl+i) 누르면 자동으로 들여쓰기 해준다

     

    * java : method, 클래스

     java에서는 함수라는 말을 쓰지 않고 method라는 말을 쓴다.

    c언어에서의 함수, function과 대응한다.

    c언어는 함수들의 집합일 뿐이고 함수들을 둘러싼 단위가 없다.

    반면, 자바에는 class(method들의 집합)가 있다.  

    자바 프로그래밍은 class들의 집합이다. class 안에 method들이 있다.

     

    * Each file has one primary class named after the file.

    public class HelloWorld {
    
    }

    클래스 이름이 대문자로 시작해야 한다.

    Inside the class we had a main() method which lists our program tasks

     

    * main method

    1) 클래스들이 각각 main method를 가져도 된다

    c 프로그래밍에서는 package 안에 main 함수가 하나여야 한다.

    java에서는 여러 개 가능

     

    2) In Java, every application must contain a main() method, which is the entry point for the application.

    All other methods are invoked from the main() method.

    The signature of the method : public static void main(String[] args) {}

    It accepts a single argument : an array of elements of type String.

    main method는 항상 다음과 같은 signature를 가진다

    public static void main(String[] args) {
    
    }

    Like classes, we used curly braces to mark the beginning and end of a method.

    Curly  braces mark the scope of our classes and methods. There are no semicolons at the end of a curly brace.

    - String[] args : placeholder for information we want to pass into our program

     

    * c언어의 print : java의 System.out.println

    System.out.println("Hello World!")

    쌍따옴표로 둘러싸면 출력된다.

    System : a class from the core library provided by Java

    out : an object that controls output

    println = print line : receives a single argument

     

    * Statements

    a statement is a line of code that executes a task and is terminated with a ;.

     

    * Comments

    bits of text that are ignored by the compiler.

    They are used to increase the readability of a program.

     

    출처 : codecademy

     

    '컴퓨터 > Java' 카테고리의 다른 글

    Conditionals and Control Flow  (0) 2019.11.21
    toString()  (0) 2019.11.21
    제네릭  (0) 2019.10.06
    형변환  (0) 2019.10.06
    Java.util.Arrays 클래스  (0) 2019.10.06

    댓글

Designed by Tistory.