Computer Programming 2 Prelim Reviewer (AMA)
Computer Programming 2 Prelim Reviewer (AMA)
statement? if (boolean_expression)
Overriding is implemented in at least two classes with Which of the following is not a Java Literal? None on the
inheritance relationship. choices
Can we directly compile codes from NetBeans? Literals are constant values assigned to constant
Yes, because we can call Java compiler from variables.
NetBeans
Literals represent fixed values that cannot be modified.
Can we directly compile codes from notepad?
Literals are a synthetic representation of boolean,
No, We can only write codes in Notepad
character, numeric, or string data, a medium of
Declare a two-dimensional integer array named values expressing particular values in the program.
of size 6 columns and 4 rows.
String is not a primitive data type.
int[ ][ ] values=new int[4][6];
Which statement will check if x is less than y?
Declare and initialize a double data type array named
if (x<y);
numbers with the following values: 23.35, 34.45, 56.77.
double[ ] numbers={2335, 3445, 5677}; Since Java uses a virtual machine, what does that mean
about the versatility of Java?
From the array int[] intArray = { 1, 2, 3, 5, 6, 7 };, what is
It can run most anywhere without modification
the value of intArray[2]? 3
The new keyword allocates memory for the array being
From the array int[] intArray = { 1, 2, 3, 5, 6, 7 };, what is
declared.
the value of intArray[3]? 5
Multithreaded, the feature of Java which makes it
How many elements could be assigned to an array
possible to execute several tasks simultaneously.\
location with 5 columns and 3 rows? 15
The Java feature, "write once, run anywhere", is termed
It is a template for creating an object? Class
as Platform independent.
Polymorphism is the ability of an object to have many
The length of an array is established when the array is
forms.
created at runtime.
Encapsulation is the method of hiding certain elements
byte, short, int, and for are one of Java's Primitive data
of the implementation of a certain class.
types. FALSE
It is used to access the instance variables shadowed by
float is one of Java's Primitive data types TRUE
the parameters. this
for, while and do-while is part of Java's Repetition
Accessor is used to read values from class variables.
Control Structures. TRUE
JVM is responsible for Interpreting bytecode.
Java is a simple, object-oriented, portable and robust
What will be the result if you execute this expression computer language. TRUE
x=true ? 1 : 0;? 1
Java is architecture neutral. TRUE
What will be the value of x after you execute this
Java is secured. TRUE
statement int z=0; for(int x=0; x<10; x++) for(int y=0; y<x;
y++) z*=(x*y);? No answer Java SE is a Java Platform. TRUE
Which is not a decision control structure? Among Java's control structures are branching, decision, and
choices none multithreaded. FALSE
The most common decision structures include if-then- Portable is one of Java's control structures. FALSE
else statements, switch statements, and ternary
operators. Repetition is one of Java's control structures. TRUE
A loop is not a repetition control structure. Use the for loop statement when traversing through
arrays.
Which of the following a valid Java identifier?
id_1 What did java generates after compiling the java source
code? Byte Code
What do you call a blueprint of an object?
Class
What is the output of the code snippet below:
What do you call a class that inherits a class?
Subclass void main(){test("11");test("1");}
void test(String x){System.out.print(x + x);}
What do you call a variable that belong to the whole
class? Class Variable ans. 111111
What does Java generate after compiling the java What is the output of the code snippet below:
source code? Byte Code
int[] intArray = { 1, 2, 3, 5, 6, 7 };
What is floating-point literal? for(int x = intArray.length-1; x>=0; x--)
• Can be express in scientific notation {System.out.print(intArray[x]);}
• An integer literal with decimal point
• By default it is double type ans. 765321
• It could be double or float value
What is the output of the code snippet below: void main()
What is the correct statement to compile Java program {test();test();} void test(){System.out.print(“1”);} ?
in command line? javac HelloWorldjava 11
What is the correct statement to run Java program in What is the output of the code snippet below:
command line? java HelloWorld
void main(){test(1.0); test(1);} void test(double x)
What is the correct statement to set javac path in { System.out.print(x); } void test(int x)
command line? { System.out.print(x);}
path=C:\Program Files\Java\jdk160_23\bin
What is the extension name of a Java Source code? ans. 101 / 1.01
java What is the result if we execute this: "a" instanceof
What is the index number of the last element of an array String; ? true
with 20 elements? 19 What is the result if we execute this: "a".equals("a");?
What is the index number of the last element of an array true
with 30 elements? 29 What is the result if we execute this: “a” instanceof
What is the input for Java Compiler? Source Code String; ? true
What is the length of the array: int[] intArray = { 1, 2, 3, 5, What is the result if we execute this: “a”.equals(“a”);?
6, 7 }; 6 true
What is the maximum index of the array: int[] intArray = { What is the return type of this method: int test(){return 1;}
1, 2, 3, 5, 6, 7 }; 5 ? int
What is the name of this method: int test(){return 1;} ? What is the return value of this method: int test(){return
test 1;} ? 1
What is the output of the code snippet below: What is the return value of this method: public void
sum(){int x=1;} ? void
int[] intArray = { 1, 2, 3, 5, 6, 7 }; What keyword is used to perform class inheritance?
for(int x = intArray.length-1; x>=0; x--) extends
{System.out.print(intArray[x]);}
What type of value does the nextLine() returns?
ans. 765321 String
What is the output of the code snippet below: What was the initial name for the Java programming
language? Oak
int[] intArray = new int[10];
for(int x = 0; x<intArray.length; x++) What will be the output if you execute this code: int a[] =
{System.out.print(intArray[x]);} new int[1]; System.out.println(a[1]);
It will produce an exception.
Ans. 0000000000
What will be the output if you execute this code? What will happen if you use JOptionPane.
do{System.out.println("Hello World!");}while(false); showInputDialog statement in your program?
print "Hello World" The program will display an input dialog box that
allows the user to input text and returns String value
What will be the output if you execute this code?
do{System.out.println("Hello World!");}while(true); What will happen if you use
print "Hello World" infinitely JOptionPane.showMessageDialog statement in your
program?
what will be the output if you execute this code? The program will display message dialog box
int x=1; switch(x){ case 1: System.out.print(“1”); case 2:
System.out.print(“1”); case 3: System.out.print(“1”); When was the officially released of Java?
default: System.out.print(“1”); } 1995
display 1111
Which is not a decision control structure? No answer
what will be the output if you execute this code?
int x=2; switch(x){ case 1: System.out.print(“1”); case 2: Which is not a repetition control structure?
System.out.print(“1”); case 3: System.out.print(“1”); switch
default: System.out.print(“1”); } Which of the following a valid Java identifier? All choices
display 111
Which of the following array declarations is correct?
What will be the output if you execute this code? double[ ] grades;grades = new double[2];
do{System.out.println("Hello World!");}while(false);
print "Hello World" Which of the following class declaration is not allowed to
be inherited? public final class Person {}
What will be the output if you execute this code?
do{System.out.println("Hello World!");}while(true); Which of the following class declaration is not allowed to
print "Hello World" infinitely be instantiated? public abstract class Person {}
what will be the output if you execute this code? Which of the following correctly accesses the sixth
int x=1;switch(x){case 1: element stored in an array of 10 elements?
System.out.print("1");case 2: stringArray[5];
System.out.print("1");case 3:
Which of the following creates an instance of a class?
System.out.print("1");default:
all choices
System.out.print("1");}
display 1111 Which of the following declares an array of int named
intArray? All choices
What will be the value of x after executing this code
for(int x=0; x<=10; x++) {} is run? 11 Which of the following does not return numeric value?
no choices
What will be the value of x after executing this code
for(int x=0; x<=11; x++) {} is run? 12 Which of the following has the correct form for an if
statement? if (boolean_expression)
What will be the value of x after you execute this
statement int z=0; for(int x=0; x no answer Which of the following is a correct declaration of an
array? EmployeeRecord[ ][ ] er=new
What will be the value of x after you execute this
EmployeeRecord[10][10];
statement int z=0; for(int x=0; x<10; x++) for(int y=0; y<x;
y++) z*=(x*y); no answer Which of the following is a jump statement in java?
break
What will be the value of x after you execute this
statementint z=0; for(int x=0; x<10; x++) for(int y=0; y<x; Which of the following is a valid editor for java source
y++) z*=(x*y); no answer code? All choices
What will be the value of x if we execute this: String s = Which of the following is a valid identifier?
"25"; int x = Integer.parseInt(s); ? int 25 name
What will happen if we compile the statement below? Which of the following is a valid method name:
~System.out.println(“Hello World!”) compute
There will be a syntax error after compilation.
Which of the following is a valid multidimensional array?
all of the choices
Which of the following is a valid nexDouble() return Which of the following method is allowed to be
value? All of the choices overriden? public final void setName(){}
Which of the following is a valid nextByte() return value? Which of the following method reads input from the user
3 and return String val ue? nextLine()
Which of the following is a valid nextInt() return value? Which of the following methods is allowed to be
1010 overriden? public void setName(){}
Which of the following is a valid statement to accept int Which of the following scenarios where an exception
input? Let us assume that we have declared scan as may occur? All of the choices
Scanner. No choices
Which of the following shows a valid Overloading
Which of the following is a valid statement to accept method?
String input? void test(char x, int y){} void test(int x, char y){}
String str = JOptionPaneshowInputDialog("");
Which of the following shows Overloading method?
Which of the following is not a Java comment? void test(int x){} void test(double x){}
Declaration Comments
Which of the following we are not allowed to write java
Which of the following is not a java keyword? source code? None of the choices
name
Which of the following we are not allowed to write java
Which of the following is not a primitive data type? source code? None of the choices
String
Which of the following will do implicit cast?
Which of the following is not a valid Float value? short x=1; int y = x;
none of the choices
Which statement will check if x is less than y?
Which of the following is not a valid variable declaration if (x<y);
in Java? float x = 20D;
Why do we need to set the path for javac in command
Which of the following is not an escape sequence? line? To make javac available or accessible in
no choices command line