P1 Test Questions

(Project Test Home Page)

Objectives

# Question
1 Using the Java Console
Which code sample will display "Hello World" to the Java Console
(Choose all that apply)

A. System.out.println( "Hello World" );
B. drawString( "Hello World", 10, 10 );
C. System.out.println( Hello World );
D. System.out.println( 'Hello World' );

2 Passing command line parameters
Which of the following code samples will compile and run without a runtime error? 
(Choose all that apply)

Command line:  C:\> java MyHello_App_Parms Hello World

public class MyHello_App_Parms {
  public static void main( String [] args ) {
    <Place code below here>
  }
}
    
A. System.out.println(MyArgs[1]);
B. System.out.println(args[1]);
C. System.out.println(args[2]);
D. System.out.println("Here it is: " + args[1]);
3 Comments
Which of the following statements about Java's  3 types of comments (single, multi-line, and JavaDoc) is true ? 
(Choose all that apply)

A. This is a single line comment:  /* Hello */
B. This is a multi-line comment: //Hello //Hello
C. This is a multi-line comment: <!-- Hello -->
D. This is a JavaDoc comment: /**  Hello */

4 Class Declarations
Assuming you have a java application by the name of "MyHelloWorld_app.java" which of the following class definitions will create the compile error?
class MyHelloWorld is public, should be declared in a file named MyHelloWorld.java 
(Choose all that apply)

A. class MyHelloWorld
B. public class MyHelloWorld
C. public class MyHelloWorld_app
D. None of the above

5 Declaring the main() method
Which of the following code samples will create the following runtime error?
Runtime: Exception in thread "main" java.lang.NoSuchMethodError: main
(Choose all that apply)

A. public static void main( String [] args )
B. public static void main()
C. public static void Main( String [] args )
D. None of the above

6 Declaring the main() method
Which of the following code samples will create the compile error?
Compile: invalid method declaration; return type required
(Choose all that apply)

A. public static void main( String [] args )
B. public static void main()
C. public static main( String [] args )
D. public static void main( String [] myargs )

7 Passing command line parameters
Which of the following code samples will print the first parameter passed to a Java application to the Java console? (Choose all that apply)

Assume the main() method: public static void main( String [] args )

A. System.out.println(MyArgs[1]);
B. System.out.println(args[1]);
C. System.out.println(args[2]);
D. None of the above
8 Passing command line parameters
Assuming the code will compile and run, what will show in the Java Console? (Choose all that apply)

Command line:  C:\> java HelloWorld_App Michael Thomas

public class HelloWorld_App {
  public static void main( String [] args ) {
     System.out.println("My name is " + args[1]);
  }
}

A. My name is Michael
B. My name is Thomas
C. My name is
D. None of the above
9 void - data type
The return data type of void means?
(Choose one)

A. A void area in memory is returned so that you can populate it.
B. No data type is returned.
C. void is not a valid data type.
D. None of the above

10 Class declarations
In order for the following class definition  to successfully compile, which of the following are true?
(Choose all that apply)

class definition:  public class HelloWorld_App

A. HelloWorld_App must have a correctly formed main() method
B. HelloWorld_App must be defined in the file HelloWorld_App.java
C. HelloWorld_App must be defined in the HelloWorld package.
D. HelloWorld_App must be imported.

11 Comments
Which of the following are valid Java comments (single line, multi-line, or JavaDoc)?
(Choose all that apply)

A. \\ This is a comment.
B. /* This is a comment. */
C. /** This is a comment. */
D. \* This is a comment *\

   
* = Advanced questions.