Java Programs – Java Programming Examples
Last Updated :
15 Nov, 2024
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.

Hands-on practice is essential to mastering Java. If you’re looking for structured exercises and programming challenges, the Java Programming Course provides numerous examples and projects to help solidify your knowledge
So, keep scrolling or bookmark this page to learn about Java (Basic to Advanced) using Java Programming Examples.
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.
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 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 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 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 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 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 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 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 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 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 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 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 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.
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.
Similar Reads
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 it
9 min read
Java Basic Programs
How to Read and Print an Integer value in Java
The given task is to take an integer as input from the user and print that integer in Java language. In the below program, the syntax and procedures to take the integer as input from the user are shown in Java language. Steps for InputThe user enters an integer value when asked.This value is taken f
2 min read
Ways to read input from console in Java
In Java, there are four different ways to read input from the user in the command line environment(console). 1. Using Buffered Reader ClassThis is the Java classical method to take input, Introduced in JDK 1.0. This method is used by wrapping the System.in (standard input stream) in an InputStreamRe
5 min read
Java Program to Multiply two Floating-Point Numbers
The float class is a wrapper class for the primitive type float which contains several methods to effectively deal with a float value like converting it to a string representation, and vice-versa. An object of the Float class can hold a single float value. The task is to multiply two Floating point
1 min read
Java Program to Swap Two Numbers
Problem Statement: Given two integers m and n. The goal is simply to swap their values in the memory block and write the java code demonstrating approaches. Illustration: Input : m=9, n=5Output : m=5, n=9 Input : m=15, n=5Output : m=5, n=15Here 'm' and 'n' are integer valueApproaches: There are 3 st
6 min read
Java Program to Add Two Binary Strings
When two binary strings are added, then the sum returned is also a binary string. Example: Input : x = "10", y = "01" Output: "11"Input : x = "110", y = "011" Output: "1001" Explanation: 110 + 011 =1001Approach 1: Here, we need to start adding from the right side and when the sum returned is more th
3 min read
Java Program to Add two Complex Numbers
Complex numbers are numbers that consist of two parts — a real number and an imaginary number. Complex numbers are the building blocks of more intricate math, such as algebra. The standard format for complex numbers is a + bi, with the real number first and the imaginary number last. General form fo
3 min read
Java Program to Check if a Given Integer is Odd or Even
A number that is divisible by 2 and generates a remainder of 0 is called an even number. All the numbers ending with 0, 2, 4, 6, and 8 are even numbers. On the other hand, number that is not divisible by 2 and generates a remainder of 1 is called an odd number. All the numbers ending with 1, 3, 5,7,
7 min read
Java Program to Find the Largest of three Numbers
Problem Statement: Given three numbers x, y, and z of which aim is to get the largest among these three numbers. Example: Input: x = 7, y = 20, z = 56Output: 56 // value stored in variable zFlowchart For Largest of 3 numbers: Algorithm to find the largest of three numbers: 1. Start2. Read the three
4 min read
Java Program to Find LCM of Two Numbers
LCM (i.e. Least Common Multiple) is the largest of the two stated numbers that can be divided by both the given numbers. In this article, we will write a program to find the LCM in Java Java Program to Find the LCM of Two NumbersThe easiest approach for finding the LCM is to Check the factors and th
2 min read
Java Program to Find GCD or HCF of Two Numbers
GCD (i.e. Greatest Common Divisor) or HCF (i.e. Highest Common Factor) is the largest number that can divide both the given numbers. Example: HCF of 10 and 20 is 10, and HCF of 9 and 21 is 3.Therefore, firstly find all the prime factors of both the stated numbers, then find the intersection of all t
2 min read
Java Program to Display All Prime Numbers from 1 to N
For a given number N, the purpose is to find all the prime numbers from 1 to N. Examples: Input: N = 11Output: 2, 3, 5, 7, 11Input: N = 7Output: 2, 3, 5, 7 Approach 1: Firstly, consider the given number N as input.Then apply a for loop in order to iterate the numbers from 1 to N.At last, check if ea
4 min read
Java Program to Find if a Given Year is a Leap Year
Leap Year contains 366 days, which comes once every four years. In this article, we will learn how to write the leap year program in Java. Facts about Leap YearEvery leap year corresponds to these facts : A century year is a year ending with 00. A century year is a leap year only if it is divisible
5 min read
Java Program to Check Armstrong Number between Two Integers
A positive integer with digits p, q, r, s…, is known as an Armstrong number of order n if the following condition is fulfilled. pqrs... = pn + qn + rn + sn +....Example: 370 = 3*3*3 + 7*7*7 + 0 = 27 + 343 + 0 = 370Therefore, 370 is an Armstrong number. Examples: Input : 100 200 Output :153 Explanati
2 min read
Java Program to Check If a Number is Neon Number or Not
A neon number is a number where the sum of digits of the square of the number is equal to the number. The task is to check and print neon numbers in a range. Illustration: Case 1: Input : 9 Output : Given number 9 is Neon number Explanation : square of 9=9*9=81; sum of digit of square : 8+1=9(which
4 min read
Java Program to Check Whether the Character is Vowel or Consonant
For any given character, we need to check if it is a vowel or a consonant. As we know, vowels are ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ and all the other characters (i.e. ‘b’, ‘c’, ‘d’, ‘f’ …..) are consonants. Examples: Input : char = 'r' Output : Consonant Input : char = 'e' Output : Vowel Here, in the below im
2 min read
Java Program for factorial of a number
Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. In this article, we will learn how to write a program for the factorial of a number in Java. Formulae for Factorialn! = n * (n-1) * (n-2) * (n-3) * ........ * 1 Example of Factorial in Java 6! == 6*5*4
3 min read