Java Jottings


Java Jottings is a collection of small Java notes that I have written to learn new concepts and techniques.

JUnit

JUnit is a unit testing framework for the Java programming language that has been instrumental in the evolution of test-driven development (TDD). In this guide, we will cover the basics of writing JUnit tests and understanding its various parts.


What is Unit Testing?

Through unit testing, we can define the intended behavior of the code and validate that it indeed performs as expected. Unit testing has evolved to become a fascinating junction of design, programming, and debugging.


Methods

Methods in Java are blocks of code that perform a specific task. They are used to achieve encapsulation, modularity, and reusability of code.


Data Members

In Java, a data member is a variable that is associated with a class or an object. It can be a primitive data type, an object, or an array.


Constructors

A constructor is a special method that is used to create and initialize objects in Java. Constructors have the same name as the class and do not have a return type. In this note, we will discuss the different types of constructors in Java.


Iterator

The Iterator interface in Java provides a way to traverse through a collection of objects one by one. It is part of the java.util package and is commonly used in conjunction with the Collection framework. The Iterator interface defines three methods:


Collections

The class collections consists exclusively of static methods that operate on or return collections. It contains polymorphic algorithms that operate on collections, "wrappers", which return a new collection backed by a specified collection, and a few other odds and ends.


Arrays

The Arrays class contains various methods for manipulating arrays (such as sorting and searching). This class also contains a static factory that allows arrays to be viewed as lists.


Using File APIs

The Java Files API provides a set of classes and methods that allow Java programs to interact with the file system. It allows you to perform common file operations such as reading, writing, and deleting files.


main Method

The main() method is a special method in Java that serves as the entry point of a Java application. When you run a Java program, the JVM (Java Virtual Machine) calls the main() method to start the execution of the program.


Packages

java package is a group of similar types of classes, interfaces and sub-packages.


Java Basic Syntax

Java programs are organized into Classes, which are defined using the class keyword. For example, the following code defines a class named MyClass:


Java Data Types and Variables

Java is a strongly-typed language, which means that all variables must have a declared data type. Variables are used to store values in memory. In Java, you declare a variable by specifying its data type and name.


Stacks

A stack is a linear data structure that follows the Last-In-First-Out (LIFO) principle. In other words, the last element added to the stack will be the first one to be removed.


Queues

Queues are a data structure that work on the principle of "First-In-First-Out" (FIFO), meaning that the first element added to the queue will be the first one to be removed. New elements are added at one end of the queue, called the "rear", and elements are removed from the other end of the queue, called the "front".


Maps in Java

A Map is a collection that stores key-value pairs, where each key is unique.


LinkedList

A linked list is a data structure that consists of a collection of nodes, where each node contains a value and a reference to the next node in the list.