OCJP Practice Papers - Java Basics
OCJP Practice Papers - Java Basics : Covers all the basic questions
Which of the following method signatures is a valid declaration of an entry point in aJava application?
A. public void main(String[] args)
B. public static void main()
C. private static void start(String[] mydata)
D. public static final void main(String[] mydata)
The following class diagram demonstrates the relationship between Gold and Silver,which extend the Metal class. Assume the attributes are all declared public. Whichstatement about the diagram is not true?
A.The diagram demonstrates platform independence in Java.
B. The diagram demonstrates object-oriented design in Java.
C. The Gold and Silver classes inherit weight and color attributes from the Metalclass.
D. Gold does not inherit the luster attribute.
What is the proper filename extension for a Java bytecode compiled file?
A. .java
B. .bytecode
C. .class
D. .dll
Given that a Date class exists in both the java.util and java.sql packages, what is theresult of compiling the following class?
A. The code does not compile because of lines 1 and 2.
B. The code does not compile because of line 4.
C. The code does not compile because of line 5.
D. The code compiles without issue.
Which of the following is not a facet of traditional object-oriented programminglanguages?
A. Objects are grouped as procedures, separate from the data they act on.
B. An object can take many forms via casting.
C. An object can hold data, referred to as attributes.
D. An object can perform actions, via methods.
Which variables have a scope limited to a method?
A. Interface variables
B. Class variables
C. Instance variables
D. Local variables
Which package is imported into every Java class by default?
A. java.util
B. java.lang
C. system.lang
D. java.system
Which of the following is not a valid code comment in Java?
A. // Add 5 to the result
B. /*** TODO: Fix bug 12312 ***/
C. # Add configuration value
D. /* Read file from system ****/
Which statement about a valid .java file is true?
A. It can only contain one class declaration.
B. It can contain one public class declaration and one public interface definition.
C. It must define at least one public class.
D. It may define at most one public class.
Given the following application, fill in the missing values in the table starting from thetop and going downward.
A. 2, 0, 1
B. 2, 2, 1
C. 1, 0, 1
D. 0, 2, 1
Which statement about import statements is true?
A. The class will not compile if it contains unused import statements.
B. Unused import statements can be removed from the class without causing a classto become unable to be compiled.
C. The class will not compile if a duplicate import statement is present.
D. If a class contains an import statement for a class used in the program that cannotbe found, it can still compile.
What is the result of compiling and executing the following class?
A. It does not compile.
B. It compiles but throws an exception at runtime.
C. It compiles and outputs 5.
D. It compiles and outputs 15.
Which statements about Java are true?
I. The java command can execute .java and .class files.
II. Java is not object oriented.
III. The javac command compiles directly into native machine code.
A. I only
B. III only
C. II and III
D. None are true.
Which of the following lines of code is not allowed as the first line of a Java class file?
A. import widget.*;
B. // Widget Manager
C. package sprockets;
D. int facilityNumber;
Which one of the following statements is true about using packages to organize yourcode in Java?
A. Every class is required to include a package declaration.
B. To create a new package, you need to add a package.init file to the directory.
C. Packages allow you to limit access to classes, methods, or data from classes outsidethe package.
D. It is not possible to restrict access to objects and methods within a package.
Given that the current directory is /user/home, with an application Java file in/user/home/Manager.java that uses the default package, which are the correctcommands to compile and run the application in Java?
A. javac Manager
java Manager
B. javac Manager.java
java Manager
C. javac Manager
java Manager.class
D. javac Manager.java
java Manager.class
Structuring a Java class such that only methods within the class can access itsinstance variables is referred to as _______.
A. platform independence
B. object orientation
C. inheritance
D. encapsulation
What is the output of the following code snippet?
A. 1
B. 55
C. 56
D. It does not compile.
Which of the following is true of a Java bytecode file?
A. It can be run on any computer with a compatible JVM.
B. It can only be executed on the same type of computer that it was created on.
C. It can be easily read and modified in a standard text editor.
D. It requires the corresponding .java that created it to execute.
What is the correct character for terminating a statement in Java?
A. A colon (:)
B. An end-of-line character
C. A tab character
D. A semicolon (;)
What is the result of compiling and executing the following class?
A. The code does not compile due to line 6.
B. The code does not compile due to line 7.
C. 31
D. 61
Given the following class definition, which is the only line that does not contain acompilation error?
A. Line 1
B. Line 2
C. Line 3
D. Line 4
Which of the following features allows a Java class to be run on a wide variety ofcomputers and devices?
A. Encapsulation
B. Object oriented
C. Inheritance
D. Platform independence
Which of the following is not a property of a JVM?
A. It prevents Java bytecode from being easily decoded/decompiled.
B. It supports platform independence.
C. It manages memory for the application.
D. It translates Java instructions to machine instructions.
Which of the following variables are always in scope for the entire program?
A. Package variables
B. Class variables
C. Instance variables
D. Local variables
Given the following wildcard import statements, which class would be included in theimport?
import television.actor.*;
import movie.director.*;
A. television.actor.recurring.Marie
B. movie.directors.John
C. television.actor.Package
D. movie.NewRelease
Which is the correct order of statements for a Java class file?
A. import statements, package statement, class declaration
B. package statement, class declaration, import statement
C. class declaration, import statements, package declaration
D. package statement, import statements, class declaration
Given the following class definition, what is the maximum number of importstatements that can be discarded and still have the code compile? For this question,assume that the Blackhole class is defined only in the stars package.
A. Zero
B. One
C. Two
D. Three
Given the following class definition, which command will cause the application tooutput the message White-tailed?
A. java forest.Deer deer 5 "White-tailed deer"
B. java forest.Deer "White-tailed deer" deer 3
C. java forest.Deer Red deer White-tailed deer
D. java forest.Deer My "deer White-tailed"
Which of the following is a true statement?
A. The java command compiles a .java file into a .class file.
B. The javac command compiles a .java file into a .class file.
C. The java command compiles a .class file into a .java file.
D. The javac command compiles a .class file into a .java file.
Which of the following statements about Java is true?
A. Java is a procedural programming language.
B. Java allows method overloading.
C. Java allows operator overloading.
D. Java allows direct access to objects in memory.
Given the following code, what values inserted in order into the blank lines, allow thecode to compile?
A. import, class, null
B. import, interface, void
C. package, int, int
D. package, class, long
What is the output of the following application?
A. 2 5
B. 8 5
C. 6 5
D. The code does not compile.
What is one of the most important reasons that Java supports extending classes viainheritance?
A. Inheritance requires that a class that extends another class be in the same package.
B. The program must spend extra time/resources at runtime jumping through
multiple layers of inheritance to determine precise methods and variables.
C. Method signature changes in parent classes may break subclasses that use
overloaded methods.
D. Developers minimize duplicate code in new classes by sharing code in a common
parent class.
Which of the following is a valid code comment in Java?
A. //////// Walk my dog
B. #! Go team!
C. / Process fails at runtime /
D. None of the above
Which of the following method signatures is not a valid declaration of an entry pointin a Java application?
A. public static void main(String... arguments)
B. public static void main(String arguments)
C. public static final void main(String[] arguments)
D. public static void main(String[] arguments)
Given the file Magnet.java below, which of the marked lines can you independently insert the line public String color; into and still have the code compile?
A. a1 and a3
B. a2 and a4
C. a2, a3, and a4
D. a1, a2, a3, and a4
What is required to define a valid Java class file?
A. A class declaration
B. A package statement
C. At least one import statement
D. The public modifier
What is the proper filename extension for a Java source file?
A. .jav
B. .class
C. .source
D. .java
Given that a Math class exists in both the java.lang and pocket.complex packages,what is the result of compiling the following class?
A. The code does not compile because of line 2.
B. The code does not compile because of line 3.
C. The code does not compile because of line 6.
D. The code compiles without issue.
Given a class that uses the following import statements, which class would not beautomatically accessible within the class without using its full package name?
A. dog.puppy.female.KC
B. dog.puppy.Georgette
C. dog.Webby
D. java.lang.Object
._______is the technique of structuring programming data as a unit consisting ofattributes, with actions defined on the unit.
A. Encapsulation
B. Object orientation
C. Platform independence
D. Polymorphism
Given the following class definition, what is the maximum number of importstatements that can be discarded and still have the code compile? For this question, assume that the Broccoli class is in the food.vegetables package, and the Apple classis the food.fruit package.
A. 0
B. 1
C. 2
D. 3
Given the following application, what is the expected output?
A. true false
B. false false
C. It does not compile.
D. It compiles but throws an exception at runtime.
What is the result of compiling and executing the following class?
A. The code does not compile.
B. 5
C. 10
D. 20
What is the result of compiling and executing the following class?
A. red
B. purple
C. blue
D. It does not compile.
Which statements about calling the compilation command javac and the execution command java are true?
I. java may use a period . to separate packages.
II. javac takes a .java file and returns a .class file.
III. java may use a slash (/) to separate packages.
A. I only
B. II only
C. I and II
D. I, II, and III
What is the result of compiling and executing the following application?
A. true
B. false
C. It does not compile.
D. It compiles but throws an error at runtime.
Given the following class diagram, which Java implementation most closely matchesthis structure?
A.
B.
C.
D.
Which statement about the JVM is true?
A. The JVM schedules garbage collection on a predictable schedule.
B. The JVM ensures that the application will always terminate.
C. The JVM requires a properly defined entry point method to execute theapplication.
D. A Java compiled code can be run on any computer.
All OCJP Java Certification Tutorials
- Oracle (OCJP) Java Certification Exam
- Java Building Blocks Java 8 Certification
- Operators And Statements
- Java Core API
- Java Class Design
- Java Exception
- Java Try-Catch Block
- Exceptional Handling in Java
- Common Exception in Java
OCJP Practice Test, Certification Path, Tips/Tricks
- Oracle (OCJP) Java Certification Exam
- Java Certification Tips And Tricks
- OCJP Practice Papers - Java Basics
- OCJP Practice Papers - Operators And Decision Constructs
- OCJP Practice Papers-A Advanced Java Class Design
- OCJP Practice Papers Creating And Using Arrays
- OCJP Practice Papers Using Loop Constructs
- OCJP Practice Papers - Generics And Collections
- OCJP Practice Papers - Lambda Built-In Functional Interfaces
- OCJP Practice Papers Java Class Design
- OCJP Practice Papers - Java Stream API
- OCJP Practice Papers - Exceptions And Assertions
- OCJP Practice Papers - Date/Time API
- OCJP Practice Papers - Java I/O Fundamentals
- OCJP Practice Papers - Working With Methods And Encapsulation
- OCJP Practice Papers - Working With Inheritance
- OCJP Practice Papers - Handling Exceptions
- OCJP Practice Papers - Selected Classes From Java API
- OCJP Practice Papers - Java File I/O Nio.2
- OCJP Practice Papers - Java Concurrency