Posts in "Core Java"

Java Hashmap tutorial

Java HashMap is a HashTable based implementation of Map. This is the reason why the interviewer always asks for the difference between HashMap and HashTable. HashMap is mostly equated to HashTable except below two differences. HashMap is unsynchronized while HashTable is synchronized. HashMap permits null while HashTable doesn’t. Important Property of HashMap DEFAULT_INITIAL_CAPACITY  Default Initial… Continue reading

this keyword in Java

What is this this is a keyword in Java. It can be used inside the method or constructor of a class. It(this) works as a reference to the current object, whose method or constructor is being invoked. This keyword can refer to any member of the current object from within an instance method or a constructor.

Order of execution

In this article, we will learn about the order of execution of blocks in Java. Different blocks and their order of execution in Java Class Static Block Init Block(Anonymous Block) Constructor /* * Here we will learn to see how the different part (Ananymous Block, Constructor and Static Block ) of class will behave * and… Continue reading

Exception Handling – The try-with-resources statement

Generally finally block is used to close all the resources (viz., file, database connection, socket or anything that should be closed after its task is done) to prevent any leaks. Sample code: public class ResourceMgt { public static void main(String[] args) { BufferedReader br = null; try { br = new BufferedReader(new FileReader("C://test.txt")); System.out.println(br.readLine()); }… Continue reading