<1.1 A "Hello, World!" program>
- In Java, everything is an object. An object is an instance of a class.
ex) A "Hello, World!" program
1
2
3
4
5
6
7
8
9
10
11
|
package cse3040;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
// TODO Auto-generated method stub
}
}
|
cs |
- A class may contain methods. The main method is the entry point(starting point) of a program.
- It is declared as static, which means this method does not require an instance. entry point인 main method는 항상 static이다. (static 메소드 VS instance 메소드)
- There are four access modifier: public, protected, private, and nothing
- I can put multiple related classes in a package and can use hierarchical packages. ex)package sogang.cse.cse3040
- 한 줄 주석은 //, 여러 줄 주석은 /* ~~ */으로
- System.out is an instance of class PrintStream.
- Println is a method defined in the class PrintStream. This method is called "instance method", because it can be called using the instance of a class.
- We create an instance of a class using the keyword new.
ex) Random generator = new Random(); 으로 generator가 Random클래스의 instance가 된다.
<1.2 Primitive Types(원시 자료형)>
- In Java, most variables are objects(=instance of a class). still, Java has primitive types(원시 자료형).
- default값으로 정수는 int형, 실수는 double형이다.
- In Java, String is used much more frequently than char.
- In Java, you cannot convert boolean to integers.(1은 ture, 0은 false 아니다)
<1.3 Variables(변수)>
- The basic syntax of Java is very similar to C/C++.
ex) int total = 0, count; (multiple definitions in one line),
Random generator = new Random(); (definition + class instantiation)
- Variable name must start with a letter. (A number is not allowed)
- Variable name is case-sensitive. (대소문자 구분한다)
- According to naming convention, a constant variable should be named using upper_case letters.(상수는 대문자로)
ex) final int DAYS_PER_WEEK = 7; (keyword final를 통해 상수선언)
cf) import할거 있을 때 커서 올리고 Ctrl+Shift+O하면 import 자동으로 해준다.
<EX 소스코드>
github.com/HoYoungChun/Java_Language_Lecture/tree/master/EX02
HoYoungChun/Java_Language_Lecture
Contribute to HoYoungChun/Java_Language_Lecture development by creating an account on GitHub.
github.com
'JAVA > JAVA_Lecture' 카테고리의 다른 글
Lecture 05: Java Programming Basics (4) (0) | 2020.10.08 |
---|---|
Lecture 04: Java Programming Basics (3) (0) | 2020.09.14 |
Lecture 03: Java Programming Basics (2) (0) | 2020.09.10 |
Lecture 01: Course Intro / Introduction to Java (0) | 2020.09.09 |
Java Language Syllabus (0) | 2020.09.09 |