Basic Java


Create a "Hello World" programming example. Compile and run the program. The topic is to learn how to compile a Java program with the javac command and run the compiled program with the java.


Write a program that prints three arguments taken from the command line.


Write a method that takes two string arguments and use the != and the equals method to compare the strings.


Create a method that uses a switch statement that prints a message to the screen for each case. Put the switch statement inside a loop statement that tries all the cases. Make two version of the method. One that uses a break for each case and one without breaks. The topics are the switch statement and loop structure.


Design a method that finds the largest value in an array of integers. The array is provided as a parameter to the method. Write test data to check that the program is correct.

Extra Assignments


Write a sort method that takes as input an unsorted array of integers in the range 0-9998 and prints the integers to screen in decreasing order. As an example on the input 23, 1, 9783, 1, 1, 23 the method prints 9783 23 1. Duplicates are allowed in the input as you can see, however, if a number is in the input several times (1 and 23 in the example) is should only be printed once. The sort method should have the complexity O(n) where n is the size of the input array. Note that the standard sort methods included in the JDK have the complexity O(nlogn). (Hint: boolean array).


Look at the other programs that are included with the J2SE version 1.5.0 SDK (can be found in the /pack/jdk-1.5.0_04 directory).