Java Notes (1) - Introduction to Java & OOP
Course: Java Programming (Coursera)
Instructor: Dashi Tang, Peking University
Java History
- Born in 1995 by James Gosling, SUN.
- Platforms:
- Java SE: J2SE, Standard Edition.
- Java EE: J2EE, Enterprise Edition.
- Java ME: J2ME, Micro Edition.
What is Java
- Simple, OOP, cross-platform, secure, muti-threads.
- "C++--":
- No pointers, automatical memory control, stable data types, no header files, no macros, no multiple inheritance, no global variables other than classes...
Java Mechanism
- JVM (Java Virtual Machine)
- source.java --compile (javac)--> source.class (bytecode) --run--> JVM for different platforms
- JRE = JVM + API (lib)
- Load code (by class loader).
- Check code (by bytecode verifier).
- Run code (by runtime interpreter).
- Code Security
- Garbage Collection
- JDK (Java Development Kit) = JRE + Tools
Object-Oriented Programming
- Class is an abstract of objects, Object is an instance of class.
- Class = Field + Method
Features:
- Encapsulation
- Pack data and functions into a class.
- Allow selective hiding of properties and methods in an object.
- Inheritance
- Superclass and subclass could share data and methods.
- e.g.
//Superclass class Person{ int age; String name; void sayHello(){...} } //Subclass class Student extends Person{ String school; double score; void meetTeacher(){...} }
- Polymorphism
- Implementing the same fuction on different objects may generate different results.
- e.g.
foo(Person p){p.sayHello();} foo(new Student()); foo(new Teacher()); //Different results!
- Encapsulation
Written on April 13, 2015