1 minute read

This is a self note while taking the online course from: LinkedIn Learning: Java 11+ Essential Training by David Gassner


1. Principle of Java

  • Simple, object-oriented, and familiar
  • Robust and secure –> designing everything as object
  • Architecture neutral and portable

    • compiles to byte code (not machine code) –> can be loaded on any operating system that has a Java virtual machine
    • applications are portable between platforms without recompiling

      Java runtime architecture: java runtime architecture

  • High performance
  • Interpreted, threaded, and dynamic
    • compiled to a format that’s interpreted at run time (directly machine code X) ==> interpreted
    • easy to build application do more than one thing at the same time ==> threaded(multi-threads)

2. Java syntax

  • Java Class file

    • all code is defined in classes
    • java source code (.java file) can be compiled using javac command
    • java command runs the compiled bytecode file with JVM
    pacakge com.example; // 1)
    
    public class Main { // 2)
        public static void main(String[] args) {
            System.out.println("Hello World");
        }
    }
    
      1. package declaration: indicates where the file is stored in terms of the directory structure of the application (organizing the code)
      1. class declaration: class name + class members + main method
  • Identifier Conventions

    • Classes start with an uppercase character
    • Method, variables start with an lowercase character
    • Constants are all uppercase

3. Memory Management in Java

  • Java automatically allocates and deallocates memory as needed (in runtime)
  • Local variables, function calls –> Stack
  • Objects, member variables –> Heap
  • Objects are reatained in memory until dereferenced
  • After dereferenced –> Garbage Collector

Tips for memory management:

  • minimize the number of objects
  • use System methods to check memory usage (Runtime.maxMemory(), Runtime.totalMemory(), …)

Tags:

Categories:

Updated: