Java Programs – Java Programming Examples
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.
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.
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,” is a starting point for anyone new to Java Programming. You’ll find a collection of basic Java program examples with outputs, designed to help you learn the essential syntax, data structures, and control flow in Java.
- Read Number From Standard Input
- Get Input from the User
- Multiply Two Floating-Point Numbers
- Swap Two Numbers
- Add Two Binary Strings
- Add Two Complex Numbers
- Check Even or Odd Integers
- Find Largest Among 3 Numbers
- Find LCM of 2 numbers
- Find GCD or HCF of 2 numbers
- Display All Prime Numbers from 1 to N
- Check Leap Year
- Check Armstrong Number between Two Integers
- Check whether the input number is a Neon Number
- Check whether input character is vowel or consonant
- Find Factorial of a number
- Find Even Sum of Fibonacci Series Till number N
- Calculate Simple Interest
- Calculate Compound Interest
- 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.
- Right Triangle Star Pattern
- Left Triangle Star Pattern
- Pyramid Star Pattern
- Reverse Pyramid Star Pattern
- Upper Star Triangle Pattern
- Mirror Upper Star Triangle Pattern
- Downward Triangle Star Pattern
- Mirror Lower Star Triangle Pattern
- Star Pascal’s Triangle
- Diamond Star Pattern
- Square Star Pattern
- Pyramid Star Pattern
- 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.
- Binary to Octal
- Octal to Decimal
- Decimal to Octal
- Hexadecimal to Decimal
- Decimal to Hexadecimal
- Decimal to Binary
- Binary to Decimal
- Boolean to String
- String to Double
- Double to String
- String to Long
- Long to String
- Int to Char
- Char to Int
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.
- Class and Object
- Abstract Class
- Singleton Class
- Create an Interface
- Encapsulation in Class
- Inheritance in Class
- Abstraction in Class
- Data Hiding in Class
- Polymorphism in Class
- Overloading of Methods in Class
- Overriding of Methods in Classes
- Super Keyword in Class
- This Keyword in Class
- Static keyword in Class
- 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.
- Main() Method
- Static and Non-Static Methods
- forEach() Method
- toString() Method
- codePointAt() Method
- compare() Method
- equals() Method
- 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.
- Search an Element in an Array
- Find the Largest Element in an Array
- Sort an Array
- Sort the Elements of an Array in Descending Order
- Sort the Elements of an Array in Ascending Order
- Remove Duplicate Elements From an Array
- Merge Two Arrays
- Check if Two Arrays Are Equal or Not
- Remove All Occurrences of an Element in an Array
- Find Common Array Elements
- Copy All the Elements of One Array to Another Array
- 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.
- Print a 2D Array
- Add Two Matrices
- Sort the 2D Array Across Columns
- Check Whether Two Matrices Are Equal or Not
- Find the Transpose
- Find the Determinant
- Find the Normal and Trace
- Print Boundary Elements of a Matrix
- Rotate Matrix Elements
- Compute the Sum of Diagonals of a Matrix
- Interchange Elements of First and Last in a Matrix Across Rows
- 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.
- Get a Character From the Given String
- Replace a Character at a Specific Index
- Reverse a String
- Reverse a String Using Stacks
- Sort a String
- Swapping Pair of Characters
- Check Whether the Given String is Pangram
- Print first letter of each word using regex
- Determine the Unicode Code Point at a given index
- Remove leading zeros
- Compare two strings
- Compare two strings lexicographically
- Print even length words
- Insert a string into another string
- 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.
- Initializing a List
- Find a Sublist in a List
- Get Minimum and Maximum From a List
- Split a list into Two Halves
- Remove a Sublist from a List
- Remove Duplicates from an Array List
- Remove Null from a List container
- Sort Array List in an Ascending Order
- Get First and Last Elements from an Array List
- Convert a List of String to Comma Separated String
- Add Element at First and Last Position of a Linked list
- Find Common Elements in Two ArrayList
- 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.
- Format time in AM-PM format
- Display Dates of Calendar Year in Different Format
- Display current date and time
- Display time in different country’s format
- Convert the local Time to GMT
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.
- Create a New File
- Create a Temporary File
- Write into a File
- Rename a file in Java
- Make a File Read-Only
- Compare Paths of Two files
- Copy one File into Another File
- Print all the Pattern that Matches Given Pattern From a File
- Append a String in an Existing File
- Read Content From One File and Writing it into Another File
- 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.
- Traverse in a Directory
- Get the Size of a Directory
- Delete a Directory
- Create Directories Recursively
- Search for a File in a Directory
- Find the Current Working Directory
- 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.
- Show Runtime Exceptions
- Show Types of Errors
- Exception Hierarchies
- Exception Methods
- Checked exceptions
- Unchecked Exceptions
- Divide By Zero and Multiple Exceptions
- Unreachable Code Error
- 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.
- Use Different Types of Collection
- Print a Collection
- Compare Elements in a Collection
- Get the Size of the Collection
- Compare Elements in a Collection
- Shuffle the Elements of a Collection
- Reverse a Collection
- Convert Collection into Array
- Convert Array into Collection
- Replace Elements in a List
- Rotate Elements of a List
- 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.
- Print Fibonacci Series in Different Ways
- Convert Linked List to an Array
- Convert Vector to a List
- Convert String to a List of Characters
- Convert Iterator to a List
- Convert List to a Map
- Convert List to a Stream
- Convert List to Set
- Convert InputStream to String
- Convert Set of String to Array of String
- Convert String to Object
- 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.
Click Here to Check out Java Exercise to Practice Java Problems Online.