Java Exercises

Sharpen your Java programming skills through a collection of hands-on exercises. This section provides a series of practical challenges designed to test and improve your understanding of Java concepts. Each exercise presents a real-world problem, allowing you to apply theoretical knowledge to build functional solutions. Progress from basic syntax challenges to more complex algorithmic problems, solidifying your abilities as a Java developer.

Introduction to Java Programming

Introduction to Java Programming

Discover the fundamentals of Java programming in this beginner-friendly lab. Learn about high-level programming languages, Java's advantages, and create your first Java program from scratch to execution.
LabJava
Variables and Operators in Java

Variables and Operators in Java

Learn Java variables, data types, and operators in this hands-on lab. Learn to declare variables, work with primitive data types, and apply arithmetic, bitwise, and logical operators in Java programming.
LabJava
Java Conditional Expressions Fundamentals

Java Conditional Expressions Fundamentals

In this lab, we learned basic data types of Java and operators. In this lab, we'll begin to learn to write procedure-oriented programs. The main idea is to use paradigm of controlling structures: conditional expressions.
LabJava
Recursion and Loops

Recursion and Loops

Computers are often used to automate repetitive tasks. Repeating tasks without making errors is something that computers do well and people do poorly. Like conditional expressions, loops can also be nested one in another, but this will make our program hard to read and the performance will not be good. Try to avoid nested loops. There are three types of loops in Java. We'll learn them one by one in this lab.
LabJava
Methods & Parameters and Object

Methods & Parameters and Object

In this lab, we move forward to methods and objects. The task is to learn how to define a method with parameters. Object is a very important concept in OOP language, so having a good knowledge of it will be good for you.
LabJava
Spy in Mockito

Spy in Mockito

Mockito is a Java framework used for mocking and unit testing Java applications. In this lab, we will learn about spies in Mockito. A Spy is like a partial mock, which will track the interactions with the object like a mock. Additionally, it allows us to call all the normal methods of the object. We will use the Mockito.spy() method and annotations to create spies and demonstrate how to stub a Spy.
LabJava
Reading a CSV File

Reading a CSV File

In this lab, we will learn how to read a CSV file in Java. CSV files are often used to store data in a simple and easily readable format. We will cover three different approaches to reading CSV files in Java: using BufferedReader, Scanner, and the OpenCSV library.
LabJava
Java Long Compare Method

Java Long Compare Method

The Long class in Java provides a compare() method that helps in comparing two long values for numerical difference. In this lab, we will explore the syntax, parameters, and return types of this method, and write down the implementation of several examples for better understanding.
LabJava
Convert Character to Lowercase in Java

Convert Character to Lowercase in Java

In Java programming, the toLowerCase(char ch) method is used to convert the given character argument to lowercase. This method uses case mapping information provided by the Unicode Data file. In this lab, you will learn how to use this method in Java programs.
LabJava
Determining Space Characters in Java

Determining Space Characters in Java

The isspacechar() method of the Character class in Java is used to determine whether the given character is a space character or not. It checks if the character belongs to the U+0020 'SPACE', U+0085 'NEXT LINE', U+000D 'CARRIAGE RETURN', U+000A 'LINE FEED', U+0009 'CHARACTER TABULATION' or U+000B 'LINE TABULATION' space character groups.
LabJava
How to Find Maximum Value Map

How to Find Maximum Value Map

In Java, the Map data structure is used to store key-value pairs. It is challenging to find the maximum value in a map since it does not store the data in a sequence. In this lab, you will learn how to find the maximum value in a Java Map using the iterative approach and the Collections class.
LabJava
How to Convert Enum to String

How to Convert Enum to String

The enum data type in Java is useful for defining constants such as the days of the week or months of the year. However, sometimes we need to convert these constants to strings. Knowing how to do this is essential for working with APIs and databases.
LabJava
Resolving 'Could Not Find or Load Main Class' Error in Java

Resolving 'Could Not Find or Load Main Class' Error in Java

Errors and exceptions are common in programming, including Java. One of the common errors developers encounter is the 'Could Not Find or Load Main Class'. This error simply means that the Java Virtual Machine (JVM) cannot find or load the specified main class. In this lab, we will look at the reasons behind this error and provide solutions for resolving this error in Java.
LabJava
Convert Integer List to Int Array

Convert Integer List to Int Array

This lab will guide you in converting an Integer List to an Int Array in Java. There are two ways of doing this - using the stream.mapToInt() method or using the ArrayUtils.toPrimitive() method.
LabJava
Comparator and Comparable

Comparator and Comparable

Comparing objects and sorting them is a common requirement in many applications. Java provides two interfaces, Comparator and Comparable, that are used to allow classes to define their own natural order based on some criteria.
LabJava