The following notes are based on the book: << Head First JAVA >> and video series: 手把手教你用Java基础教程 - 北京尚学堂 - 马士兵
- Java is a interpreted language
After .java is compiled into .class, JVM takes .class as input, one line at a time, translates a line into machine language to have it executed.
(The other kind is complied language, ex. C/C++)
- Garbage Collection
Java has its own garbage collector to automatically clean up the unused ram. (C/C++ needs coder to manunlly specify the clean-up process)
- Java’s work flow: JVM
- Ram segement
- heap: new.
- stack: local data.
- data segment: static data, const data.
- code segment: code.
- Terminology
JDK: java development kit (developer)
JRE: java runtime environment (user)
- Run java in shell
1 | $ javac HelloWorld.class //compile |
- Rules
- one .java can have at most only one public class
- public class, if exists, name has to be same as filename
- execution entry is fixed
public static void main (String[] args)
1 | public class MyFirstApp{ |
- Commement
1 | // single line comment |
- Java keywords
abstract |
continue |
for |
new |
switch |
---|---|---|---|---|
assert *** |
default |
goto * |
package |
synchronized |
boolean |
do |
if |
private |
this |
break |
double |
implements |
protected |
throw |
byte |
else |
import |
public |
throws |
case |
enum ** |
instanceof |
return |
transient |
catch |
extends |
int |
short |
try |
char |
final |
interface |
static |
void |
class |
finally |
long |
strictfp ** |
volatile |
const * |
float |
native |
super |
while |
- Java Variables
1 | int i = 10; // default inteiger |
Smaller types of variables can be cast to larger types:
byte, short, char -> int -> long -> float -> double
1 | public class TestConvert { |
- Java operators
1 | /* binary oprators |
- Others
- java uses unicode (UTF-16), 1 character always takses 2 bytes.