


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive set of questions and answers covering key concepts in java 8 programming, specifically designed for the oracle certified associate java se 8 programmer 1 exam. it's a valuable resource for students and professionals preparing for the certification, offering detailed explanations and covering topics such as data types, variables, methods, and object-oriented programming principles. The questions are well-structured and the answers are thorough, making it an excellent study aid.
Typology: Exams
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















What year was the Java programming created - 1995 What does OCA stand for - Oracle Certified Associate What are the 2 tests for Java developers provided by Oracle - OCA and OCP The full declaration of a method is called the method ____ - signature True or False - can you add a multiline comment within a multiline comment? - false How many public classes can be added to a single file - 1 Write the syntax for the main method. - public static void main(String[] args) When you compile a Java class what file type extension is output? - .class What does a .class file contain - bytecode True or false, what creating a public Java class in a file does the case used in the file name have to match the case used by the Java class name? - true In a method declaration, the public, protected and private declarations are called what? - access modifiers
What is the one special package in Java that you don't need to import? - java.lang What is the generic term for packages that are defined after the com.company package? - child packages When creating an array, which one of these definitions is correct? 1.) String[] args, 2.) String args[], 3.) String... args, 4.) all of the above - 4 All of the above What package does the Files and Paths object belong to? - java.nio.file What 2 common packages contain the Date class - java.util.Date and java.sql.Date If a class wanted to use the java.util.Date class, but the class had imports for java.util.* and java.sql.* which both contain the Date class how would you fix this?
How many primitive data types does Java have? - Answer: 8 There are 8 primitive data types: boolean, byte, short, int, long, float, double and char. What are the 8 Java primitive types? - boolean, byte, short, int, long, float, double and char How many bits is an int primitive data type - 32 bits How many bits is a long primitive data type? - 64 bits Which of these floating point data types is bigger? float or double? - Answer: double Reason: A double type is larger because it is 64 bits and float is only 32. How many bits is the char primitive type? - Answer: 16 bits How many bits is a byte primitive data type - Answer: 8 bits How many bits is a short data type? - Answer: 16 bits
When setting a float data type, what is the correct syntax? - Answer: float myfloat = 123.456f Reason: You have to remember to add the trailing "f". What is the range of data a Java byte can hold - Answer: -128 to 127 How many bits are used with the statement: int num; - Answer: 32 What is the maximum number an int can hold - Answer: 2,147,483, When declaring a literal number what type does Java assume the data is? - Answer: int Reason: Java assumes the data is an int. If you want a really big number you have to add an "L" to the end to get a long. How would you define a literal binary number in Java? - Answer: add the 0b prefix Reason: By adding 0b you can then add the binary values such as 0b How would you define a literal octal number in Java? - Answer: add 0 prefix
That's just the way it is. When declaring multiple variables on the same line what is the rule? - You can declare as many as you want, but they have to be of the same type and separated by commas. String s1="hello", s2="world; How many variables are declared and initialized in the following snippet? int i1, i2, i3=0; - 3 are declared, 1 is initialized. What is wrong with the following statement? int num, String value; - This will not compile because you can't declare different variable types. What is wrong with the following statement? double d1, double d2; - Java does not allow 2 types of variables to be declared even if they are of the same type on the same line. What are the 3 rules for identifier naming? - 1.) must begin with a letter or a $ or _ 2.) subsequent characters may also be numbers. 3.) cannot use Java reserved words.
When declaring a local variable, what is the default value? - Local variables do not have a default value and contain garage until initialized. You cannot use a local variable in a method until it is initialized. What is wrong with the following code snippet? public void test(boolean check) { int answer1; int answer2; if (check) { answer1 = 1; answer2 = 2; } else { answer2 = 2; } System.out.println(answer1); System.out.println(answer2); } - This won't compile because the local variable answer1 is never initialized. How do you identify a class variable? - It has the keyword static before it. What is the default value for an instance variable of type boolean? - false
What does the following code output: public class Finalizer { protected void finalize() { System.out.println("calling finalize"); } public static void main(String[] args) { Finalize f = new Finalizer(); } } - It won't output anything because the program exits before there is any need to run the garbage collector. For the exam, it is good to know that this finalize() method will run 0 or one time. In the following snippet, what happens when the garbage collector run finalize()? public class Finalizer { private static List objects = new ArrayList(); protected void finalize() { objects.add(this); } } - The garbage collection of this object is aborted. Later, if the object becomes eligible, the finalize() method will not be called a second time. What are the 3 styles of comments? - 1.) single line comment
2.) multi-line comment 3.) JavaDoc comment What are the 6 key benefits to Java? - OO, E, PI, R, S, S 1.) object oriented 2.) encapsulation through access modifiers to protect data from unintended access. 3.) platform independent 4.) robust - no memory leaks. 5.) simple - no pointers, no operator overloading 6.) secure - runs in a JVM What does the following program print? public class Test { public static void main(String[] args) { System.out.println(args[0]); } } java Test hello - hello
You might think that the private access modifier for brand and empty would cause a compiler error, but it doesn't because main() is considered part of the class. Which of the following are OK? a.) short numPets = 5; b.) int numGrains = 5.6; c.) String name = "Scruffy"; d.) numPets.length(); e.) numGrains.length(); f.) name.length(); - a is OK b is not because 5.6 is a float c is OK d is not because numPets is not an object e is not because numGrains is not an object f is OK because name is an object Given the following class, which of the following is true? 01: public class Snake { 02: 03: public void shed(boolean time) { 04:
05: if (time) { 06: 07: } 08: System.out.println(result); 09: 10: } 11: } a.) if String result = "done"; is added to line 2, the code will compile b.) if String result = "done;"; is added on line 4, the code will compile c.) if String result = "done"; is added to line 6, the code will compile d.) if String result = "done"; is added to line 9, the code will compile e.) None of the above changes will make the code compile. - a is OK b is OK c won't work because result will be out of scope d won't work because it is too late e is obviously not the answer Given the following package structure, which Water class will be used? <com.test.aquarium> class Water
c.) package named.a; d.) package named.A; e.) package a; f.) package A; g.) Does not compile - d.) package named.A What is an example of a unary operator? - ++ or -- What is the result: System.out.println( 10 / 3); - 3 What is the result System.out.println(10 % 3) - 1 In numeric promotion what happens when two values have different data types? - Java will automatically promote the one of the values to the larger of the two data types. In numeric promotion, what happens when one value is an integral value and the other is a floating-point? - Java will promote the integral value to the floating values data type
In numeric promotion, what happens when a byte, short or char are used? - They are promoted to int before being used in the calculation In numeric promotion, what is the resulting data type - It will be the same data type as the promoted operand What is the data type returned from the following expression? int x = 1; long y = 33; ? = x * y -? will be a long data type because of numeric promotion What is the data type returned from the following expression? double x = 39.21; float y = 2.1; ? = x * y - Trick question - this fails to compile because a floating-point literal is assume to be double and since: float y = 2.1; is attempting to assign the double 2.1 to a float, it fails compilation. What is the data type returned from the following expression?
What does the following code do? int x = !5; - does not compile because the logical compliment operator cannot be applied to an integer. What does the following code do? boolean y = -true; - Fails to compile because you can't set a boolean to negative What does the following code do? boolean z = !0; - Fails to compile because 0 is an integer and the logical compliment operator can only be applied to a boolean. What does the following code output? int x = 1; System.out.println(x++); - 1 because the ++ is applied after the value is returned What does the following code output? int x = 1; System.out.println(++x); - 2 because the ++ is applied before the value is returned.
What is y? int x = 3; int y = ++x * 5 / x-- + --x; - y is 7 as follows: ++x * 5 / x-- + --x ++3 * 5 / x-- + --x 4 * 5 / 4 + 2 20 / 4 + 2 = 7 What creating a JavaDoc statement. How do you define the description of method arguments? - Answer: @param argName