January 2017

Class Loaders in Java

  • Satish 

1. Introduction to Class Loaders Class loaders are responsible for loading Java classes during runtime dynamically to the JVM (Java Virtual Machine). Also, they are part of the JRE (Java Runtime Environment). Hence, the JVM doesn’t need to know about the underlying files or file systems in order to run Java programs thanks to class loaders. Also, these Java classes aren’t loaded into memory all at once, but when required by an application. This is where class loaders come into the picture.… Read More »Class Loaders in Java

Java – Try with Resources

  • Satish 

1. Overview Support for try-with-resources – introduced in Java 7 – allows us to declare resources to be used in a try block with the assurance that the resources will be closed when after the execution of that block. The resources declared must implement the AutoCloseable interface. 2. Using try-with-resources Simply put, to be auto-closed, a resource must be both declared and initialized inside the try, as shown below: try (PrintWriter writer = new PrintWriter(new File(“test.txt”))) { writer.println(“Hello World”); } 3. Replacing try–catch-finally With try-with-resources The simple and obvious… Read More »Java – Try with Resources