It is all about java. Writings on java technology, programming concepts and knowledge articles especially for beginners
Monday, 9 February 2026
Number systems and Conversions
Decimal to Hexadecimal Converter
Hexadecimal value:
Hex to Decimal ConverterHex to Decimal Converter
Decimal Value:
Binary to Decimal ConverterBinary to Decimal Converter
Thursday, 11 December 2025
Tutorial on Java classes and objects
Java Classes and Objects:
Classes and objects both are treated in similar way in all programming languages. Java is not exception.
Understanding classes and objects with real world example
Consider a physical class room with lot of real world objects. What we Observe in class room..?
- Chairs
- Table
- Students
- Teacher
- Black board
- Markers and Erasers etc
So, a programmer needs to instruct the computer, how to create a class room object and it's subsequent objects. like, chair, table, teacher and student etc.
If programmer wants to create or develop a School application, he would need to create:
- class room object
- Office room object,
- Student object,
- Stationary object
- Play room object etc
Let us now create School application with above mentioned objects and classes using java programming language.
To create Objects, first of all, we have to create respective classes in java
public class School_Application{
public Student students;
public Teacher teachers;
public ClassRoom classRoom;
public School_Application(Student students, Teacher teachers, ClassRoom classRoom){
this.students = students;
this.teachers = teachers;
this.classRoom = classRoom;
}
}
Subsequently, programmer needs to create, Student, Teacher and ClassRoom classes and respective objects in main() method.
Objects in java are created using new operator. Example:
Happy coding! :)
Monday, 17 November 2025
Tutorial on coding and best practices
Write code or write code in right way...
Writing a coding solution to a problem can be done in many ways. If the solution can be obtained with less number of code lines, then it is easy to understand and maintain.
But what if code is large with having millions of lines. Moreover maintenance and readability becomes difficult as the code base grows... Right?
Aspects to consider while coding:
- Naming convention
- Cyclomatic Complexity
- SOLID principles
- DRY Principle
- Managing dead code
- Comments
Naming conventions:
Every programming language mandates few norms in order to name variables, classes and functions etc. For ex: Java uses class names first letter to be a upper case and rest to be lower case letters.
But if we dig little bit more, naming conventions are not limited to only upper case or lower case letters and using alphanumeric letters etc.
Naming a variable must be enough concise as naming your first child's name...
Few bad names for variables and constants:
int final static MAX_LENGHT = 2; [Correct]
Cyclomatic Complexity:
Cyclomatic complexity is a measure or metric to estimate complexity level of a snippet or block of code.
Cyclomatic complexity and best practices:
- Never put more than three conditional checks (&& operator and || operator etc.) in one if condition
- Never exceed more than thirty lines in one function or method.
- Never exceed more than 1000 lines in one class or one file.
SOLID principles:
Usually developing a large and scalable application, requires better design. Adhering to SOLID principles yields better scalable and easily maintainable applications.
There are five SOLID principles. They are:
- Single Responsibility Principle
- Open/Closed Principle
- Liskov's Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
DRY Principle:
DRY stands for Do Not Repeat Yourself. Sometimes, There could be a need to use same or similar set of lines of code to be used multiple times in the same application. For ex. String utilities, DB connections or updating records in database etc.
Writing frequently used code snippets multiple times is not a good practice. Instead move this code to a function or method and use this method in places where ever required.
Simple use cases are:
- DB Connections
- File IO Operations
- String Utilities etc.
Managing Dead Code:
Sometimes there are some lines or instructions in code base, which are completely not executed in all cases at all. This is considered as dead code.
Dead code reduces the quality with respect to the readability.
Comments:
Comments increases the readability of the program for programmers. Comments are written at class level, method level and variable level [Constants, instance variables and class variables] differently.The reason for this difference is, the pattern of comments is identified by API document generator tools and generates API documents.
Conclusion:
Tuesday, 21 October 2025
Tutorial and CHEAT SHEET for java List interface, LinkedList and ArrayList
Consider Below points before choosing List concrete implementations for your use case:
- ArrayList is a linear data structure and re-sizable/dynamic array
- Initial size can be given. and if not given the default size is 10
- It is always good practice to give initial size and advised not to give very large number as size
- Good programmers prefer ArrayList to LinkedList if retrieval operations is done more frequently than insertion and deletions of elements.
- Better choose LinkedList if insertion and deletion operations are done frequently compared to retrieval operations.
- Lists are not sorted. if required use Collections.sort() to sort
- Collections.sort() uses optimized merge sort [tim sort] on ArrayList
- However legacy merge sort also can be used using a switch. But it is going to be deprecated in near future
- The major difference between ArrayList and LinkedList is RandomAccess behavior
- ArrayLists uses Random access indexing where as LinkedLists uses
- LinkedList carries extra overhead in the form of reference to the next and previous elements other than element's data itself
- LinkedList uses Doubly LinkedList data structure internally
- Deque is the java DoubleLinkedList data structure implementation
- Before choosing List implementation ask yourself below questions
b. Which operations are used more frequently? [insertion, deletion,
retrieval, search, sort are few among others]
- Search Algorithm:
b. Collections class uses linear search if List is of type LinkedList
- ArrayList and LinkedList both uses fast fail iterations.
- If another thread tries to modify list while iterating, java runtime throws ConcurrentModificationException. This can be considered as fast fail behavior
Sunday, 28 September 2025
Tutorial on Atomicity with Java Programming Language
Atomicity with Java
What is Atomicity
Does Java language helps in developing Secured application..?
- Primitive data types
- User defined data types
Primitive data types:
Java supports 8 different primitive data types. They are:
- boolean 1 byte
- short 2 bytes
- int 4 bytes
- char 2 bytes
- float 4 bytes
- long 8 bytes
- double 8 bytes
- byte 1 byte
User Defined data types:
Saturday, 20 September 2025
Tutorial on file IO operations with java programming language
File Management in OS
| GUI that represents Windows File Manager |
File Management with Java
- Readers and Writers: Readers and writers does the IO operations, character by character
- InputStream and OutputStream: Where as InputStream and OutputStream does IO operations byte by byte
Below are simple Java programs that demonstrates different File IO operations.
Program for creating directory
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
public void makeDirectory(String path, String dirName) {
Path dirPath = Path.of(path, dirName);
File dir = new File(dirPath.toString());
boolean isCreated = dir.mkdir();
if (isCreated)
System.out.println("A new directory with the name " + dir.getPath() + " created!");
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.makeDirectory("e:\\", "students");
}
}
Program for creating file:
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
public void createFile(String dirPath, String dirName, String fileName) throws IOException {
Path filePath = Path.of(dirPath, dirName, fileName);
File file = new File(filePath.toString());
boolean isFileCreated = file.createNewFile();
if (isFileCreated)
System.out.println("A new file with the name " + file.getPath() + " created!");
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.createFile("e:\\", "students", "student_1");
}
}
Listing all files available in given folder
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
Path dir = Path.of(dirPath, dirName);
File file = new File(dir.toString());
String[] listOfAllFiles = file.list();
System.out.println("List of all Files in the directory/folder - " + dirName + ": ");
for (String fileName : listOfAllFiles) {
System.out.println(fileName);
}
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.listFiles("e:\\", "pinterest");
}
}
Delete a directory
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
Path dir = Path.of(dirPath, dirName);
File dirToBeDeleted = new File(dir.toString());
if (dirToBeDeleted.exists()) {
boolean isDeleted = dirToBeDeleted.delete();
if(isDeleted)
System.out.println("File deleted!");
else
System.out.println("Could not delete file. File is being used by other program or application.");
}
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.deleteDirectory("e:\\", "pinterest");
}
}
Read a file content
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
Path filePath = Path.of(dirPath, dirName, fileName);
File file = new File(filePath.toString());
FileReader reader = new FileReader(file.getAbsolutePath());
BufferedReader bufferedRead = new BufferedReader(reader);
String line = null;
while((line = bufferedRead.readLine()) != null) {
System.out.println(line);
}
bufferedRead.close();
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.readFile("e:\\", "pinterest", "demo.txt");
}
}
Write content into file
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
Path filePath = Path.of(dirPath, dirName, fileName);
File file = new File(filePath.toString());
FileWriter writer = new FileWriter(file);
BufferedWriter bufferedWriter = new BufferedWriter(writer);
bufferedWriter.write("allabtjava.com is a web site, has information about java technologies \n");
bufferedWriter.write("This article explains about, files and IO management with java programming language.");
bufferedWriter.close();
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
}
}
Tutorial on Swing Components
Swing library and it's categorization of components and controls Basically, Swing library provides around 50+ components. These all com...