Scroll to top

Core Java

Posted by JBT
July 22, 2017

jdk vs jre vs jvm

In order to understand JDK vs JRE vs JVM. You need to first understand each and every term. So let’s start by defining JDK (Java Development Kit), JRE (Java Runtime Environment), and JVM (Java Virtual Machine).

Read More
Posted by JBT
June 20, 2017

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());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (br != null)
				try {
					br.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
		} //finally
	} // main
}
If you look at the above sample code, to close the BufferedReader resource, we had to check if it is still open and then invoke the close() method. There is a possibility of the close method throwing an exception and hence it has to be surrounded in a try catch block. This code is to be repeated for every resource that is opened. For big applications, you will see a lot of duplicate code due to this.

Read More
Posted by JBT
May 29, 2017

Exception Handling – try catch Java blocks

As developers, we deal with risky situations on a daily basis. Server goes down, or there isn’t enough space to allocate objects on the heap or file is not present in the given location and so on. So every time we decide to do a risky action, we have to inform the compiler that we know it is a risky thing and we are ready to handle it. How we treat it is not the compiler’s problem. All it needs to remember is that we are taking care of any exceptional situations that might arise. We handle these situations by wrapping our code in try catch in Java.

Read More
Posted by JBT
April 20, 2017

Java Thread Tutorial

Thread term can be used in two ways

  • An instance of class java.lang.Thread
  • A Thread of Execution

Read More
Posted by JBT
September 26, 2016

Introduction to lambda expressions

In this article I will give you a quick introduction about one of Java 8's new features: lambda expressions. I will show you what lambda expressions are and how can you utilize this new feature.

Read More
Posted by JBT
February 15, 2016

Java virtual machine basics

JVM is an abbreviated form of Java Virtual Machine. It is a Java byte code processing engine that converts Java byte code into machine language, which is then executed by the machine (computer). Java byte code is an intermediary language between Java and the machine on which it has to be executed, and this execution can be done when JVM processes Java byte code into the machine language.

Read More
Posted by JBT
February 12, 2016

Java 8 lambda foreach List

You must have heard about Lambda Expression introduced in Java 8. Soon we will cover detail topics on it. But now in this article i will show how to use Lambda expression to iterate Collection List. If you want to iterate over Map you can check Java 8 lambda foreach Map article.

Read More
Posted by JBT
February 12, 2016

Java 8 lambda foreach Map

You must have heard about Lambda Expression introduced in Java 8. Soon we will cover detail topics on it. But now in this article i will show how to use Lambda expression to iterate Collection.

Read More
Posted by JBT
February 1, 2016

Java enum example

/** * @author GHajba * */ public class Main { public static void main(final String......

Read More
Posted by JBT
January 16, 2016

Java Enum (Enumerations)

In this article I'll write about Java Enumerations which are the most elegant way to define and use constants in your application. This is the basic feature every one knows but there are some more which you might don't know.

Read More