Java Projects

by Michael Thomas

(Tutorial Home Page)

by Michael Thomas

(Tutorial Home Page)

To learn a programming language you must get your hands dirty in the source code.  I've prepared some Java Projects to help you learn the Java Language Fundamentals.

If your in one of my ILT (Instructor Led Training) courses, see the syllabus's sessions link to know which projects you are to complete and when they are due.  If you are a web self learner and preparing for the SCJP exam, I suggest trying to complete all of the projects unless you use the code at work.

To complete the projects, find examples at one of the following resources:

Metrics - This is the concepts that you need to implement.  If you are in one of my ILT classes, grade yourself on the metrics that you attempted to implement (max 20 pts) and the metrics that you correctly implemented (max 20 pts) which totals to 40 pts.  The other 60 pts will be explained in class.

* = Example(s) at SCJP Certification Training site.

Project # Description
WS1 Take your First Java Steps.
  • Goto www.michael-thomas.com/java/javafirststeps and complete the following:
  • Download and install your first JDK, JRE & Java API from Sun. (5pts)
  • Compiling your first Java program from DOS. (5pts)
  • Edit/Debug your first Java program from a text editor. (5pts)
  • Edit/Debug your first Java program from a Java IDE (Option w/ILT - we will do this in class if institution allows).  (0 points - optional)
  • Take your first Java tutorial.  Take just the first 2 lessons: "Your first cup of Java" and "Getting Started". (5pts)
  • NOTE:  For ILT courses we will probably do all of these steps together in the lab.

Note: ILT courses hand in the following:

  • MyFirstApplication.java - Add the grading comments at the top of this file.
  • MyFirstApplet.java
  • MyFirstApplet.htm
  • You don't need to create any Questions for this project.
  • Note:  The Java IDE will be done in class so this is Optional.
  • Make sure you perform a code walkthrough with a student in the class.
P1* Java Application - Hello World to Java Console. (File/Class naming & main)

Be creative and create one or more Java applications which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Display "Hello World" to the Java console using System.out.println() and also print 2 values passed via command parameters.  (5pts)
  • Add the following types of Comments - single line, multi-line, and JavaDoc. (5pts)
  • Class and File Naming - Name your file "HelloWorld_app1.java".  Name your class "HelloWorld_app1". (5pts)
    Before you try each of the following changes make sure you delete the class files that were created in the previous compile.  Try to compile and run the following changes to your application and record your results as comments in your source code.
    Run your programms with: java HelloWorld_app1
    • public class HelloWorld_app1 //Currently works fine.
    • public class HelloWorld_app // class HelloWorld_app is public, should be declared in a file named HelloWorld_app.java.
    • class HelloWorld_app //java.lang.NoClassDefFoundError: MyHelloWorld_app
    • class HelloWorld_app1 //OK
    • Some of the errors you might encounter:
      • Error: class HelloWorld_app is public, should be declared in a file named HelloWorld_app.java.  Solution - if a class is public, then the file name must be the same as the public class.
      • Error: Exception in thread "main" java.lang.NoClassDefFoundError: MyHelloWorld_app.  Solution - the class file name created matches the name of the class definition, NOT the file name.  Therefore either run the new class name "java MyHelloWorld_app" or change the class name to match the file name.
  • Memorize the items in the main() method. (Note the name of the String array "args[]" can be named differently however "args[]" is the industry standard.
    Try to compile and run the following changes to your application and record your results as comments in your source code.  (5pts)
    • public static void main( String [] args ) //Industry standard.
    • public static void main( String [] myargs ) //Variable name is changed - OK
    • public static void main( String args [] )  //Another way to declare an array of String - OK
    • static void main ( String [] args )  //Missing public - OK, but bad.
    • public static main( String [] args ) //Missing void
    • public static void Main( String [] args ) //Class name is different.
    • public static void main( ) //Missing array of String parameter.
    • public void static main( String [] args ) //Return type does not precede identifier.
    • Errors you may encounter:
      • Runtime: Exception in thread "main" java.lang.NoSuchMethodError: main
        Note: static - need to see method without instantiation.  main( String args ) - JVM looks for main() with a String parameter.
      • Compile: invalid method declaration; return type required
        Note: void - method need to return a value.
      • Compile: <identifier> expected - if return type "void" does not precede main()
P2* Java Application - Hello World, by extending AWT's Frame.

Be creative and create one or more Java applications which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Display "Hello World" using Graphics.drawString() and extending Frame.(4pts)
  • Set the title of the Frame to: "Java Application extending java.awt.Frame" (4pts)
  • Set the size of the Frame to 500 pixels wide (x)  by 100 pixels tall (y). (4pts)
  • Use Container's getInsets() (super of Frame) to locate the beginning of the visible drawing area so you can use Graphics.drawString().  Also, display the coordinates of the insets to the Java Console. (4pts)
  • Add a window listener so that the "X" in the upper right of the Frame box will close the application.  Test the "X".  Now comment out the listener and notice that the "X" does not close the window.  Make sure you test from DOS so that you can kill the application by killing the DOS window.  You can also use Task Manager (Ctrl-Alt-Delete) to kill the process. (4pts)
P3* Java Application - Hello World, by extending Swing's JFrame

Be creative and create one or more Java applications which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Display "Hello World" using Graphics.drawString() and extending JFrame (5pts)
  • Set the title of the Frame to: "Java Application extending java.awt.JFrame" (5pts)
  • Set the size of the Frame to 500 pixels wide (x)  by 100 pixels tall (y). (5pts)
  • Use Container's getInsets() (super of Frame) to locate the beginning of the visible drawing area so you can use Graphics.drawString().  Also, display the coordinates of the insets to the Java Console. (5pts)
P4* Java Application - Swing's Dialog Box

Be creative and create one or more Java applications which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Using JOptionPane.showInputDialog()  display the following 5 Types of Swing's Dialog Boxes: Error, Information, Warning, Question, Plain. (10pts)
  • Using JOptionPane.showMessageDialog()  display the following 5 Types of Swing's Dialog Boxes: Error, Information, Warning, Question, Plain. (10pts)
P5* Java Applet (AWT's Applet) - Hello World.

Be creative and create one or more Java applets which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Display "Hello World" to the screen using Graphics.drawString(). (2pts)
  • Name your class and file name: HelloWorld.java.  
    Create an HTML file ("HelloWorld.html") that will launch the applet.  Once it launches your applet correctly, then change the the applet tag to: applet code="MyHelloWorld.class".  Record the results.  (5pts)
    (Note: here is an example of HTML Code)
    <html>
    <head>
    <title>
    Hello World - Applet only</title>
    </head>
    <body>
    <h1 align=
    "center">Hello World - Applet</h1>
    <hr align=
    "center">
    <p align=
    "center">
    <applet code=
    "HelloWorld.class" codebase="." align="baseline" width="275" height="55"></applet>
    </body>
    </html>
  • What seems to be the difference between using the DOS command "appletviewer" to view the applet vs using a browser (IE 5.X or NS 4.X) ?  You may want to try NS6. Record the results in your source code as a comment. (5pts)
  • Since there is no main(), how was the paint() method called?  Record your answer in the source code. (3pts)
  • Locate the Graphics class in the Java API and list 5 other methods in that class. Record your research as a comment in you source code. (5pts)
P6* Java Applet (Swing's JApplet) - Hello World.

Be creative and create one or more Java applets which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • JApplet (5pts)
  • Graphics.drawString() (5pts)
  • From the Java API choose 1 additional methods of the Graphics class and implement. (5 pts)
  • What seems to be the difference between using the DOS command "appletviewer" to view the applet vs using a browser (IE 5.X or NS 4.X) ?  You may want to try NS6. 
    (Warning: JApplet was implemented with Swing in Java 1.2.  IE 5.X and NS 4.X implement Java 1.1 therefore these browsers will have problems.  NS 6.X implements Java 1.2) (5pts)
P7* Java Applet - Applet Methods & Parm Passing.

Be creative and create one or more Java Applets which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 5 test questions)

Metrics:

  • In each of the following methods of Applet, write to the Java Console a message saying indicating that the method was run:  (Note: JApplet works the same way.)
    • init(),  (5pts)
    • paint(), (5pts)
  • Pass 3 or more parameters from the HTML Applet tag into your Applet and display them. (10 pts)
    Example applet tag:
    <applet code="HelloWorld.class" codebase="." align="baseline" width="275" height="55">
    <param name=
    "First" value="Michael">
    <param name=
    "Last" value="Thomas">
    <param name=
    "Middle" value="Arthur">
    </applet>
P8* Java Application - Fundamentals (Identifiers, Primitive Data Types, Literals, Escape Characters)

Be creative and create one or more Java applications which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Play with identifier names.  Create some that cause compiler errors.  Then comment the line out and note that the line will cause a compile error. (4pts)
  • Integer Wrapper Classes:  Integer.parseInt() & Double.parseDouble() (4pts)
  • Escape sequences: \n, \\, \", \t  (4pts)
  • Java primitive data types: boolean, char, byte, short, int, long, float, double.  Create each of these primitives and assign a literal value to them. (4pts)
  • String Class:  Add the code to your program. Make comments on each line that has interesting results.  (4pts)
    • String strEx1 = "Hello World";
    • System.out.println( strEx1);
    • System.out.println( "equals : " + strEx1.equals( "Hello World" ) );
    • strEx1 = strEx1 + " - add info.";
    • System.out.println( strEx1 );

Note: 

  • An identifier is a series of characters consisting of letters, digits, underscores(_) and dollar signs ($) that does not begin with a digit, does not contain any spaces and is not a keyword.
P9* Java Application - Fundamentals (Operators, Assignments, & Comparison)

Be creative and create one or more Java applications which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Arithmetic operators: +,-,*,/,% (modulus), =  (3pts)
  • Precedence of operators: (Place this code in your program.)  (3pts)
    • 3 + 2 * 3 = 9 (not 15) 
    • (3 + 2) * 3 = 15  
  • Equality: ==, !=, >, <, >=, <= (3pts)
  • Increment and decrement operators: x++,++x, x--, --x (3 pts)
  • Arithmetic assignment operators: +=, -=, *=, /=, %=  (3 pts)
  • Logical Comparison:  ||, &&, ! (5 pts)
P10* Java Application - Control Structures: if/else, ?:, for

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • if/else (5pts)
  • inline if - ?: (5pts)
  • for (5pts)
  • Understand and use the following code in your program: (5 pts)
    int intFirst = 5; int intSecond = 4;
    strMsg = ( inFirst == intSecond ) ? "Equal to" : "Not equal to";
P11* Java Application - Control Structures: while, do/while

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics

  • while loop (5pts)
  • do/while loop (5pts)
  • Create another while loop and use the continue; statement. (5pts)
  • Create another do/while loop and use the break; statement. (5pts)
P12* Java Application - Control Structures: switch w/break

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics

  • switch (10 pts)
  • Another switch using the break; statement (10 pts)
P13* Java Application - Strings & Characters

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • String class methods: charAt, equals, equalsIgnoreCase, endsWith, startsWith, indexOf, lastIndexOf, length(), replace(), substring(), trim(), toUpperCase(), toLowerCase(), regionMatches() and compareTo() - alphabetical order.  Also show valueOf(int) used as a static method! (4pts)
  • String class constructor: use 3 of the constructors. (2 pts)
  • String compare - add the following example code to your program to show how string compares work. (2 pts)
    • String strEx1 = "Hello";
    • String strEx2 = "Hello";
    • String strEx3 = strEx1;
    • if ( strEx1 == strEx1 ) { <your code ...> }
    • if ( strEx1 == strEx2 ) { <your code ...> }
    • if ( strEx1.equals( strEx2 ) { <your code ...>  }
    • if ( strEx1 == strEx3 ) { <your code ...> }
  • StringBuffer class methods: append(), delete(), insert(), length(), replace(), toString(). (5 pts)
  • StringTokenizer - Take the string "This is a test." and list the words one word at a time. (5 pts)
  • Character class - isDigit, isLetter(). (2 pts)
P14 Java Application - Math & Random class

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • java.lang.Math class: 
    • abs() (3pts)
    • ceil() (3pts)
    • floor() (3pts)
    • max() (3pts)
    • min() (3pts)
    • random() (3pts)
  • java.util.Random class (2pts)
P15 Java Application - Wrapper Classes for Primitive Data Types

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Integer - for int's
  • Byte - for byte's
  • Short - for short's
  • Long - for long's
  • Float - for float's
  • Double - for double's
  • Boolean - for boolean's
  • Character - for char's
P16* Java Application - Arrays

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Declare an array (astrList) that will hold 10 Strings.  Next use the a "for" loop to load the array with the following:  "String " + i . (5pts)
    Example data would be: String1, String2, String3, etc...
  • Pass the above array to a method "void changeValue (astrList)" which will change the first value to "Changed".  Now list the array to the Java Console. (5pts)
  • In one statement, declare and instantiate an array (aintList) with a list of 5 int's.  Then list the array to the Java Console. (5pts)
  • Declare a multi-dimensional array.  Next load the array with the following table of data and the then list to the Java Console. (5pts)
    10 11 12 13
    20 21 22 23
    30 31 32 33
P17 Java Application - Graphics & Graphics2D

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Font class (5pts)
  • Color class (5pts)
  • Graphics class - drawRect, fillOval, draw3DRect().  Make your drawPolygon() example a unique shape. (5pts)
  • Gprahics2D - use the class to draw a shape. (5pts)
  • JColorChooser - (Extra 5pts)
P18
Under Construction
Java Application/Applet - Images & HotSpots

Be creative and create a Java Applet/Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Make sure the Java program will run as an Applet or as an Application.
  • Display a graphic image and create 2 hotspots that can be clicked.  When clicked, popup a new window and display a message that shows which hotspot was clicked.
  • Click here to download the graphics.
P19
Under Construction
Java Application: Object-Based Programming

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Click here - to download a complete example.  Recreate all of the files by hand and read the Java Jems at my Certification site.
  • Constructors: default, multiple, super()
  • Variable Scoping: 
    • Class scope (instance & static): public, private, protected, default
    • Method scope (local), and 
    • block scope
    • final
  • Methods: Static, Public, Private 
  • Method overloading & overriding
  • Setter/Getter methods 
  • Creating Packages 
  • "this" & "super"  reference
P20
Under Construction
Java Application: Object-Oriented Programming

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Click here - to download a complete example.  Recreate all of the files by hand and read the Java Jems at my Certification site.
  • Inheritance "Is a" (a class that is a Subclasses)
  • Composition "has a" (a class has an objects)
  • Polymorphism (call a super class's method but have Java execute the correct overriden method polymorphically (many forms).)
  • Method overriding
  • Member Access control - protected
  • Constructors - using the super() method
  • Super's Methods - call a super method with super.methodname()
  • Inner & Anonymous Class for event handling.
P21
Under Construction
Java Application: Packages & JavaDoc

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Click here - to download a complete example.  Recreate all of the files by hand and read the Java Jems at my Certification site.
P22 Java Applet - AWT Layout Managers

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Panel - this is a container for components which works well w/Applets and Applications. (5pts)
  • Implement 2 of the following Layout Managers (5pts)
    • FlowLayout - (4pts)
    • BorderLayout - (2pts)
    • GridLayout - (2pts)
    • CardLayout - (2pts)
  • GridBagLayout - this is the most flexible and useful layout.  Also the most difficult to implement. (10pts)
P23 Java Applications - Event Listeners & Adapters

Be creative and create one or more Java Applications,  which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • ActionListener (5pts)
  • ItemListener (5pts)
  • FocusListener (5pts)
  • WindowListener (5pts)
P24 Java Application - Mouse & MouseMotion Listeners & MouseEvent

Be creative and create one or more Java Applications,  which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • As the mouse is moved or clicked display to the screen messages that show the methods below were called by implemented the MouseListener & MouseMotionListener interfaces bellow.
  • MouseListener Interface
    • mouseClicked()
    • mouseEntered()
    • mouseExited()
    • mousePressed()
    • mouseReleased()
  • MouseMotionListener Interface
    • MouseDragged()
    • MouseMoved()
P25 Java Application - Keyboard Events

Be creative and create one or more Java Applications,  which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Component.requestFocus() (5pts)
  • Make the Enter key & mouse click work on a Button (10pts)
  • Make the Enter key work on a TextField (5pts)
P26* Java Applet and/or Application - AWT GUI Components

Be creative and create a Java Application, which will also run as an Applet,  which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics

  • For each of the components below, create an Event Handler to show that you can trap an event from each component. (10 pts)
  • AWT Components (10 pts)
    • Label (1 pt)
    • TextField (1 pt)
    • Button (1 pt)
    • CheckBox (1 pt)
    • Radio Buttons (CheckBox w/CheckboxGroup) 2pts
    • List (Single or Multi select) (2 pt) 
    • Choice (2 pt)
P27 Java Applet and/or Application - Swing GUI Components

Be creative and create a Java Application, which will also run as an Applet,  which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics

  • For each of the components below, create an Event Handler to show that you can trap an event from each component. (10 pts)
  • Swing (10 pts)
    • JLabel
    • JTextField
    • JPasswordField
    • JButton
    • JCheckBox
    • JRadioButton
    • JList
    • JPanel
P28 Java Application - Collection Classes: Vector & List

Be creative and create a one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Note: Vector & HashTable have been around since JDK1.0.

Metrics:

  • Vector (10pts)
  • List (10 pts)
P29 Java Application - Collection Classes: Sorting, Searching, Arrays, ArrayList

Be creative and create a one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Note: Vector & HashTable have been around since JDK1.0.

Metrics:

  • Use Collections.sort to sort an ArrayList (10pts)
  • Use Collections.binarySearch to locate an item in the ArrayList. (10pts)
P30 Java Application - Collection Classes: HashMap & TreeMap

Be creative and create a one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Note: Vector & HashTable have been around since JDK1.0.

Metrics:

  • HashMap (10pts)
  • TreeMap (10pts)
P31 Java Application - Exception Handling

Be creative and create a one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • try, catch, finally (3 pts)
  • Trap a divide by zero exception. (2pts)
  • Create your own custom exception and trap it's error. (10pts)
  • Throw an exception (5 pts)
P32* Java Application - Files and Streams

Be creative and create a one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Create a program that will display a String with at least 5 lines to the screen and then create a text file from that String. (10 pts)
  • Create a program that will read a text file, place the contents into a String, and then display it's contents to the screen. (10 pts)
P33
Under Construction
Java Application - Threads

Be creative and create one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Click here - to download a complete example.  Recreate all of the files by hand and read the Java Jems at my Certification site.
Extra Credit Extra Credit Projects

You can apply the extra points to any of your the project grades.

Extra 1
(10 pts)
Java Application - AWT's ScrollPane w/ ScrollBars

Be creative and create a one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Extra 2
(10 pts)
Java Application - AWT's FileDialog

Be creative and create a one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Display to the screen the file name that the user choose.
Extra 3
(10 pts)
Java Application - AWT Menu's

Be creative and create a one or more Java Application which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

 

Extra 4
(10 pts)
Java Applet and/or Application - Advanced Swing GUI Components

Be creative and create a Java Application, which will also run as an Applet,  which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • JTextArea 
  • JSlider 
  • JTable
Extra 5
(10 pts)
Java Applet and/or Application - Swing GUI Menu's

Be creative and create a Java Application, which will also run as an Applet,  which shows the implementation of your knowledge of the following concepts (metrics):
(Reminder: Create 2 test questions)

Metrics:

  • Java Menu's - Create a menu with at least 2 items in the menu bar, at least 2 items in the pull down menu,  and at least one submenu.  Use a separator bar in at least one of the pull down menu's. (5 pts)
  • JPopupMenu (2 pts)
  • JDesktopPane & JInternalFrame (2 pts)