Java Programs for Practice
All Java Topics
Last updated: May 25, 2026
Author: ManaCoding Team
This section contains structured Java programs for practice covering strings, arrays, loops, patterns, and basic algorithms to improve coding skills.
Syntax
// Basic Java Structure
public class Main {
public static void main(String[] args) {
System.out.println("Practice Java Programs");
}
}
Example Program
// 1. Print Hello World
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
// 2. Swap two numbers
class SwapNumbers {
public static void main(String[] args) {
int a = 10, b = 20;
int temp = a;
a = b;
b = temp;
System.out.println("a=" + a + " b=" + b);
}
}
// 3. Check Even or Odd
class EvenOdd {
public static void main(String[] args) {
int num = 7;
if (num % 2 == 0) {
System.out.println("Even");
} else {
System.out.println("Odd");
}
}
}
// 4. Print Multiplication Table
class MultiplicationTable {
public static void main(String[] args) {
int num = 5;
for (int i = 1; i <= 10; i++) {
System.out.println(num + " x " + i + " = " + (num * i));
}
}
}
// 5. Sum of Digits
class SumOfDigits {
public static void main(String[] args) {
int num = 1234;
int sum = 0;
while (num > 0) {
sum += num % 10;
num /= 10;
}
System.out.println(sum);
}
}
// 6. Reverse Number
class ReverseNumber {
public static void main(String[] args) {
int num = 1234;
int rev = 0;
while (num > 0) {
rev = rev * 10 + (num % 10);
num /= 10;
}
System.out.println(rev);
}
}
// 7. Print Star Pattern
class StarPattern {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
1. Why Practice Java Programs?
- 1 Improve logic building
- 2 Prepare for interviews
- 3 Understand syntax
- 4 Build confidence in coding
2. Types of Practice Programs
- 1 Basic programs
- 2 Loop programs
- 3 Array programs
- 4 Pattern programs
3. Important Topics
- 1 Loops and conditions
- 2 Strings and arrays
- 3 Math problems
- 4 Patterns
4. Practice Strategy
- 1 Start with basics
- 2 Repeat daily practice
- 3 Solve interview questions
- 4 Increase difficulty gradually
Quick Summary
- Java practice programs help beginners learn coding.
- Covers loops, arrays, and patterns.
- Important for interview preparation.
- Improves logic and confidence.
FAQs
Why practice Java programs?
To improve logic and coding skills.
What is swap program?
Program to exchange values of two variables.
What is reverse number?
Reversing digits of a number.
What are pattern programs?
Programs that print shapes using loops.
How to improve coding skills?
By daily practice and solving problems.
Interview Questions
Q1.
Why practice Java programs?
Answer:
To improve logic and coding skills.
Q2.
What is swap program?
Answer:
Program to exchange values of two variables.
Q3.
What is reverse number?
Answer:
Reversing digits of a number.
Q4.
What are pattern programs?
Answer:
Programs that print shapes using loops.
Q5.
How to improve coding skills?
Answer:
By daily practice and solving problems.
Quiz
What is the main benefit of Java practice programs?