Home » Core Java

Core Java

Java 11 Standardized HTTP Client API Example

In this article, we will test a REST API application using the Java HTTP Client API. 1. Introduction There are many tools available to test your REST API applications.  There are command line tools, such as cURL, and there are GUI tools, such as Postman and SoapUI that can perform these tasks.  If you are using a Continuous Integration and ...

Read More »

Java Convert Byte[] array to String Example

1. Introduction A byte array is an array of bytes. A byte is binary data with 8 bits which represents an integer with values from -128 to 127. A char is a primitive data type which represents a character. The bytes translate to characters based on the character encoding scheme (such as Unicode, UTF-8, UTF-16, and UTF-32). The String class ...

Read More »

How to Create and Run Your First Java Program

1. Introduction This is an in-depth article on how to create and run your first java program. Java compiler is used to compile java code. Java class is the output of the compilation. To execute the program you need java runtime virtual machine. 2. Run Your First Java Program 2.1 Prerequisites Java 7 or 8 is required on the linux, ...

Read More »

Java HashMap vs TreeMap Example

1. Introduction A very important data structure in programming is the Map which is used for extremely fast lookups. In this post, we will take a look at two implementations of the Map data structure in Java, the HashMap and TreeMap classes. The main difference between those two implementations is that the HashMap offers better lookup and insertion times but ...

Read More »

Java Generate Random Integers Example

1. Introduction Java JDK has provided the following utility classes to generate random integers over time: The java.util.Random class from version 1.0, java.util.concurrent.ThreadLocalRandom class from version 1.7, and java.util.SplittableRandom class from version 1.8. These classes provide the nextInt method to generate a random integer and ints method to generate a stream of random integers. Here are the syntax details: /** ...

Read More »

Java 8 Optional In Depth Example

1. Introduction This is an in-depth article about Java 8 Optional. A new class Optional was introduced in Java 8. The optional class is part of java.util package. Optional is used to represent a value. It can be present or absent. No more null checks and NullPointerException are needed. Optional helps in avoiding any runtime NullPointerExceptions. It helps in developing clean ...

Read More »

Java ArrayList vs LinkedList Example

1. Introduction One of the most commonly used data structures in programming is the Array. Java comes with two implementations of the Array data structure, the ArrayList and LinkedList classes. In a nutshell, the ArrayList is a resizable-array implementation, whereas the LinkedList is a doubly-linked list implementation. In this post, we will cover the differences between the methods and time ...

Read More »

Java Copy Array Example

1. Introduction Java array is an object which represents a data structure that contains elements of a similar data type. Array in java is index-based, the first element of the array is stored at the 0 index. Java has provided several ways to copy an array over time: System.arraycopy – provided since version 1.0. It copies an array from a ...

Read More »

Java Pass by Value vs Pass by Reference Example

1. Introduction There are two ways to pass arguments (parameters) into methods (functions) in most programming languages: Pass by Reference – A reference to the actual parameter is passed to the method. If the method modifies the parameter variable, the changes are visible to the caller.Pass by Value – The method parameter values are copied to another variable and then ...

Read More »

Java public static void main(String[] args) Example

1. Introduction In every programming language, when a program starts the execution it has to start from somewhere. For Java, the entry point for a program is the main method. In this post, we will examine this very important method and learn how to use it to start simple programs. The technologies that we will use in the code examples ...

Read More »