Java Programs – Java Programming Examples
Java is one of the most popular programming languages today because of its simplicity. Java programming concepts such as control statements, Arrays, Strings, Object-Oriented Programming (OOP), etc. are very important from an interview perspective as well as from exams.
So, whether you are a fresher preparing for job interviews or a beginner who has covered Java Fundamentals and wants to practice Java concepts then, this Java Programming Examples page covers a wide range of Java programs in an organized manner.
In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.
So, keep scrolling or bookmark this page to learn about Java (Basic to Advanced) using Java Programming Examples.
Table of Content
- Java Basic Programs
- Java Pattern Programs
- Java Conversion Programs
- Java Classes and Object Programs
- Java Methods Programs
- Java Searching Programs
- Java 1-D Array Programs
- Java 2-D Arrays (Matrix) Programs
- Java String Programs
- Java List Programs
- Java Date and Time Programs
- Java File Programs
- Java Directory Programs
- Java Exceptions and Errors Programs
- Java Collections Programs
- Java Multithreading Programs
- Java More Java Programs
Java Basic Programs
This section, “Java Basic Programs,” provides a launchpad if you are new to Java programming. Here, you’ll encounter a collection of fundamental Java programs, that is crafted to introduce you to the core syntax, data structures, and control flow mechanisms of Java development.
- Java Program to Read The Number From Standard Input
- Java Program to Get Input from the User
- Java Program to Multiply Two Floating-Point Numbers
- Java Program to Swap Two Numbers
- Java Program to Add Two Binary Strings
- Java Program to Add Two Complex Numbers
- Java Program to Check Even or Odd Integers
- Java Program to Find Largest Among 3 Numbers
- Java Program to Find LCM of 2 numbers
- Java Program to Find GCD or HCF of 2 numbers
- Java Program to Display All Prime Numbers from 1 to N
- Java Program to Check Leap Year
- Java Program to Check Armstrong Number between Two Integers
- Java Program to Check whether the input number is a Neon Number
- Java Program to Check whether input character is vowel or consonant
- Java Program to Find Factorial of a number
- Java Program to Find Even Sum of Fibonacci Series Till number N
- Java Program to Calculate Simple Interest
- Java Program to Calculate Compound Interest
- Java Program to Find the Perimeter of a Rectangle
Java Pattern Programs
In this section, you will get a list of Java programming language that deals with patterns. By meticulously arranging stars, numbers, or characters, you’ll not only solidify your grasp of Java loops and control structures but also discover the aesthetic side of programming.
- Java Program to Print Right Triangle Star Pattern
- Java Program to Print Left Triangle Star Pattern
- Java Program to Print Pyramid Star Pattern
- Java Program to Print Reverse Pyramid Star Pattern
- Java Program to Print Upper Star Triangle Pattern
- Java Program to Print Mirror Upper Star Triangle Pattern
- Java Program to Print Downward Triangle Star Pattern
- Java Program to Print Mirror Lower Star Triangle Pattern
- Java Program to Print Star Pascal’s Triangle
- Java Program to Print Diamond Star Pattern
- Java Program to Print Square Star Pattern
- Java Program to Print Pyramid Star Pattern
- Java Program to Print Spiral Pattern of Numbers
Java Conversion Programs
Java Conversion Programs put your coding skills to the test. Here, you’ll encounter a series of exercises designed to strengthen your ability to transform data, like converting Binary to Decimal and more.
- Java Program For Binary to Octal Conversion
- Java Program For Octal to Decimal Conversion
- Java Program For Decimal to Octal Conversion
- Java Program For Hexadecimal to Decimal Conversion
- Java Program For Decimal to Hexadecimal Conversion
- Java Program For Decimal to Binary Conversion
- Java Program For Binary to Decimal Conversion
- Java Program For Boolean to String Conversion
- Java Program For String to Double Conversion
- Java Program For Double to String Conversion
- Java Program For String to Long Conversion
- Java Program For Long to String Conversion
- Java Program For Int to Char Conversion
- Java Program For Char to Int Conversion
Java Classes and Object Programs
Here in this section, you will dive into the world of classes, acting as blueprints for objects, and objects themselves, the real-life entities.
- Java Program to Create a Class and Object
- Java Program to Create Abstract Class
- Java Program to Create Singleton Class
- Java Program to Create an Interface
- Java Program to Show Encapsulation in Class
- Java Program to Show Inheritance in Class
- Java Program to Show Abstraction in Class
- Java Program to Show Data Hiding in Class
- Java Program to Show Polymorphism in Class
- Java Program to Show Overloading of Methods in Class
- Java Program to Show Overriding of Methods in Classes
- Java Program to Show Use of Super Keyword in Class
- Java Program to Show Use of This Keyword in Class
- Java Program to Show Usage of Static keyword in Class
- Java Program to Show Usage of Access Modifier
Java Methods Programs
This section unlocks the secrets of methods, the building blocks of reusability in object-oriented programming. Here, you’ll embark on a hands-on journey, crafting and wielding methods like a programming pro.
- Java Program to Show Usage of Main() method
- Java Program to Show Use of Static and Non-static Methods
- Java Program to Show Usage of forEach() Method
- Java Program to Show Usage of toString() Method
- Java Program to Show Usage of codePointAt() Method
- Java Program to Show Usage of compare() Method
- Java Program to Show Usage of equals() Method
- Java Program to Show Usage of hasNext() and next() Method
- Thread Lifecycle Methods
Java Searching Programs
Looking for the Java Search related programs, hence here in this section we have listed down multiple searching Java programming examples.
Java 1-D Array Programs
This section is all about organizing things in your Java code. Here, you’ll learn how to create these “cabinets,” put things in them, and take them out whenever you need them.
- Java Program to Search an Element in an Array
- Java Program to Find the Largest Element in an Array
- Java Program to Sort an Array
- Java Program to Sort the Elements of an Array in Descending Order
- Java Program to Sort the Elements of an Array in Ascending Order
- Java Program to Remove Duplicate Elements From an Array
- Java Program to Merge Two Arrays
- Java Program to Check if Two Arrays Are Equal or Not
- Java Program to Remove All Occurrences of an Element in an Array
- Java Program to Find Common Array Elements
- Java Program to Copy All the Elements of One Array to Another Array
- Java Program For Array Rotation
Java 2-D Arrays (Matrix) Programs
This section dives into two-dimensional arrays, which are like spreadsheets for your code. Imagine organizing data in rows and columns, perfect for things like tables or images.
- Java Program to Print a 2D Array
- Java Program to Add Two Matrices
- Java Program to Sort the 2D Array Across Columns
- Java Program to Check Whether Two Matrices Are Equal or Not
- Java Program to Find the Transpose
- Java Program to Find the Determinant
- Java Program to Find the Normal and Trace
- Java Program to Print Boundary Elements of a Matrix
- Java Program to Rotate Matrix Elements
- Java Program to Compute the Sum of Diagonals of a Matrix
- Java Program to Interchange Elements of First and Last in a Matrix Across Rows
- Java Program to Interchange Elements of First and Last in a Matrix Across Columns
Java String Programs
In this section, you will dive deep into working with text in Java. You’ll learn to manipulate, analyze, and modify strings, the fundamental building blocks of text data, with the help of multiple Java String programs.
- Java Program to Get a Character From the Given String
- Java Program to Replace a Character at a Specific Index
- Java Program to Reverse a String
- Java Program to Reverse a String Using Stacks
- Java Program to Sort a String
- Java Program to Swapping Pair of Characters
- Java Program to Check Whether the Given String is Pangram
- Java Program to Print first letter of each word using regex
- Java Program to Determine the Unicode Code Point at a given index
- Java Program to Remove leading zeros
- Java Program to Compare two strings
- Java Program to Compare two strings lexicographically
- Java Program to Print even length words
- Java Program to Insert a string into another string
- Java Program to Splitting into a number of sub-strings
Java List Programs
Dive into the world of Java Lists, a fundamental data structure in Java. Here, you’ll learn how to store, access, and manipulate elements in a specific sequence.
- Java Program to Initializing a List
- Java Program to Find a Sublist in a List
- Java Program to Get Minimum and Maximum From a List
- Java Program to Split a list into Two Halves
- Java Program to Remove a Sublist from a List
- Java Program to Remove Duplicates from an Array List
- Java Program to Remove Null from a List container
- Java Program to Sort Array List in an Ascending Order
- Java Program to Get First and Last Elements from an Array List
- Java Program to Convert a List of String to Comma Separated String
- Java Program to Add Element at First and Last Position of a Linked list
- Java Program to Find Common Elements in Two ArrayList
- Java Program to Remove Repeated Element From An ArrayList
Java Date and Time Programs
This section gives you to handle the ever-changing world of dates and times within your Java programs. Explore the working with calendars, timestamps, and time manipulation – essential skills for building applications that deal with deadlines, scheduling, or even historical data analysis.
Java File Programs
Java File Programs empowers you to interact with files in Java. This section dives deep into reading, writing, and manipulating data stored outside your program.
- Java Program to Create a new file
- Java Program to Create a temporary file
- Java Program to Write into a file
- Java Program to Rename a file in java
- Java Program to Make a File Read-Only
- Java Program to Compare Paths of Two files
- Java Program to Copy one file into another file
- Java Program to Print all the Pattern that Matches Given Pattern From a File
- Java Program to Append a String in an Existing File
- Java Program to Read content from one file and writing it into another file
- Java Program to Read and printing all files from a zip file
Java Directory Programs
This section navigate you to the world of directories and files in Java. Through this Java programming examples “Java Directory” section you’ll master creating, manipulating, and interacting with directories.
- Java Program to Traverse in a directory
- Java Program to Get the size of a directory
- Java Program to Delete a Directory
- Java Program to Create directories recursively
- Java Program to Search for a file in a directory
- Java Program to Find the current working directory
- Java Program to Display all the directories in a directory
Java Exceptions and Errors Programs
Through a series of hands-on exercises on Java Exceptions and Errors Handling programs, you will easily get to know how to become a good Java programmer.
- Java Program to Show Runtime Exceptions
- Java Program to Show Types of Errors
- Java Program to Handle the Exception Hierarchies
- Java Program to Handle the Exception Methods
- Java program to Handle the Checked exceptions
- Java Program to Handle the Unchecked Exceptions
- Java Program to Handle Divide By Zero and Multiple Exceptions
- Java Program to Show Unreachable Code Error
- Java Program to Show Thread interface and memory consistency errors
Java Collections Programs
Java Collections is not just about storing your data in Java; So practicing Java Collections programs will help you boost your organization skills. Get deep down into lists, sets, maps, and more, and discover how to structure your data effectively to build robust and efficient Java applications.
- Java Program to Use Different Types of Collection
- Java Program to Print a Collection
- Java Program to Compare Elements in a Collection
- Java Program to Get the Size of the Collection
- Java Program to Compare Elements in a Collection
- Java Program to Shuffle the Elements of a Collection
- Java Program to Reverse a Collection
- Java Program to Convert Collection into Array
- Java Program to Convert Array into Collection
- Java Program to Replace Elements in a List
- Java Program to Rotate Elements of a List
- Java Program to Iterate through Elements of HashMap
Java Multithreading Programs
In this section you will get hand on Java Multithreading programs. It will help you to conquer the art of threading, a technique that lets your program handle multiple tasks seemingly at once.
Java More Java Programs
This section extends your coding experience with a diverse array of programs that explore more intricate functionalities. Brace yourself to tackle problems that involve algorithms, data manipulation, and object-oriented programming concepts.
- Java Program to Print Fibonacci Series in Different Ways
- Java Program to Convert Linked List to an Array
- Java Program to Convert Vector to a List
- Java Program to Convert String to a List of Characters
- Java Program to Convert Iterator to a List
- Java Program to Convert List to a Map
- Java Program to Convert List to a Stream
- Java Program to Convert List to Set
- Java Program to Convert InputStream to String
- Java Program to Convert Set of String to Array of String
- Java Program to Convert String to Object
- Java Program to Convert string value to byte value
Conclusion
In this article, we dealt with a variety of Java programming questions categorized as basic programs, control statements, Arrays, Strings, OOPs, and much more that are frequently asked in interviews and exams.
Each Java program will give you a different approach to solving a particular problem in Java. If you are new to Java programming, we highly recommend you to go through our article on Java tutorial, where we’ve covered all the basics and advanced topics of Java programming with practical examples and programs.
Contact Us