1.First java program

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

2.Java Virtual Machine (JVM)

pF1uiYn.png
New project 后大概如图所示 src是文件目录 以下是创建文件示意图
pF1uVyT.png

3.Which PART?

class / main method / statement / semicolon / braces / squared / brackets / parentheses / parameter
public class Hello { //class
public static void main(String[] args) { //main method 
System.out.println("Hello World"); //statement 
}  //parentheses圆括号 parameter参数
}  //semicolon 分号 braces 大括号 squared 方括号 brackets 中括号

pF1unw4.png

4.Object-Oriented Language

面向对象设计语言:JAVA
Java is an Object-Oriented Language:
○ every Java file must contain a class类declaration声明 
○ all code代码 is written inside在 a class 类
○ to run a Java program, need to define a main method定义主方法

5.IN-class-quiz

public class Hello { 
public static void main(String[] args) { 
int num = 5; 
num = num + num; 
System.out.println(num); 
} 
}
Output: 10

6.TIPS:

○ single quote \'  单引号’
○ double quote \" 双引号”
○ new line character \n 新一行Enter
○ backslash \\ 反斜线\

7.For Example

7 + 4 = num1
6 + 4 = num2
System.out.println(‘\’num1 + num2 = ‘ + (num1 +num2) + ‘\’’)
Output: ‘num1 + num2 = 21’
int&float&double differents
Println输出换行
print 输出接上

8.Binary, Bit and Bytes

To a modern computer, everything is binary
○ 1 bit is 1 binary digit: 0 or 1 ; ON or OFF ; TRUE or FALSE
● Every bit we add doubles the total we can represent
○ 1 bit – 2
○ 2 bits – 4
○ 3 bits – 8
○ 4 bits – 16
○ ...
○ 8 bits – 256 – one Byte
● Mathematically: n bits yields 2n patterns (2 to the n-th power)
decimal to binary
8 bits = 1 byte ≈ often 1 character, e.g. "a"
1024 bytes = 1 kilobyte ≈ several paragraphs
1024 kilobytes = 1 Megabyte ≈ about 200 pages of text
1024 Megabytes = 1 Gigabyte ≈ 256 MP3 files
1024 Gigabytes = 1 Terabyte ≈ 40 large movies

9.Hexadecimal

● Base 16 numbering system
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
● Represented with 0x__
i.e. 255 in decimal is 0xFF
● More readable than binary 比二进制更可读
decimal 121 10进制
binary 01111001 2进制
hex 0x79 16进制
● Stores more information than binary 存储比二进制文件更多的信息
hex and binary relate well 十六进制和二进制之间的关系很好
1 hex digit can always be represented with 4 binary digits
1个十六进制数字总是可以用4个二进制数字表示
no relationship like this between decimal and binary

10.24-bit Colour

● 24-bit colour means that there are 24 bits allocated for RGB channels
为RGB通道分配了24位
○ 8 bits for red, 8 bits for green, 8 bits for blue 红绿蓝
● How to represent this colour purple?
○ rich purple? deep purple?
● Need a better representation
○ often use hexadecimal 0xd400ff
○ what does that mean? 0x是十六进制的开头
● Hex 0xd400ff
○ d4 – red bits
○ 00 – green bits
○ ff – blue bits
● Compact, as opposed to 24-bit value for this colour purple
○ 110101000000000011111111

11.ASCII

ASCII = American Standard Code for Information Interchange
● Recall, computers can only store binary
○ includes characters
● ASCII is an encoding scheme 编码方案
that represents each character
with a 7-bit value

12.What’s Java?

●Created by James Gosling Modern object-oriented language Continuously improved since 1990s
● Widely used
Mars rover, cell phones, web servers, ...
● Unfortunately, Java is verbose Using more words – compare with Python!
● More importantly, it is not about the language
The programming skills that you learn in this course will apply to many Languages

13.JAVA basic principle

Case sensitive:Java is case sensitive, This means that the identifier Hello is different from the hello.
大小写区分
Class name: For all classes, the initials of the class name should be capitalized. If the class name consists of several words, then the first letter of each word should be capitalized, such as MyFirstJavaClass.
类名命名:每个单词首字母大写
Method name: All method names should start with lowercase letters. If the method name contains a number of wordm90 |s, the following first word is capitalized.
方法名命名:小写字母开头,但是若干单词后面每个单词首字母大写
Source file name: The source file name must be the same as the class name. When saving a file, you should save the class name as a file name (remember that Java is case sensitive), and the file name is 后缀suffix. java.(If the file name is not the same class name).
文件名必须是类名
Main method entry: All Java programs are executed starting by the public static void main (String [] args) method.(所有程序必须从该方法开始执行)