Exam
Submitted by jeffheaton on Thu, 01/10/2008 - 03:55
1. Which of the following is a valid main method? A> public static void main(String args[]) B> static void main(String args[]) C> public static void main() D> public static int main(String args[]) 2. Which company created Java? A> Microsoft B> Oracle C> IBM D> Sun Microsystems 3. How do you usually read a number from the user? A> Use the readNumber method. B> Use the inputNumber method. C> Use readLine to read in a string, and then convert that string to a number. 4. What does the command “javac” do? A> It compiles a Java program. B> It runs a Java program. C> It allows you to edit a Java program. 5. Given the following method declaration, what does "void" mean? public void test() A> The statement “void” means that this method does not return any thing. B> It means that this method will return a variable of type void. C> It means that this method should no longer be used. 6. Can a static method can access nonstatic instance variables? A> Yes B> No 7. Which of the following would you most likely store inside of a String? A> The name of your father. B> The year that a person was born. C> The price of butter. 8. Which of the following variable types can hold decimal places? (i.e. 3.13). Choose all correct answers A> byte B> short C> int D> long E> float F> double 9. Java programs must be compiled before they are run. A> True B> False 10. What happens when an Exception occurs inside of a try block, and there is a catch block that handles this sort of exception? A> The program terminates (crashes) B> An error message is displayed and the program continues. C> The program executes the catch block. 11. Which of the following variable types can be used with a switch/case block? There may be more than one correct answer. A> String B> int C> double D> byte E> short 12. Which of the following would you most likely store inside of an int? A> The name of your mother. B> The price of a pound of cheese. C> The number of rooms in your home. 13. What happens when you compile a computer program? A> The program is deleted. B> Your program begins running. C> The source code is converted to a form that the computer can easily understand, and execute. 14. What is a .class file? A> It is what the compiler produces. B> You edit this file and put your Java source code here. C> Java does not use .class files. 15. What is the proper way to compare two strings: str1 and str2? A> if( str1==str2 ) B> if( str1=str2) C> if( str1.equals(str2) ) 16. What does the Java import statement do? A> Displays a line of text. B> Not a valid Java statement. C> Allows your program to use other classes. 17. Are Java variable names case sensitive? A> Yes. B> No 18. What should be at the end of each case statement? A> break; B> end case C> end if 19. Which of the following makes use of Java’s single-line comment? A> # Comment line 1 #comment line 2 B> // Comment line 1 // Comment line 2 C> -- Comment line 1 -- Comment line 2 D> /* Comment line 1 Comment line 2 */ 20. Which of the following are valid types of Java applications? Choose all that are correct. A> Console Application. B> Java Applet C> Mini Java application. 21. What is true of packages and classes? A> Neither packages nor classes exist in Java, those words are meaningless. B> Classes are placed inside of packages for larger projects. C> Packages are placed inside of classes for larger projects. 22. What happens when you pass a bad number (i.e. “33jj2”) to the Integer.parseInt method? A> A NumberFormatException is thrown. B> The method would return 0. C> The method would return -1. D> The method would return null. 23. If the variable str contains a string and the variable d contains a double, how do you convert str into a double? A> d = str; B> d = val(str); C> d = Double.parseDouble(str); 24. What is the name of the first method that is executed? This is where your program begins. A> start B> startup C> main 25. What can usually replace an if/else ladder? A> Nothing, they are required. B> A switch/case block. C> A stair/case block.












