java programs for freshers

Top 8 java Programs for Freshers and Beginners in 2025

javatpoint java programs

javatpoint java programs

Java is one of the most famous programming languages with applications for developing applications, websites, and software solutions. If you are a fresher or just beginning, the best way to start learning Java is to practice some small Java programs. The article presents 10 important Java programs that will help you get deeper insights into the basic concepts of Java.

Java in AI and Machine Learning – A Complete Guide

1. Hello World Program in Java for Beginners

Hello World is the first Java program to learn in general. This is basically a way to show how to print something that goes to the screen.

Java is the first program Hello World one uses for learning. It is a generally method to show the method of printing something that goes to the screen.

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Explanation:

The public class HelloWorld is a class characterized as HelloWorld.

public static void main(String[] args)0 is the first place of entry to a program implemented in Java.

System.out.println(“Hello, World!”); prints out the phrase “Hello, World!” into the console.

2. Simple Calculator program in java for beginners

import java.util.Scanner;

public class SimpleCalculator {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter first number: ");
        double num1 = scanner.nextDouble();
        System.out.print("Enter second number: ");
        double num2 = scanner.nextDouble();
        System.out.println("Addition: " + (num1 + num2));
        System.out.println("Subtraction: " + (num1 - num2));
        System.out.println("Multiplication: " + (num1 * num2));
        System.out.println("Division: " + (num1 / num2));
        scanner.close();
    }
}

Explanation:

  • Uses Scanner to take user input.
  • Performs addition, subtraction, multiplication, and division.

3. Check Even or Odd Number in java

This program checks if a given number is even or odd.

import java.util.Scanner;

public class EvenOdd {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();
        if (num % 2 == 0) {
            System.out.println(num + " is even.");
        } else {
            System.out.println(num + " is odd.");
        }
        scanner.close();
    }
}

How to calculate Factorial of a Number in java

import java.util.Scanner;

public class Factorial {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();
        long factorial = 1;
        for (int i = 1; i <= num; i++) {
            factorial *= i;
        }
        System.out.println("Factorial of " + num + " is " + factorial);
        scanner.close();
    }
}

How to Create Fibonacci Series in java

This program generates Fibonacci numbers up to a given limit.

import java.util.Scanner;

public class Fibonacci {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter limit: ");
        int limit = scanner.nextInt();
        int a = 0, b = 1;
        System.out.print("Fibonacci Series: " + a + " " + b);
        for (int i = 2; i < limit; i++) {
            int next = a + b;
            System.out.print(" " + next);
            a = b;
            b = next;
        }
        scanner.close();
    }
}

How Check Prime Number in java

how to Checks whether a number is prime by a java programming

import java.util.Scanner;

public class PrimeCheck {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();
        boolean isPrime = true;
        for (int i = 2; i <= num / 2; i++) {
            if (num % i == 0) {
                isPrime = false;
                break;
            }
        }
        System.out.println(num + (isPrime ? " is Prime" : " is not Prime"));
        scanner.close();
    }
}

Reverse a Number program in java

By this program you can reverses an integer in java programming

import java.util.Scanner;

public class ReverseNumber {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();
        int reverse = 0;
        while (num != 0) {
            reverse = reverse * 10 + num % 10;
            num /= 10;
        }
        System.out.println("Reversed Number: " + reverse);
        scanner.close();
    }
}

How to Check a Armstrong Number in java

you can easily Checks whether a number is an Armstrong number by using below given code.

import java.util.Scanner;

public class Armstrong {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter a number: ");
        int num = scanner.nextInt();
        int original = num, sum = 0;
        while (num > 0) {
            int digit = num % 10;
            sum += digit * digit * digit;
            num /= 10;
        }
        System.out.println(original + (sum == original ? " is an Armstrong number" : " is not an Armstrong number"));
        scanner.close();
    }
}

1 Comment

  1. It’s perfect ttime to make some plans for the future and it’s time to be happy.I have read this post and if I could I want to suggest you some interesting things or
    advice. Perhaps you could write next articles referring to this article.
    I want to ead even more things about it! http://Boyarka-inform.com/

Leave a Reply

Your email address will not be published. Required fields are marked *