Introduction, Code Structure and Exceptions
Intro¶
- Write Once, run anywhere
- source code -> javac compiler -> Byte Code -> Execute on Java Virtual Machines
- compared to c and rust java uses much more memory
- The JVM is capable of optimizing your code while it is running
Code Structure¶
- source file - Class Definitions- Method definition(s)- statements/loc
 
 
- Method definition(s)
 
- Class Definitions
- Anatomy of a class- when JVM starts running, it looks for the class you give at the command line
- Then it searches that class for a special function - public static void main
- There has to be one main method at least, not one per class but one for the entire codebase.
 
Exceptions to watch out for¶
- Booleans aand others are not compatible in Java
    int x = 1 while(x){}- The above piece of code will give type casting error as only boolean are allowed for conditional testing
 
- The == operator can be used to compare two variables of any kind, and it simply compares the bits.
int a = 3; byte b = 3; if (a == b) { // true }