Java Basics

Java Reserved and Contextual Keywords

Java has 51 reserved words and 16 contextual keywords that cannot be used as identifiers in the code. Programmers should not use these keywords for other purposes.

Convert an Object to Map in Java

Learn to convert a given Java object into a Map using different solutions including Jackson ObjectMapper, Gson and Java reflection.

Format Output with Java Printf

Learn to print formatted output in Java using the format() and printf() methods. Learn to format strings, date-time, floats with precision.

Java Text Blocks

In Java, a text block is a multi-line string literal. It means we do not need to get into the mess of explicit line terminators, string concatenations, and delimiters.

Java Naming Conventions

Java naming conventions are sort of guidelines that application programmers are expected to follow to produce consistent and readable code throughout the application. If teams do not follow these conventions, they may collectively write an application code that is hard to read and difficult to understand. Always try to give …

Java Flow Control Statements

In Java, control flow statements help in conditionally executing statements based on whether the evaluation result is true or false.

Java Version – Time-Based Release Versioning

Starting from Java 10, Oracle has adapted time based version-string scheme [JEP 322]. The new time-based model has replaced the feature-based, multi-year release model of the past. Unlike the old releases, the new time-based releases will not be delayed and features will be released every six months, with no constraints …

Java Comments

Inside a Java program, we can write a special text that will be ignored by the Java compiler — known as the comment. Comments allow us to exclude code from the compilation process (disable it) or clarify a piece of code to yourself or other developers. Learn everything about Java comments, …

Difference between JDK, JRE and JVM in Java

JDK, JRE and JVM is very common words when developers talk about java applications and their development environments. Let’s find out the differeneces between these words.

Java Modules Tutorial

JPMS (Java Platform Module System) is the major enhancement in Java 9. It is also known as Project Jigsaw. In this Java 9 modules tutorial, we will learn about modules (in general) and how your programming style will change in future when you will start writing modular code.

Generating Random Numbers in Java

Learn to use java.util.Random, Math.random(), SecureRandom and ThreadLocalRandom to generate random numbers based on your application requirements.

Java Classpath

Use given syntax examples for setting CLASSPATH for any java application runtime, in windows and linux environments.

Block Statements in Java

A block statement is a sequence of zero or more statements enclosed in braces. A block statement is generally used to group together several statements, so they can be used in a situation that requires you to use a single statement. 1. What is a Block Statement? Generally, a java …

Types of Statements in Java

A statement specifies an action in a Java program. For example, a statement may tell the add of values of x and y and assign their sum to the variable z. It then prints a message to the standard output or writes data to a file, etc. Java statements can …

Introduction to Java Programming Language

Java is concurrent, object-oriented, and intended to let application developers “write once, run anywhere” (WORA). Java is considered a fast language, almost as fast as languages like C and Rust, but it uses a lot of memory in comparison to these languages. 1. What is Java Programming Language Java is …

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 …

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 …

Java Base64 Encode and Decode Example

Java 8 introduced ‘java.util.Base64‘ utility class that provides built-in support for performing base64 encoding and decoding operations as specified in RFC 4648 and RFC 2045. Let us explore Base64 encode and decode processes with various usecases with examples. 1. What is Base64? Base64 is a binary-to-text encoding scheme that converts …

Java Exact Arithmetic Operations Support in Math Class

Java 8 has brought many awesome features for java developers. Some of them I have already described in Comparator changes, Streams examples, Internal vs. external iterations, predicates, functional interfaces, default methods, lambda expressions and date and time API changes. All above changes were related to lambda expressions, which is the …

Java String.join()

Since Java 8, we can use String.join() method to concatenate strings with a specified delimiter. For advanced usages, use StringJoiner class.

Internal vs. External Iteration in Java

Learn the difference between internal iteration and external iteration in Java with examples. 1. External Iteration Till Java 7, the collections framework relied on the concept of external iteration where the Collection provides a means to enumerate its elements by implementing the Iterator interface. The clients use the iterator to …

Usage of class sun.misc.Unsafe

This post is next update in sequence of discussions regarding little known features of java. Please subscribe through email to get updated when next discussion goes live. And do not forget to express your views in comments section. Java is a safe programming language and prevents programmer from doing a …

Spring 3: Timer Tasks

Timer is a utility class which is used to schedule tasks for both one time and repeated execution in spring applications. Timer is dependent on system clock

Comparing Performance of Java Loops

This Java article compares the performance of an ArrayList iteration using simple for-loop, enhanced for-loop, list iterator and stream API.

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.