Java Practice Exercise

The following Java Practice Exercise will help you learn the Java Programming Language.

  1. Create a Java application that computes and displays the area of a circle.
  2. Demonstrate how typecasting & conversions take place in Java.
  3. Write code in Java language to perform add, subtract, and divide and multiply 2 numbers.
  4. Create a Java application to display the grade of a student.
  5. Demonstrate using a Java program to accept numbers as Command line arguments.
  6. Create a Java application that randomly generates a number and checks whether it is prime or not.
  7. Develop an application in Java that randomly generates a number from a range of 10-99 and checks whether it is Armstrong or not.
  8. Create an application in Java to insert an array and print those elements using command line arguments.
  9. Write code to initialize and print the elements of an array.
  10. Perform sorting on an array in ascending and descending order using a Java program.
  11. Create a Java program to display the smallest element of an array of 5 integers.
  12. Write a program to display the difference between smallest and largest elements of an array of 5 integers.
  13. Create a Java application to demonstrate the working of any Ten String class functions.
  14. Write code to extract surname from the complete name
  15. Write a program to create a class called StringDemo and declare three strings and use functions like length, charAt, and equals on them.
  16. Develop a program to create a class called Box and calculate its volume by calling its method.
  17. Build a Java application to create a class called Test and pass its object to one of its methods to illustrate the usage of reference variables.
  18. Write a program to create a class called Use Static and declare some static variables, a static method that will print those variables, and a static block that will perform some operation on that variable.
  19. Develop a Java application to create a class Add that will add to numbers by using a constructor.
  20. Write code to create a class called triangle with base and height as the attributes and calculate its area using the parameterized constructor.
  21. Develop an application in Java to create a class called Rectangle and calculate its area using this keyword.
  22. Write a program to create a class Area and calculate the area of the rectangle and circle using method overloading.
  23. Demonstrate how to create a class called Box with instance variables width, height, and depth. Create another class BoxWeight which inherits class Box with an additional instance variable weight. Compute the volume of the box using inheritance.
  24. Implement the above program using the super keyword.
  25. Create a class Figure and its 2 subclasses Rectangle and Triangle and calculate its area using dynamic method dispatch.
  26. Implement the above program using abstract classes by making the Figure class abstract.
  27. Create an application to show the usage of the final keyword with class, variables, and methods in java.
  28. Write relevant programs showing the usage of package and access protection in java.
  29. Create a java program to show the concept of importing a package.
  30. Write code in Java to implement stacks using interfaces.
  31. Demonstrate in Java the implementing nesting of the interface.
  32. Write relevant programs to show the usage of try, catch, throw, throws, and finally in java.
  33. Develop an application in Java to create a user-defined exception class using the extends keyword.
  34. Create an application that demonstrates how a program throws exceptions if the age of the voter is less than 18.
  35. Similarly, create another application that throws exceptions if the stack is full or is empty.
  36. Write a program that throws exceptions if the bank balance drops below 1000 due to any transaction.
  37. Create an application to show the concept of creating Thread through thread class and Runnable interface
  38. Write Java code to print multiples of 2,3,4 simultaneously.
  39. Demonstrate through a program that high priority thread gets more CPU attention than a low-priority thread.
  40. Write relevant programs to show the concept of thread synchronization and inter-thread communication.
  41. Create an application in Java that accepts a hostname and displays its IP address.
  42. Write a TCP/IP client-server program that echoes whatever is typed on the client to the server.
  43. Develop a Java application to demonstrate client-server application using Java RMI.
  44. Write a program that displays the life cycle of the Applet and other relevant programs that shows the implementation of Applets in java.
  45. Create a Java application to draw different figures using AWT.
  46. Develop a Java application to add a label, Buttons, Textfield, lists, etc using AWT.
  47. Create a login window to check user name and password using text fields and command buttons.
  48. Develop an application in Java that creates 3 control boxes for font name, size, and style, change the font of the text according to user selection.
  49. Create a Java program layout Manager to add different controls on a frame.
  50. Demonstrate using a Java program different event handlers.
  51. Develop a Java application that shows working with Graphics, colors, and fonts in AWT.
  52. Write a program to implement the Swing 2 function calculator.
  53. Create a Swing login window to check user name and password using text fields and command buttons.
  54. Develop a swing application with 3 control boxes for font name, size, and style, change the font of the text according to user selection.
  55. Create a program in java to show the connectivity of java with the database using SQL statements.
  56. Develop an application in Java to insert a record in the database.
  57. Demonstrate how to create a table in a database via java.
  58. Create an application in Java that updates some records.
  59. Write a program to create a simple bean.