1- Computer can execute the code in ____________?
A. machine language B. assembly language
C. high-level language D. none of the above
2- ___________ translates high-level language program into machine language program?
A. An assembler B. A compiler
C. CPU D. The operating system
3- Java was developed by ____________?
A. Sun Microsystems B. Microsoft C. Oracle D. IBM
4- Java ___________ can run from a Web browser?
A. applications B. applets
C. servlets D. Micro Edition programs
5- ________ is interpreted?
A. Java B. C++ C. C D. Ada
7- ________ consists of a set of separate programs for developing and testing Java programs,
each of which is invoked from a command line?
A. Java language specification B. Java API C. Java JDK D. Java IDE
8- ________ provides an integrated development environment for rapidly developing Java
programs. Editing, compiling, building, debugging, and online help are integrated in one
graphical user interface?
A. Java language specification B. Java API C. Java JDK D. Java IDE
9- The main method header is written 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)
E. public void main(String[] args)
10- Which of the following statements is correct?
A. Every line in a program must end with a semicolon.
B. Every statement in a program must end with a semicolon.
C. Every comment line must end with a semicolon.
D. Every method must end with a semicolon.
E. Every class must end with a semicolon.
11- The JDK command to compile a class in the file [Link] is?
A. java Test B. java [Link]
C. javac [Link] D. javac Test E. JAVAC [Link]
12- Which JDK command is correct to run a Java application in [Link]?
A. java ByteCode B. java [Link]
C. javac [Link] D. javacByteCode E. JAVAC ByteCode
13- Java compiler translates Java source code into _________?
A. Java bytecode B. machine code
C. assembly code D. another high-level language code
14- Suppose you define a Java class as follows:
public class Test {
}
In order to compile this program, the source code should be stored in a file named?
A. [Link] B. [Link] C. [Link]
D. [Link] E. Any name with extension .java
15- The extension name of a Java bytecode file is?
A. .java B. .obj
C. .class D. .exe
16- The extension name of a Java source code file is?
A. .java B. .obj
C. .class D. .exe
17- Which of the following lines is not a Java comment?
A. /** comments */ B. // comments
C. -- comments D. /* comments */
18- Which of the following are the reserved words?
A. public B. static C. void D. class
19- Every statement in Java ends with ________?
A. a semicolon (;) B. a comma (,)
C. a period (.) D. an asterisk (*)
20- If a program compiles fine, but it produces incorrect result, then the program suffers
______?
A. a compilation error B. a runtime error C. a logic error
21- If you forget to put a closing quotation mark on a string, what kind error will be raised?
A. a compilation error B. a runtime error C. a logic error
22- Suppose a Scanner object is created as follows:
Scanner input = new Scanner([Link]);
What method do you use to read an int value?
A. [Link](); B. [Link]();
C. [Link](); D. [Link]();
32- What is the exact output of the following code?
double area = 3.5;
[Link]("area");
[Link](area);
A. 3.53.5 B. 3.5 3.5
C. area3.5 D. area 3.5
34- Which of the following is a valid identifier?
A. $343 B. class
C. 9X E. radius
35- Which of the following are correct names for variables according to Java naming
conventions?
A. radius B. Radius
C. RADIUS D. findArea
36- Which of the following are correct ways to declare variables?
A. int length; int width; B. int length, width;
C. int length; width; D. int length, int width;
37- To assign a value 1 to variable x, you write
A. 1 = x; B. x = 1;
C. x := 1; D. 1 := x;
38- To declare a constant MAX_LENGTH inside a method with value 99.98, you write
A. final MAX_LENGTH = 99.98; B. double MAX_LENGTH = 99.98;
C. final double MAX_LENGTH = 99.98;
39- Which of the following is a constant, according to Java naming conventions?
A. MAX_VALUE B. Test
C. read D. ReadInt
E. COUNT
40- According to Java naming convention, which of the following names can be variables?
A. FindArea B. findArea
C. totalLength D. TOTAL_LENGTH
E. class
41- Which of these data types requires the most amount of memory?
A. long B. int
C. short D. byte
42- What is the result of (45 / 4)?
A. 10 B. 11
C. 11.25 D. 12
43- (25 % 1) is _____
A. 1 B. 2
C. 4 D. 0
44- (-25 % 5 is) _____
A. 1 B. 2
C. 4 D. 0
45- (24 % 5) is _____
A. 1 B. 2
C. 3 D. 4
46- (-24 % 5) is _____
A. -1 B. -2 C. -3 D. -4
47- (-24 % -5) is _____
A. 3 B. -3 C. 4 D. -4
48- [Link](2, 3) returns __________.
A. 9 B. 8 C. 9.0 D. 8.0
49- [Link](4, 1 / 2) returns __________.
A. 2 B. 2.0
C. 0 D. 1.0
50- The expression 4 + 20 / (3 - 1) * 2 is evaluated to
A. 4 B. 20
C. 24 D. 9
51- To add a value 1 to variable x, you write
A. 1 + x = x; B. x += 1;
C. x := 1; D. x = x + 1;
E. x = 1 + x;
52- To add number to sum, you write
A. number += sum; B. number = sum + number;
C. sum = Number + sum; D. sum += number;
E. sum = sum + number;
53- Suppose x is 1. What is x after x += 2?
A. 0 B. 1
C. 2 D. 3
54- Suppose x is 1. What is x after x -= 1?
A. 0 B. 1
C. 2 D. -1
55- Are the following four statements equivalent?
number += 1;
number = number + 1;
number++;
++number;
A. Yes B. No
57- Which of the following expressions will yield 0.5?
A. 1 / 2 B. 1.0 / 2
C. (double) (1 / 2) D. (double) 1 / 2
E. 1 / 2.0
58- What is the value of (double)(5/2)?
A. 2 B. 2.5
C. 3 D. 2.0
59- If you attempt to add an int, a byte, a long, and a double, the result will be a __________
value.
A. byte B. int
C. long D. double
60- Which of the following is the correct expression of character 4?
A. 4 B. "4"
C. '\0004' D. '4'
61- Suppose x is a char variable with a value 'b'. What will be displayed by the statement
[Link](++x)?
A. a B. b
C. c D. d
62- Which of the following statement prints smith\exam1\[Link]?
A. [Link]("smith\exam1\[Link]");
B. [Link]("smith\\exam1\\[Link]");
C. [Link]("smith\"exam1\"[Link]");
D. [Link]("smith"\exam1"\[Link]");
63- Will [Link]((char)4) display 4?
A. Yes B. No
65- (’3’ - '2' + 'm' / 'n') is ______.
A. 0 B. 1
C. 2 D. 3
66- The expression "Java " + 1 + 2 + 3 evaluates to ________.
A. Java123 B. Java6
C. Java 123 D. java 123
E. Illegal expression
67- Note that the Unicode for character A is 65. The expression 'A' + 1 evaluates to ________.
A. 66 B. B
C. A1 D. Illegal expression
68- The [Link]() returns ________________ .
A. the current time.
B. the current time in milliseconds.
C. the current time in milliseconds since midnight.
D. the current time in milliseconds since midnight, January 1, 1970.
E. the current time in milliseconds since midnight, January 1, 1970 GMT (the Unix time).
69- The __________ method parses a string s to an int value.
A. [Link](s); B. [Link](s);
C. [Link](s); D. [Link](s);
70- The __________ method parses a string s to a double value.
A. [Link](s); B. [Link](s);
C. [Link](s); D. [Link](s);
71- Analyze the following code:
boolean even = false;
if (even = true) {
[Link]("It is even!");
}
A. The program has a compile error.
B. The program has a runtime error.
C. The program runs, but displays nothing.
D. The program runs and displays It is even!.
72- Object-oriented programming allows you to derive new classes from existing classes. This is
called ____________.
A. encapsulation B. inheritance
C. abstraction D. generalization
73- What is the output of the following code?
public class Test1 {
public static void main(String[] args) {
ChildClass c = new ChildClass();
[Link]();
}
}
class ParentClass {
int id = 1;
void print() {
[Link](id);
}
}
class ChildClass extends ParentClass {
int id = 2;
}
A. 0 B. 1
C. 2 D. Nothing
74- What is the output of the following code?
public class Test {
public static void main(String[] args) {
new Person().printPerson();
new Student().printPerson();
}
}
class Student extends Person {
public String getInfo() {
return "Student";
}
}
class Person {
public String getInfo() {
return "Person ";
}
public void printPerson() {
[Link](getInfo());
}
}
A. Person Person B. Person Student
C. Student Student D. Student Person
77- Which of the following classes cannot be extended?
A. class A { } B. abstract class A { }
C. final class A { } D. class A { protected A();}
78- Polymorphism means ______________.
A. that data fields should be declared private.
B. that a class can extend another class.
C. that a variable of supertype can refer to a subtype object.
D. that a class can contain another class.
79- Encapsulation means ______________.
A. that data fields should be declared private.
B. that a class can extend another class.
C. that a variable of supertype can refer to a subtype object.
D. that a class can contain another class.
80- Inheritance means ______________.
A. that data fields should be declared private.
B. that a class can extend another class.
C. that a variable of supertype can refer to a subtype object.
D. that a class can contain another class.
81- Suppose your method does not return any value, which of the following keywords can be
used as a return type?
A. void B. int
C. double D. public
E. None of the above
82- What is the representation of the third element in an array called a?
A. a[2] B. a(2)
C. a[3] D. a(3)
83- The JVM stores the array in an area of memory, called _______, which is used for dynamic
memory allocation where blocks of memory are allocated and freed in an arbitrary order.
A. stack B. heap
C. memory block D. dynamic memory