baeldung

The Java Headless Mode

1. Overview On occasion, we need to work with graphics-based applications in Java without an actual display, keyboard, or mouse, let's say, on a server or a container. In this short tutorial, we're going to learn about Java's headless mode to address this scenario. We'll also look at what we can do in headless mode and what we can't. 2. Setting up Headless Mode There are many ways we can set up headless mode in Java...

javabeginnerstutorial.com javabeginnerstutorial.com

Java 14: instanceOf Pattern Matching

JDK prepares to use pattern matching in future versions. In JDK 12 pattern matching has been implemented in switch expression. And the same is being implemented to instanceOf in JDK 14 as a preview feature. In java program, instanceof include logic that combines testing if an expression has a certain type, and then conditionally extracting components of its state for further processing. if(obj instanceof Person){ ...

javabeginnerstutorial.com javabeginnerstutorial.com

Switch case statement in Java

A switch statement is a conditional statement that tests against multiple cases and displays one or multiple outputs based on the matching circumstances. Unlike if-then and if-then-else statements, the switch statement can work with byte, short, char, and int primitive data types. It also works with enum types (discussed in Java Enum), the String class, and a few wrapper classes: Character, Byte, Short,...

javabeginnerstutorial.com javabeginnerstutorial.com

Java 12 new features

Most Common Features of  Java 12 Switch expressions (JEP 325) Java 12 has enhanced Switch expressions for Pattern matching. It extends the switch statement so that it can be used as either a statement or an expression. These Forms can be used either as a “traditional” or “simplified” scoping control flow behavior. Thus the benefits are, these changes are used for simplification of everyday coding, for preparing the way, use...

javabeginnerstutorial.com javabeginnerstutorial.com

Data types in Java

Java is a statically-typed language, which means that all variables must first be declared before they can be used. It means the variable’s name and types must be defined before it can be used in code. boolean bool = true; By writing the above line we are telling the program that a variable named bool of type boolean is created, which has the default value as true. Java has 8 types of primitive data types. Different Primitive...