Java is an object oriented language with strict requirements:
Every Java file must contain a class declaration.
All code lives inside a class, even helper functions, global constants, etc.
To run a Java program, you typically define a main method using public static void main(String[] args).
Java is statically typed (not like Python):
All variables, parameters, and methods must have a declared type.That type can never change.
Expressions also have a type, e.g. “larger(5, 10) + 3” has type int.
The compiler checks that all the types in your program are compatible before the program ever runs! (This is unlike a language like Python, where type checks are performed DURING execution.) e.g. String x = larger(5, 10) + 3 will fail to compile.
Functions must be declared as part of a class in Java. A function that is part of a class is called a “method”.
All parameters of a function must have a declared type, and the return value of the function must have a declared type.
Functions in Java return only one value!
2. Compilation in Java
.class:
.class file has been type checked. Distributed code is safer.
.class files are ‘simpler’ for machine to execute. Distributed code is faster.
Minor benefit: Protects your intellectual property. No need to give out source.
3. Object-Oriented Programming
3.1 Class
A class serves as a template for all of its instances.
Abstraction focuses on exposing only essential features while hiding the implementation details. It is achieved through abstract classes or interfaces.
3.6.1 Abstract Class
Abstract Class cannot be instantiated, and it can only be inherited (extends).