/Java-Programs

Java code for fundamental programs for students

Primary LanguageJava

Java-Programs

Java code for fundamental problems for student

Module 1:

  1. Program to read a number from the user and print whether it is positive or negative. PositiveNegative.java Positive.Java
  2. Program to solve quadratic equations (use if, else if and else). QuadraticEquation.Java
  3. Take three numbers from the user and print the greatest number. GreatestThree.java Greatest3.java
  4. Program that keeps a number from the user and generates an integer between 1 and 7 and displays the name of the weekday. Weekday.java
  5. Program that reads in two floating-point numbers and tests whether they are the same up to three decimal places. FloatingDigit.java
  6. Program that takes a year from user and print whether that year is a leap year or not. LeapYear.java
  7. Program to display the first 10 natural numbers. FirstnNatural.java
  8. Program to input 5 numbers from keyboard and find their sum and average. SumAverage.java
  9. Program in Java to display the multiplication table of a given integer. MultiplicationTable.java
  10. Program in Java to display the pattern like right angle triangle with a number. PrintPattern.java
Input number of rows : 5
Expected Output :
1 
12 
123 
1234 
12345
  1. Program to compute the factorial of a given number. Factorial.java
  2. Program to compute the area of a circle for given radius. AreaCircle.java
  3. Program to check whether a given string is Palindrome or not. Palindrome.java
  4. Program to print Fibonacci series upto a given number. FibonacciSeries.java
  5. Program to revese the digit order for a given number. ReverseOrder.java
  6. Program to check wheter a given character is alphabet or not. AlphabetCharacter.java
  7. Program to compute the Greatest Common Divisor (GCD) of given two numbers.GCD_2Num.java
  8. Program to compute the Least Common Multiple (LCM) of given two numbers. LCM2NUM.java
  9. Program to display all prime numbers in between two given numbers. AllPrime.java
  10. Program to compute the compound interest. CompoundInterest.java
  11. Program to compute the simple interest. SimpleInterest.java
  12. Program to check wheter a given number is an even or an odd number. EvenOdd.java
  13. Program to swap two numbers. SwapTwo.java
  14. Class name and file name may be different. Test.java

Module 2:

  1. Program to read two numbers and perform the arithmetic operations using method. Add2Num.java SumMethod.java
  2. Program that performs arithmetic with values of type char. AddCharacter.java
  3. Design a class to overload a method compare() to return the greater of two as follows: CompareMethod.java
void compare(int, int)
void compare(char, char)
void compare(String, String)
  1. Program that creates a class Account that stores a variable balance. The class has methods to start account, to deposit money, to withdraw money and tell the current balance amount. BankAccount.java
  2. Program to implement a Book class that stores the details of a book such as its code, title and price (Use constructors to initialize the objects). BookDetails.java
  3. Program to differentiate between static and non-static methods. StaticVsNonStaticMethod.java
  4. Program to illustrate the usage of this, final and finalize. This_Final_Finalize_Working.java
  5. Program to implement the concept of dynamic method dispatch. DynamicMethodDispatch.java
  6. Program to pass the variable length arguments. VariableLenArgu.java
  7. Program to show the overloading of constructures. ConstructorOverloading.java
  8. Program to read the comman line arguments and print the total number of arguments and its values. CommandLineAgu.java

Module 3:

  1. Program for sorting a given list of names in ascending order. ListSorting.java
  2. Program to multiply two given matrices. MatrixMultiplication.java
  3. Program to find the maximum and minimum value in an array of size m passed as argument. ArrayMinMax.java
  4. Program to read and print an array of size n rows with variable column size. (Hint: Irregular Array). IrregularArray.java
  5. Program that copies contents of one array to another using length member. CopyArray.java
  6. Program to find element from an sorted array using binary search. (Hint: java.util.package) BinarySearch.java
  7. Program to delete duplicate elements from an array of size 5. RemoveDuplicate.java
  8. Program that reverses an array and stores it in the same array. ReverseArray.java
  9. Program to implement all String methods on a Input String. StringOperations.java
  10. Program to convert a given integer array of size n into string. Integer2String.java
  11. Program to read and print a given string using different methods. ReadStringMethod.java
  12. Program to reverse the words in a string. ReverseString.java
  13. Program to read a string and replace all the vowels with a @ symbol. ReplaceVowels.java
  14. Program to count the number of occurrences of a search string in a given text string. SubStringCount.java

Module 4:

  1. Program to define a class Point with two fields x and y each of type double. also, a method distance(Point p1, Point p2) to calculate the distance between points p1 and p2 and return the value in double. Hint: use Math.sqrt() Distance2Point.java
  2. Program for a class Shape is defined with two overloading constructors in it. Another class Test1 is partiallydefined which inherits the class Shape. The class Test1 should include two overloading constructors as appropriate for some object instantiation. You should define the constructors using the super class constructors. Also, override the method calculate() in Test1 to calculate the volume of a Shape. ShapeOverloading.java
  3. Program to create a class named 'Member' having the following members: Name, Age, Phone number, Address, Salary. It also has a method named printSalary which prints the salary of the members. Two classes Employee and Manager inherits the Member class. The Employee and Manager' classes have data members specialization and department respectively. Now, assign name, age, phone number, address and salary to an employee and a manager by making an object of both of these classes and print the same. EmployeeInheritence.java
  4. Program to create a class named 'Shape' with a method to print This is This is shape. Then create two other classes named Rectangle, Circle inheriting the Shape class, both having a method to print This is rectangular shape and This is circular shape respectively. Create a subclass Square of Rectangle having a method to print Square is a rectangle. Now call the method of Shape and Rectangle class by the object of Square class. ShapeOverloading1.java
  5. Program to create a class with a method that prints This is parent class and its subclass with another method that prints This is child class. Now, create an object for each of the class and call Inheritance1.java
  • method of parent class by object of parent class
  • method of child class by object of child class
  • method of parent class by object of child class
  1. Program to create a class telephone with ( ) , lift ( ) and disconnected ( ) methods as abstract methods create another class smart telephone and demonstrate polymorphism. PolymorphismExample.java
  2. Program to design a vehicle class hierarchy in Java, and develop a program to demonstrate Polymorphism. PolymorphismProgram.java
  3. Program to find the roots of a quadratic equation using interface and packages.
  • Declare an interface in package Quad1
  • Declare another package Quad2 and implement the interface
  1. Program to generate Fibonacci Series by using Constructor to initialize the Data Members. FibonacciSeries.java
  2. Program to demonstrate multiple inheritance through interface. MultipleInheritence.java

Module 5:

  1. Program to demonstrate the visibility of members in subclasses of same and different packages.
  2. Program to create a user defined package in Java.
  3. Program to find the roots of a quadratic equation using interface and packages.
  • Declare an interface in package Quad1
  • Declare another package Quad2 and implement the interface
  1. Define a Interface Polygon in package pack1. create a class triangle from Polygon in package pack2, override method to calculate area of the triangle and raise an exception if it is an equilateral triangle. (Note : Exception has to be defined in package pack3.)
  2. Develop a program to demonstrate exception handling by using THROW, MULTIPLE CATCH & FINALLY statements.
  3. Create a class Student with attributes roll no, name, age and course. Initialize values through parameterized constructor. If age of student is not in between 15 and 21 then generate user defined exception AgeNotWithinRangeException. If name contains numbers or special symbols raise exception NameNotValidException. Define the two exception classes.
  4. Program to throw a user defined exception for employee details
  • If an employee name is a number, a name exception must be thrown.
  • If an employee age is greater than 50, an age exception must be thrown
  1. Program to demonstrate nested exception.
  2. Program to create an Account class with data members accno, name,bal. Include methods deposit(), withdraw(). Raise an exception when balance in account is less than 1000.
  3. Create a Student class with data members Rollno, Name, marks in subjects. Include methods to compute average. Raise an exception if the student has more than 2 backlogs.