Garbage Collection

class MyClass {
    private Connection con;
    public MyClass() throws Exception {
        con = DriverManager.getConnection("url", "username", "password");
    }
    @Override
    public void finalize() {
        try {
            if(con != null)
                con.close();
        } catch(Exception e) { }
    }
}
class Main {
	public static void method() throws Exception {
		MyClass my = new MyClass();
		my = null;
		System.gc(); // request GC
	}
	// ...
}
System.gc();
Runtime.getRuntime().gc();

JVM Architecture

Java Compilation Process

Hello.java --> Java Compiler --> Hello.class
javac Hello.java

Bytecode

.class --> JVM --> Windows (x86)
.class --> JVM --> Linux (ARM)