Objectives
Creating basic Java Applications
Use of the Java Console
Passing parameters via the command line.
Using Java comments.
# | 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" ); |
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 */ |
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 |
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
) |
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 ) |
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. |
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 |
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. |