0% found this document useful (0 votes)
24 views10 pages

Midterm Revision

Uploaded by

Michael Saad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views10 pages

Midterm Revision

Uploaded by

Michael Saad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

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 Test.java is?
A. java Test B. java Test.java
C. javac Test.java D. javac Test E. JAVAC Test.java
12- Which JDK command is correct to run a Java application in ByteCode.class?
A. java ByteCode B. java ByteCode.class
C. javac ByteCode.java 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. Test.class B. Test.doc C. Test.txt
D. Test.java 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(System.in);
What method do you use to read an int value?

A. input.nextInt(); B. input.nextInteger();

C. input.int(); D. input.integer();

32- What is the exact output of the following code?

double area = 3.5;


System.out.print("area");
System.out.print(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- Math.pow(2, 3) returns __________.

A. 9 B. 8 C. 9.0 D. 8.0

49- Math.pow(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
System.out.println(++x)?

A. a B. b

C. c D. d

62- Which of the following statement prints smith\exam1\test.txt?

A. System.out.println("smith\exam1\test.txt");

B. System.out.println("smith\\exam1\\test.txt");

C. System.out.println("smith\"exam1\"test.txt");

D. System.out.println("smith"\exam1"\test.txt");

63- Will System.out.println((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 System.currentTimeMillis() 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. integer.parseInt(s); B. Integer.parseInt(s);

C. integer.parseInteger(s); D. Integer.parseInteger(s);

70- The __________ method parses a string s to a double value.

A. double.parseDouble(s); B. Double.parsedouble(s);

C. double.parse(s); D. Double.parseDouble(s);
71- Analyze the following code:
boolean even = false;
if (even = true) {
System.out.println("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();
c.print();
}
}

class ParentClass {
int id = 1;
void print() {
System.out.println(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() {
System.out.print(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

You might also like