Category Archives: Java

Object Initialization Order in Java

An object is a chunk of memory bundled with the code that manipulates memory. In the memory, the object maintains its state (the values of its instance variables), which can change and evolve throughout its lifetime. To get a newly-created object off to a good start, its newly-allocated memory must be initialized to a proper initial state.Here we take an in-depth look at the mechanisms Java uses to manage object initialization. Java's Initialization Mechanisms At the beginning of an object's life, the Java virtual machine (JVM) allocates enough memory on the heap to accommodate the object's instance variables. When that memory is first allocated, however, the data it contains is unpredictable. If the memory were used as is, the behavior…

Continue Reading

HashMap Internal Implementation Analysis in Java

Most of you will agree that HashMap is most favorite topic for discussion in interviews now-a-days. Now, I am continuing this discussion with you all. I am assuming that if you are interested in internal working of HashMap, you already know basics of HashMap, so I'm skipping that part. But if you are new to concept, follow official java docs. Single Statement Answer If anybody asks me to describe "How HashMap works?", I simply answer: "On principle of Hashing". As simple as it is. Now before answering it, one must be very sure to know at least basics of Hashing. Right? What is Hashing Hashing in its simplest form, is a way to assigning a unique code for any variable/object after…

Continue Reading

Integrate Spring MVC with Log4j

It’s quite straightforward to integrate Log4j into the Spring MVC application. First, include Log4j.jar library into your project dependency, then create a log4.properties file to define the Log4j’s appender and put this file into the project class path, Done. In tutorial, we show you how to integrate the Log4j 1.x logging framework into the Spring MVC application. Add Log4j Library to Your Project Download the Log4j library from the official website, or via Maven : Create log4j.properties Create a Log4j properties file (log4j.properties), put it into the project class path. see figure : File : log4j.properties – Define how log4j handling the logged message, in this example, it will redirect all the logged messages into a text. Use Log4j in…

Continue Reading

Unit Testing of Spring MVC Controllers

After all the services, DAO’s and support classes are tested then it’s time for the controller. Generally this is hard to test and most developers (based on observation) would rather just test it via Selenium or worse, by hand. That can work but it makes testing logic branches difficult and not to mention it’s time consuming. Plus no active developer would be willing to wait for browser tests to run before checking in code. Luckily the Spring MVC Test project can do full controller testing via unit tests, it was such a success that it’s now in Spring MVC core as of version 4.0.5. Getting Ready We can get the required testing dependencies by adding the following dependency declarations to…

Continue Reading

Spring 4 MVC Hello World Tutorial Using Maven

In this tutorial you will learn how to develop a Spring 4 MVC Hello world example. We hope this tutorial will give you a quick start with Spring MVC development using the latest Spring 4 Release. Technologies used: Spring 4.0.4.RELEASE JDK 1.8 Tomcat 7.0.53 Maven 3.2.1 Eclipse Java EE IDE ( Eclipse Kepler) Maven Project Setup In Eclipse Let us start with the creation of  a Maven web project in Eclipse. A maven web project archetype will create all the necessary folder structures required for a web project. We assume that you have installed the maven plugins for Eclipse. File -> New -> Other -> Maven -> Maven Project Click Next and Click Next again ( If you wish to…

Continue Reading

How To Convert Byte[] Array To String In Java

In some cases, we have to convert String variable into a Byte array format, for example, JCE encryption. However how do we convert a Byte[] array to String afterward? Simple toString() function like following code is not working property. It will not display the original text but byte value. In order to convert Byte array into String format correctly, we have to explicitly create a String object and assign the Byte array to it. And here's a sample code: Output

Continue Reading
Contact Us
  • Room 614, Zonghe Building, Harbin Institute of Technology
  • cshzxie [at] gmail.com