Tag Archives: Java

Java Enum Example

Introduction Java Enums are used to define constants. Rather than declaring common categories of constants as individual strings, we can categorize and declare them as Enums. In this article, we will discuss how to declare Enums, use Java Enum in a for loop and Java switch case, and how Java Enums can be used in if/else statements. Some… Read More »

Java JDBC Insert Example

Introduction Web applications collect data from the user through the User Interface (UI) and insert the information into the database. This process happens automatically without us running any database scripts or monitoring data. This magic is done by JDBC (Java DataBase Connectivity), which is a Java API to connect Java code to any database. What is JDBC (Prepared)Statement… Read More »

Java String to Int

Introduction In Java, a lot of data is stored as objects rather than primitives. A string is an object, whereas int is a primitive data type. The advantage of objects is the ease of manipulation and storage. If we need any calculations to be performed, it is easy to convert String to int using various methods. Java also… Read More »

Java Queue

Introduction In Java, Queues are used for pushing in data and retrieving it later. Queue follows the principle of FIFO i.e. First In First Out. In this article, we will discuss the most important methods of Java Queues and give a good amount of Java Queue examples to further the learning process. How to use Java Queue: Examples… Read More »

Java Scanner

Introduction Java Scanner class is used to obtain input from the user. It is the best way for the program to read interactive command-line input. Java Scanner inputs the data from the user and processes it accordingly. The class is available from Java version 5 onwards. Java user input and scanner class In Java, user input can be… Read More »

How to format Java String output?

Introduction Strings are an extremely important part of the Java language. Most of the data that we receive is stored in the form of Strings because they are easy to manipulate, read, and store. Java API also provides methods for parsing and converting Java string into different other data types. There are also many methods and format specifiers… Read More »

Java Do While Loop

This loop will work when the number of iterations is not known and the code has to run at least once. This loop will execute the program a number of times until the condition is false. The do-while loop will get executed at least once because the condition is checked after the first iteration at the end of… Read More »

Java While Loop

Unlike for-loop, while loop is used when the number of iteration is not known. The while loop will execute the program several times until the condition is false. Syntax while(condition){ //code to be executed } Example public class WhileExample { public static void main(String[] args) { int i=1; while(i<=3){ System.out.println(i); i++; } } } Output 1 2 3… Read More »

Java Switch

Java switch statement will allow you to check for a number of condition to execute the statements. It works like an if-else-if statement. The switch statement will allow you to use byte, short, int, long, enum types, String and some wrapper types like Byte, Short, Int, and Long. with the latest version of Java, you can also use… Read More »