Download Pre-AP Chapter 2/3 Test

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Pre AP Introducing Java Test
3rd Ed – Chapter 2
Name: _______________________
2nd Ed – Chapter 3
True/False
Indicate whether the statement is true or false.
____
1. Compiled source code files have the extension .java.
____
2. There is no difference between the print() and println() methods.
____
3. An escape sequence must be used to display a double quotation mark (").
____
4. A class defines the actual data for an object.
____
5. The main() method is placed in the controlling class.
____
6. Machine code is comprised of 1s and 0s.
____
7. Source code files have the extension .class.
____
8. The object-oriented programming approach allows programmers to create modules that can be used over
and over again.
____
9. Java is an object-oriented programming language.
____ 10. The format() method can be used to control the way output is displayed.
____ 11. Statements must end with a period.
____ 12. Programs are created to solve problems.
____ 13. A Java application contains at least one class.
____ 14. Platform-independent applications can only be run on computers with a Windows operating system.
____ 15. Packages are importable.
____ 16. The main() method is automatically executed when a Java application is run.
____ 17. A program containing syntax errors will compile.
____ 18. An interpreter is software that runs each bytecode instruction of a compiled Java program.
____ 19. If a width of 10 is specified in a format string specifier and the argument is 12 characters, a syntax error
will occur.
____ 20. Classes are required to create objects.
____ 21. An application is a type of package.
Multiple Choice
Identify the choice that best completes the statement or answers the question.
____ 22. Compiled Java source code is called
a. bytecode.
b. machine code.
c. source code.
d. compiled code.
____ 23. Which statement declares a package with the name testApplication?
a. import testApplication;
b. package testApplication;
c. public package testApplication;
d. declare testApplication;
____ 24. Which is not a feature of object-oriented languages?
a. encapsulation
c. polymorphism
b. inheritance
d. platform-dependent
____ 25. To display a double quotation mark (") as part of string output,
a. place the double quotation mark within double quotation marks (").
b. place the double quotation mark within a comment.
c. precede the double quotation mark with a single quotation mark (').
d. precede the double quotation mark with a back slash (/).
____ 26. Java was developed by
a. Microsoft.
c. Sun Microsystems.
b. Apple.
d. W3C.
____ 27. Which character is an escape sequence?
a. !
c. \
/
b.
d. *
____ 28. Which method controls the way output is displayed?
a. format()
c. print()
b. main()
d. println()
____ 29. Which is a named set of statements that perform a single, well-defined task?
a. object
c. comment
b. method
d. argument
____ 30. Which indicates a method that will not return a value?
a. static
c. void
package
b.
d. out
____ 31. Which describes the output displayed by the statement:
System.out.format("%-10s %-10s %8s", "Item", "Quantity", "Cost\n");
a. Item and Quantity will be right aligned, Cost will be left aligned.
b. Item and Quantity will be left aligned, Cost will be right aligned.
c. Item, Quantity, and Cost will be right aligned.
d. Item,Quantity, and Cost will be right aligned.
____ 32. Which type of statement is used to make a package accessible to an application?
a. package
c. public
b. import
d. out
____ 33. Which of the following represent correctly-formed comments?
I.
II.
III.
a. I only
b. I and II only
// Happy
/* Sorry /*
/* Wise */
c. I and III only
d. III only
____ 34. Which is a set of guidelines for writing an application?
a. comments
c. algorithm
b. code conventions
d. class
____ 35. Which converts bytecode to machine code?
a. Java Virtual Machine
c. a comment block
b. the interpreter
d. just-in-time compiler
____ 36. What effect does \n have when included in an output string?
a. Output is moved to the next line.
b. A \n is displayed in the output.
c. A tab (8 spaces) is displayed in the output.
d. A N is displayed in the output.
public class MulticulturalGoodbye {
public static void main(String[] args) {
System.out.println("good-bye");
System.out.print("adios\n");
System.out.println("au voire");
}
}
____ 37. MulticulturalGoodbye produces output similar to:
a.
c.
b.
d.
____ 38. Which is a string argument in Multicultural Goodbye?
a. public
c. "good-bye"
b. System.out.print
d. }
____ 39. Which would be the resulting bytecode file name if testApplication.java is compiled?
a. testApplication.cmd
c. testApplication.java
b. testApplication.class
d. testApplication.jit
____ 40. Which is not true about a syntax error?
a. A syntax error will stop the application from compiling.
b. A syntax error is caused by a violation of the rules of Java.
c. A syntax error indicates improper spaces in the code.
d. A syntax error must be corrected and the program recompiled before the program will run.
____ 41. Sets of instructions in program code are called
a. objects.
c. statements.
b. methods.
d. comments.
____ 42. Which method displays output to the screen and then moves the insertion point to the next line?
a. format()
c. print()
b. main()
d. println()
____ 43. Which is a set of steps that tell how to solve a problem?
a. algorithm
c. Java application
b. argument
d. package
____ 44. Which is used to enclose single or multiline comments?
*/
*/
a. /*
c. /**
b. //
//
d. !
!
____ 45. Which statement displays Hello, world! on the screen?
a. System.out.println('Hello, world!');
b. System.out.println("Hello, world!");
c. System.println('Hello, world!');
d. system.println("Hello, world!");
____ 46. Which is another name for package?
a. object
c. method
b. library
d. string
____ 47. Java code typed by a programmer is called
a. bytecode.
c. source code.
b. machine code.
d. compiled code.
____ 48. The main() method is defined as
a. public static void main(string[] args)
b. public static void Main(String[] args)
c. public static void main(String[] args)
d. public static main(String[] args)
____ 49. Which is used for documentation?
*/
*/
a. /*
c. /**
b. //
d. !
____ 50. Which process converts source code to code that the computer understands?
a. running
c. compiling
b. executing
d. interpreting
____ 51. Which occurs in a statement that violates the rules of Java?
a. a logic error
c. a syntax error
b. an output error
d. an argument
____ 52. Which outlines a solution using a mix of English and program code?
a. flow chart
c. pseudocode
b. Java code
d. source code
Extra Credit:
On a blank sheet of paper, Copy the five errors in the following application:
explain why it is an error and write out the correction.
/*
* InternetRules.java
/*
package studentRules
/**
* Displays student rules for accessing the Internet.
*/
public class InternetRules
public static void main(String[] args) {
System.out.println("Internet Rules\n");
System.out.println("1. Use school issued login and password.");
System.out.println("2. Do not download any files.")
system.out.println("3. Do not reveal personal information.");
}
}
Related documents