

























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


























What year was the Java programming created - ANSWER>> What does OCA stand for - ANSWER>>Oracle Certified Associate What are the 2 tests for Java developers provided by Oracle - ANSWER>>OCA and OCP The part of a method declaration that includes the name and parameter types is called the method ____ - ANSWER>>signature True or False - can you add a multiline comment within a multiline comment?
How many public classes can be added to a single file - ANSWER>> Write the syntax for the main method. - ANSWER>>public static void main(String[] args) When you compile a Java class what file type extension is output? - ANSWER>>.class What does a .class file contain - ANSWER>>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? - ANSWER>>true In a method declaration, the public, protected and private declarations are called what? - ANSWER>>access modifiers What is the one special package in Java that you don't need to import? - ANSWER>>java.lang
When defining a constructor for class Junk, what is the proper syntax? - ANSWER>>public Junk() { } // notice there is NO return value. What is a code block outside of a method called? - ANSWER>>instance initializer Given the class public class Junk { int eggs=0; public Junk() { eggs=1; } { eggs = 10; } } what is the value of eggs and why? - ANSWER>>ANSWER: 1 Reason: The value is 1 because the fields and instance initializers are run in the order they are declared and lastly the constructor is run. In the following code snippet, will this compile? public class Junk { { eggs = 6; } int eggs; }
Why or why not? - ANSWER>>ANSWER: Won't Compile Reason: This will not compile because the instance initializer will try to set a field that hasn't been declared yet. What are the two types of data that Java applications contain? - ANSWER>>primitive type and reference types How many primitive data types does Java have? - ANSWER>>ANSWER: 8 There are 8 primitive data types: boolean, byte, short, int, long, float, double and char. What are the 8 Java primitive types? - ANSWER>>boolean, byte, short, int, long, float, double and char How many bits is an int primitive data type - ANSWER>>32 bits How many bits is a long primitive data type? - ANSWER>>64 bits
int num; - ANSWER>>ANSWER: 32 What is the maximum number an int can hold - ANSWER>>ANSWER: 2,147,483, When declaring a literal number what type does Java assume the data is? - ANSWER>>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>>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>>ANSWER: add 0 prefix Reason: By adding a 0 prefix, you can define an octal number such as 017 which is equal to decimal 15.
How would you define a literal hex value in Java? - ANSWER>>ANSWER: Add a 0x prefix Reason: By adding a 0x prefix, you can define a hex number. For example; 0x1F is 31. In Java 7, what feature was added to make numbers easier to read? - ANSWER>>An underscore option was created. int million = 1_000_000; the underscore cannot be first, before a decimal, after a decimal or at the end, but its OK elsewhere. Is the following statement valid? int value = null; - ANSWER>>ANSWER: No Reason: Primitive types cannot be set to null. As a general rule, all primitives start with:
What is wrong with the following statement? double d1, double d2; - ANSWER>>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? - ANSWER>>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? - ANSWER>>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) {
} else { ANSWER2 = 2; } System.out.println(ANSWER1); System.out.println(ANSWER2); } - ANSWER>>This won't compile because the local variable ANSWER1 is never initialized. How do you identify a class variable? - ANSWER>>It has the keyword static before it. What is the default value for an instance variable of type boolean? - ANSWER>>false What is the default value for an instance variable of type byte, short, int and long? - ANSWER>>
Will an object's finalize() method ever get called twice? - ANSWER>>No 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(); } } - ANSWER>>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); } } - ANSWER>>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? - ANSWER>>1.) single line comment 2.) multi-line comment 3.) JavaDoc comment What are the 6 key benefits to Java? - ANSWER>>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.
f.) 1980_s - ANSWER>>a, b, e c is a Java reserved word d is a Java package e is OK because public is the reserved word, not Public. f cannot start variables with a number What is the output from the following program: public class WaterBottle { private String brand; private boolean empty; public static void main(String[] args) { WaterBottle wb = new WaterBottle(); System.out.println("Empty = " + wb.empty()); System.out.println(", Brand = " + wb.brand(); } } - ANSWER>>Empty = false, Brand = null
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(); - ANSWER>>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 {
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?
class Water
class Water import com.test.aquarium.*; public class Main { public static void main(String[] args) { Water water = new Water(); }
} - ANSWER>>The com.test.aquarium.Water because the * imports the classes under aquarium, but not the other packages. Given the following class in the file /my/directory/named/A/Bird.java: INSERT CODE HERE public class Bird. Which of the following replaces INSERT CODE HERE if we compile from my/directory? Choose all that apply. a.) package my.directory.named.a; b.) package my.directory.named.A; c.) package named.a; d.) package named.A; e.) package a; f.) package A; g.) Does not compile - ANSWER>>d.) package named.A What is an example of a unary operator? - ANSWER>>++ or --