SDSU CS 596 Java Programming
Fall Semester, 1998
Assignment 1
To Assignment Index
© 1998, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 08-Sep-98

Due:
September 16 in class for SDSU section.
September 17 in class for Qualcomm section.

  1. What is the smallest integer type in Java needed to store:
      a) The USA's national debt?
      b) The population of the USA?
      c) The number of states in the USA

  2. Explain how the intern() method in java.lang.String can improve runtime performance of a program.

  3. In some languages the operators "&&" (and) and "||" (or) are short circuited. That is once the result of a boolean expression of &&s and ||s is known, the remainder of the boolean expression will not be evaluated. For example in (( x > x ) && ( z == y) ) the expression (z ==y) will not be evaluated. Write a Java method that will test if boolean expressions in Java are short circuited. Explain how your program will determine if boolean expressions are short circuited.

  4. In both parts of the problem do not perform any IO in the methods. Provide output to show that your program runs.
      a) Write a Java method that has a float parameter and returns the float converted to a string.
      b) Write a Java method that has a string parameter and returns the string converted to an int. Assume that the string represents an integer base 10 in the correct range for an int.

  5. Write a Java class that stores two shorts in a single int. Write methods putHigh( short highValue), putLow( short lowValue), getHigh(), and getLow() to store and retrieve short values from the int. Do not perform any IO in these four methods. Show the value of your int with the following values for the low and high short. Provide output to show that your program runs.

high
low
32767
-1
-32768
0
32767
32767
-32768
-32768

Copyright © 1998 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
All rights reserved.

visitors since 08-Sep-98