COP 2800 (Java Programming I) Homework Assignment #1

 

Due: by the start of class on the date shown on the syllabus

Description:

Answer the following questions as briefly (but completely) as possible:

  1. What is a source program?  What is a compiler?
  2. What is the “JVM”?
  3. What is an operating system?
  4. Identify and fix the errors in the following code:
         public class Welcome  {
            public void Main(String[] args) {
                System.out.println('Welcome to Java!);
            }
         )
  5. If a NoClassDefFoundError occurs when you attempt to run a Java program, what is the cause of the error?
  6. Why doesn't the System class need to be imported?
  7. Which of the following identifiers are valid?  Which are Java keywords? Applet, applet, a++, --a, 4#R, $4, #44, apps, class, public, int, x, y, radius
  8. What are the benefits of using constants?  How should you declare an int constant named SIZE with the value 20?
  9. Assume that “int a=1” and “double d=1.0”, and that each expression is independent of the others.  What are the results of the following expressions (that is, the resulting value of a or d)?
        a = 46 / 9;
        a = 46 % 9 + 4 * 4 - 2;
        a = 45 + 43 % 5 * (23 * 3 % 2);
        a %= 3 / a + 3;
        d = 4 + d * d + 4;
        d += 1.5 * 3 + (++a);
        d -= 1.5 * 3 + a++;
  10. If today is a Tuesday, what will be the day 100 days from now?  (Show the Java code to calculate that.)
  11. Are the following statements correct?  If so, show the output.
    1. System.out.println("25 / 4 is " + 25 / 4);
    2. System.out.println("25 / 4.0 is " + 25 / 4.0);
    3. System.out.println("3 * 2 / 4 is " + 3 * 2 / 4 );
    4. System.out.println("3.0 * 2 / 4 is " + 3.0 * 2 / 4);
  12. How would you write the following arithmetic expression in Java?
    4 3 ( r + 34 ) 9 ( a + bc ) + 3 + d ( 2 + a ) a + bd {4} over {3(r+34)} - 9(a+bc) + {3+d(2+a)} over {a+bd}
          4                 3 + d(2+a)
       -------  - 9(a+bc) + -----------
       3(r+34)                 a+bd
    
    arithmetic formula - GIF version
  13. What is wrong in the following statements?
    1. System.out.printf("%5d %d", 1, 2, 3);
    2. System.out.printf("%5d %f" , 1);
    3. System.out.printf("%5d %f" , 1, 2);
  14. Show the output of the following statements:
    1. System.out.printf("amount is %f %e\n" , 32.32, 32.32);
    2. System.out.printf("amount is %5.4f %5.4e\n", 32.32, 32.32);
    3. System.out.printf("%6b\n", (1>2));
    4. System.out.printf("%6s\n", "Java");
    5. System.out.printf("%-6b%s\n", (1>2), "Java");
    6. System.out.printf("%6b%-s\n", (1>2), "Java");
    7. System.out.printf("%6b%-8s\n", (1>2), "Java");

To be turned in:

Email your homework assignment, by copy-and-paste (no attachments please, to (homework submission).  If possible use the “text” and not the “HTML” mode of your email program.  Please use the subject similar to “Java Programming I Homework Assignment #1 Submission”, so I can tell which emails are submitted homework assignments.

Homework assignments will not be returned.  Please do not send as attachments.  Refer to the Homework and the Submitting Assignments sections of your syllabus for more information.

Confused?  Send questions about the homework assignment to (homework questions).  Please use a subject similar to “Java Programming I Homework Assignment #1 Questions” so I can tell which emails are questions about assignment quiz (and not submissions).