Administrator

Lokesh Gupta

A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies. An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.

Website: https://howtodoinjava.com

Github: https://github.com/lokeshgupta1981/

Twitter: @HowToDoInJAVA

LinkedIn: https://www.linkedin.com/in/lokeshgupta1981/

My Articles:

Java Memory Model – Structure and Components

Whenever we execute a Java program, a separate memory area is reserved for storing various parts of our application code which we roughly call JVM memory. Though not necessary, having some knowledge about the structuring of this memory area is quite beneficial. Knowing Java memory model becomes more important when …

HiLo Guessing Game in Java

In HiLo game, we have to adjust our next guess such that we are able to guess the right number within six attempts. Learn with a Java program.

Guide to Java LineNumberReader

For reading a file line by line, the LineNumberReader class could be used that allows to keep track of which line we are currently processing.

Java FileFilter (with Examples)

Java FileFilter accepts File objects and thus can be used to filter the files based on other attributes such as read-only, directory etc.

Difference between DOM and SAX Parser

Both DOM and SAX parsers are extensively used to read and parse XML files in java applications and both of them have their own set of advantages and disadvantages.

Java – Read and Write PDF with iText

In this iText tutorial, we are writing various code examples to read a PDF file and write a PDF file. iText library helps in dynamically generating the .pdf files from Java applications. The given code examples are categorized into multiple sections based on the functionality they achieve. With each example, …

Localized Currency Formatting in Java

Most of the applications today, which are targeted at a larger audience e.g. internet users, usually deal in money as well. In such applications, a requirement will be to display money/currency in a format specific to that location or country. In this tutorial, I am giving some examples that will …

Getting Current Locale in Java

Learn to get the locale of the user in Java that is used to format the content according to the user’s demographics (geographical, political, or cultural information). 1. What is Locale? Suppose we are developing an application and we are asked to make the application customized for international end-users. To …

Running Multiple Tomcats with Single Server Installation

Many times we come to a situation where we need to modify the server configuration such that it is specific to an application. And if we got more than one such application and we want each application to have its own defined configuration options, then it needs some sort of …

Java MongoDB: Get/Save Image using GridFS APIs

In previous tutorials, We have learned about MongoDB basics and installing MongoDB in Windows, as well as we learned about Inserting documents in MongoDB and selecting documents from MongoDB. In this tutorial, I am giving few examples of code which will help you when you have to work with images …

Spring context:annotation-config vs context:component-scan

Learn the main differences between tags <context:annotation-config> and <context:component-scan> in Spring MVC applications so that when we use them in the future, we will know, what exactly we are doing. 1. The Differences between <context:annotation-config> vs <context:component-scan> The first big difference between both tags is that <context:annotation-config> is used to …

Best Way to Learn Java Programming

In this article, I am listing 5 simple steps to learn Java, and by following these steps, you can become a good Java programmer over time.

Java transient keyword example

The Java transient keyword is used on class attributes/variables to indicate that serialization process of such class should ignore such variables while creating a persistent byte stream for any instance of that class. A transient variable is a variable that can not be serialized. According to Java Language Specification [jls-8.3.1.3] …

Difference between 32-bit Vs. 64-bit Java

In computer architecture, 64-bit computing is the use of processors that have datapath widths, integer size, and memory addresses widths of 64 bits (eight octets/bytes). Also, 64-bit CPU and ALU architectures are those that are based on registers, address buses, or data buses of that size. From the software perspective, …

Java Generics Tutorial

Java Generics is a technical term denoting a set of language features related to the definition and use of generic types and methods.

[Solved] Jackson: No suitable constructor found for type

If you are working on Jackson library and trying to marshal/unmarshal Java objects to/from JSON documents, you may encounter JsonMappingException error. 1. JsonMappingException When we are parsing a JSON file into Java object or we are converting the Java object to JSON representation, we must have created a POJO class. …

Java Compare and Swap Example – CAS Algorithm

One of the best additions in java 5 was Atomic operations supported in classes such as AtomicInteger, AtomicLong etc. These classes help you in minimizing the need of complex (un-necessary) multi-threading code for some basic operations such as increment or decrement a value which is shared among multiple threads. These …

Java Reflection – Real Usage Examples

Reflection is one of those things like multi-threading where everyone with experience of it says “Don’t use it unless you absolutely have to”. Above quote is absolutely true for all for us alike. In my previous tutorial, I discussed basics of annotation in which I discussed the usage of reflection …

Complete Java Annotations Tutorial

An annotation is a kind of metadata in Java that can be applied to various elements of Java source code so that later some tool, debugger, or application program can take advantage of these annotations; and help analyze the program in a positive and constructive way. Just to mention, we …

Guide to Java 8 Optional

All of us must have encountered NullPointerException in our applications. It happens when you try to use an object that has not been initialized, initialized with null or does not point to any instance. In simple words, NULL simply means ‘absence of a value’. In this Java tutorial, we will …

Difference between HashMap vs Hashtable in Java

At entry level Java programmer, you can expect this interview question on Hashtable vs HashMap. Though the question becomes really easy when you know other concepts like how hashmap works, yet after getting a many queries from my blog readers who are preparing for or working at junior level, I …

Java ASCII to Hex Conversion (and vice-versa)

ASCII (American Standard Code for Information Interchange) is a character encoding standard that assigns numerical values to characters. Each character is represented by a unique numerical value ranging from 0 to 127. Similarly, Hexadecimal (or hex) is a base-16 numbering system that uses 16 distinct symbols: 0-9 and A-F (or …

Java Concurrency – Difference between yield() and join()

Multi-threading is very popular topic among interviewers from long time. Though I personally feel that very few of us get real chance to work on a complex multi-threaded application (I got only one chance in last 7 years), still it helps in having the concepts handy to boost your confidence …

MongoDB Insert Document into Collection

In MongoDB learning series, we have already covered the MongoDB basics, MongoDB installation in Windows, and how to query/select documents from a collection. In this tutorial, I am listing multiple ways you can utilize to insert or add document(s) into a collection in MongoDB. 1. Sample Document to Insert into …

Java Concurrency – Thread Safety?

Defining thread safety is surprisingly tricky. A quick Google search turns up numerous “definitions” like these: Thread-safe code is code that will work even if many Threads are executing it simultaneously. A piece of code is thread-safe if it only manipulates shared data structures in a manner that guarantees safe …

MongoDB find document examples

MongoDB find document examples. Learn number of ways to find a document or multiple documents based on same condition as we do in SQL using WHERE CLAUSE.

Java Fork/Join Framework Tutorial

Java fork-Join breaks the task at hand into subtasks until the subtasks are simple enough that they can be solved without further breakups.

Introduction to MongoDB: Why MongoDB?

Before jumping directly into basics of MongoDB, we should try to understand the need to No-SQL database itself. Why the traditional relational databases are loosing the battle with their new competitor like MongoDB. Why they are so popular now-a-days. Why? Why NoSQL? Interactive applications have changed dramatically over the last …

Throttling Task Submission Rate in Java

1. Introduction In BlockingQueue and ThreadPoolExecutor example, we learned creating a CustomThreadPoolExecutor which had the following capabilities: Tasks are being submitted to the blocking queue. An executor picks up the task from the queue and execute them. It had overridden beforeExecute() and afterExecute() methods to perform pre-and-post activities if needed. …

Adapter Pattern

The adapter design pattern is a structural design pattern used to allow two unrelated interfaces to work together. The object that joins these unrelated interfaces is called an Adapter. The definition of Adapter provided in the original Gang of Four book on Design Patterns states: “Convert the interface of a …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.