Java Code Examples – Programmingempire

0
22

The following list presents some of the Java Code Examples.

Basic Java Code Examples

  1. In order to find area of ​​a rectangle, create a class Rectangle with data members length and breadth and member functions getDimensions () for reading input and findArea () to display the output.
  2. Write a program to demonstrate the use of method overloading to calculate area of ​​square, rectangle and triangle.
  3. Develop a program in Java to demonstrate the use of static variable, static method and static block.
  4. Write a program to demonstrate concept of “this” keyword in Java.
  5. Create a program to demonstrate multi-level and hierarchical inheritance.
  6. Write a program to use super () to invoke base class constructor.
  7. Further, write a program to demonstrate run-time polymorphism.
  8. Write a program to demonstrate the concept of aggregation.
  9. Develop a program to demonstrate the concept of abstract class with constructor and “final” method.
  10. Write a program to demonstrate the concept of interface when two interfaces have unique methods and same data members.
  11. Create a program to demonstrate checked exception during file handling.
  12. Write a program to demonstrate unchecked exception
  13. Similarly, write a program to demonstrate creation of multiple child threads.
  14. Write a program to use Byte stream class to read from a text file and display the content on the output screen.
  15. Create a program to demonstrate any event handling.

Advanced Java Code Examples

  1. Write a program to create a class employee which have name, age and address of employee, include methods getdata () and showdata (), getdata () takes the input from the user, showdata () display the data in the following format: Name: Age: Address:
  2. Furthermore, write a Java program to perform basic Calculator operations. Make a menu driven program to select operation to perform (+ – * /). Take 2 integers and perform operation as chosen by user.
  3. Write a Java program to find out whether the given String is Palindrome or not.
  4. Likewise, write a program to make use of BufferedStream to read lines from the keyboard until ‘STOP’ is typed.
  5. Write a program declaring a Java class called SavingsAccount with members “accountNumber” and “Balance”. Provide member functions as “depositAmount ()” and “withdrawAmount ()”. If user tries to withdraw an amount greater than their balance then throw a user-defined exception.
  6. Develop a program creating 2 threads using Runnable interface. Print your name in “run ()” method of first class and “Hello Java” in “run ()” method of second thread.
  7. Write a program to implement inter-thread communication.
  8. Create program that uses swings to display combination of RGB using 3 scrollbars.
  9. Develop a swing application that uses at least 5 swing controls
  10. Write a program to implement border layout using Swing.

Further Reading

Java Servlet Practice Questions

Source

LEAVE A REPLY

Please enter your comment!
Please enter your name here