java

Java 8 Date Time API Usage

Introduction Every effort we put in to showcase the extent of Java 8 Date Time API usage leaves us only scratching the surface of it. This post walks through a couple of examples and some standard methods that can be helpful in daily use. Timezone aspects are not covered in this post. Refer to this post to for an introduction to Java 8 Date Time API. Old And The New Let us see how date formatting code changes with the new Java 8 Date Time API. If you landed directly on this post, we recommend reading this introductory post first. [crayon-5925e1d196005056426164/] Goodbye ThreadLocals and c...
Read More

Try With Resources in Java 7 and Above

Introduction Try with Resources in Java 7 and above allows for automatic closing of resources that implement java.lang.AutoCloseable or the more familiar java.io.Closeable (which extends AutoCloseable) Anyone through a basic Java course will be familiar with this block of code. Open a text file to write data and close it when done. [crayon-5925e1d197f22614213928/] The method attempts to write to a file and throws any exception that hinders in achieving this. The finally block ensures that no file handle is left open by this method. But close() can throw an exception if closing the file f...
Read More

Resource Management in Game

Introduction This post is the next in the game development series. In this post we will learn about Resource Management in the Game. After writing the game engine, now we can add some background to our game. We will try to add our menu as well and try to add navigation in the menu. Once that is done we will be able to move through the menu and choose various options. Without wasting much time, lets dive in. Objects in the Game There are many different type of entities in our game. They can be categorized into Screens and Actors and few more. You have absolute freedom to make it more gran...
Read More

Understanding Classes in Java

Introduction After gathering some insight into Java Reference Types in the previous posts, now understanding classes in Java has become easier. We need to understand how a Reference Type comes to existence and more. Apart from that we must also learn about Interfaces and Enums which are the building blocks of any written program. A Class in Java A class declaration defines a new reference type and describes its implementation. A class contains members which are enclosed in the body of the class. Members may also be inherited from a Super Class or Interfaces. A member can be a field, a...
Read More

A Generic toString in Java

Alternative to Java's toString() method: A generic toString in java For the impatient readers who know the problem I am trying to solve and need the code can scroll down to the Source code section. If you are still reading then, let us describe the problem in hand. Problem Statement Have you ever faced an issue where you included a POJO(Plain Old Java Object) in your source code and tried to print it's state in the logs or may be on the console. But unlike your expectations you ended up with some ugly object references which gives no good representation of the data you require. This t...
Read More

Using Abstract Classes And Interfaces

Introduction This article is going to be a short one with some details about the interfaces and abstract classes in java. There have been a lot of confusion about using them interchangeably, but as I always say, encapsulation is a strong feature of java and one of the most important rule in java is that every thing has its own purpose. Hence, if two distinct features (abstract class and interface) exists in the language, then they must have different reasons as well. Purpose of the Article The article describes in detail using Abstract Classes And Interfaces, what is the difference between ...
Read More

Interview Question – Static variables

Introduction This question was asked in a recent java interview in Goldman Sachs, this isn't complicated but candidates might get confused solving it. This is about static blocks and static variables initialization, so I publish this article under the heading Interview Question - Static variables. To get updates on the other articles in the series, please use the Subscribe feature on the right panel. Problem Statement What would be the result when the below code is executed? [crayon-5925e1d19a4ba653164442/]   Solution What is the approach for solving this question? Remember your b...
Read More