Explore topic-wise MCQs in Java Programming.

This section includes 52 Mcqs, each offering curated multiple-choice questions to sharpen your Java Programming knowledge and support exam preparation. Choose a topic below to get started.

1.

Four bits are used for packed sequences numbering is a sliding window protocol used in a computer network. What is the maximum window size?

A. 4
B. 8
C. 15
D. 16
Answer» D. 16
2.

A and B are two stations on a Ethernet. Each has a steady queue of frames to send. Both A and B attempts to retransmit after a frame collide and A wins the first back off race. At the end of this successful transmission by A, both A and B attempt to transmit and collide. The probability that A wins the second back off race is

A. 0.5
B. 0.625
C. 0.75
D. 1
Answer» C. 0.75
3.

A IP packet has arrived in which the fragmentation offset value is 100, the value of HLEN is 5 and the value of total length field is 200. What is the number of the last byte ?

A. 194
B. 394
C. 979
D. 1179
Answer» D. 1179
4.

A network using CSMA / CD has a bandwidth 10 Mbps. If the maximum propagation time (including delays in the devices and ignoring the time needed to send a jamming signal) is 25.6 micro seconds. What is the minimum size of the frame?

A. 512 bytes
B. 1024 bytes
C. 64 bytes
D. 32 bytes
Answer» D. 32 bytes
5.

Assume that a 12-bit Hamming codeword consisting of 8-bit data and 4 check bits is d8d7d6d5c8d4d3d2c4d1c2c1, where the data bits and the check bits are given in the following tables:Data bitsd8d7d6d5d4d3d2d1110x0101 c8c4c2c1Y010Which one of the following choices gives the correct values of x and y?

A. x is 1 and y is 0.
B. x is 1 and y is 1.
C. x is 0 and y is 1.
D. x is 0 and y is 0.
Answer» E.
6.

In CRC calculation if divisor is 1011, and dataword is 1001 what will be the CRC?

A. 111
B. 101
C. 110
D. 100
Answer» D. 100
7.

Bit stuffing refers to

A. Inserting a ‘0’ in user data stream to differentiate it with a flag
B. Inserting a ‘0’ in flag stream to avoid ambiguity
C. Appending a nibble to the flag sequence
D. Appending a nibble to the user data stream
Answer» B. Inserting a ‘0’ in flag stream to avoid ambiguity
8.

In an Ethernet local area network, which one of the following statements is TRUE?

A. A station stops to sense the channel once it starts transmitting a frame.
B. The purpose of the jamming signal is to pad the frames that are smaller than the minimum frame size.
C. A station continues to transmit the packet even after the collision is detected.
D. The exponential back-off mechanism reduces the probability of collision on retransmissions.
Answer» E.
9.

Maximum channel utilization in case of pure ALOHA is:

A. 39%
B. 18%
C. 27%
D. 54%
Answer» C. 27%
10.

Maximum throughput of slotted ALOHA network is:

A. 50%
B. 35.8%
C. 36.8%
D. 18.4%
Answer» D. 18.4%
11.

A computer network uses polynomials over GF (2) for error checking with 8 bits as information bits and uses x3 +x +1 as the generator polynomial to generate the check bits. In this network. The message 01011011 is transmitted as

A. 01011011010
B. 01011011011
C. 01011011101
D. 01011011100
Answer» D. 01011011100
12.

Consider the cyclic redundancy check (CRC) based error detecting scheme having the generator polynomial X3 + X + 1. Suppose the message m4m3m2m1m0 = 11000 is to be transmitted. Check bits c2c1c0 are appended at the end of the message by the transmitter using the above CRC scheme. The transmitted bit string is denoted by m4m3m2m1m0c2c1c0. The value of the check bit sequence c2c1c0 is

A. 101
B. 100
C. 111
D. 110
Answer» C. 111
13.

Consider a binary code that consists of only four valid code wards as given below:00000, 01011, 10101, 11110Let the minimum Hamming distance of the code be p and the maximum number of erroneous bits that can be corrected by the code be q. Then the values of p and q are

A. p = 3 and q = 1
B. p = 3 and q = 2
C. p = 4 and q = 1
D. p = 4 and q = 2
Answer» B. p = 3 and q = 2
14.

What will be the result?1.int i = 10;2.while(i++ <= 10){3.i++;4.}5.System.out.print(i);

A. 0
B. 1
C. 2
D. 3
E. ine 5 will be never reached.
Answer» E. ine 5 will be never reached.
15.

1. public class Test{2.public static void main(String [] args){3.int x = 0;4.// insert code here5.do{ } while(x++ < y);6.System.out.println(x);7.}8. }Which option, inserted at line 4, produces the output 12?

A. nt y = x;
B. nt y = 10;
C. nt y = 11;
D. nt y = 12;
E. one of the above will allow compilation to succeed.
Answer» D. nt y = 12;
16.

What will be the result of compiling and runnig the following code:public class Test{public static void main(String... args) throws Exception{Integer i = 34;int l = 34;if(i.equals(l)){System.out.println("true");}else{System.out.println("false");}}}

A. rue
B. alse
C. ompiler error
D. one of these
Answer» B. alse
17.

What will be the result of the following code?public class Test{static public void main(String args[]){ //line 2int i, j;for(i=0; i<3; i++){for(j=1; j<4; j++){i%=j;System.out.println(j);}}}}

A. 2 3 1
B. 2 3 2
C. epeatedly print 1 2 3 and cause infinite loop.
D. ompilation fails because of line 2
E. one of these
Answer» D. ompilation fails because of line 2
18.

Determine output:public class Test{public static void main(String args[]){int i, j;for(i=1, j=0;i<10;i++) j += i;System.out.println(i);}}

A. 0
B. 1
C.
D. 0
Answer» B. 1
19.

Consider the following program written in Java.class Test{public static void main(String args[]){int x=7;if(x==2); // Note the semicolonSystem.out.println("NumberSeven");System.out.println("NotSeven");}}What would the output of the program be?

A. umberSeven NotSeven
B. umberSeven
C. otSeven
D. rror
Answer» B. umberSeven
20.

What will be the output of the following program?public class Test{public static void main(String args[]){int i = 0, j = 5 ;for( ; (i < 3) && (j++ < 10) ; i++ ){System.out.print(" " + i + " " + j );}System.out.print(" " + i + " " + j );}}

A. 6 1 7 2 8 3 8
B. 6 1 7 2 8 3 9
C. 6 1 5 2 5 3 5
D. ompilation Error
Answer» B. 6 1 7 2 8 3 9
21.

Choose the correct statement in context of the following program code.public class Test{public static void main(String[] args){double sum = 0;for(double d = 0; d < 10;){d += 0.1;sum += sum + d;}}}

A. he program has a compile error because the adjustment is missing in the for loop.
B. he program has a compile error because the control variable in the for loop cannot be of the double type.
C. he program runs in an infinite loop because d<10 would always be true.
D. he program compiles and runs fine.
Answer» E.
22.

What is the printout of the following switch statement?char ch = 'a';switch (ch){case 'a':case 'A': System.out.print(ch); break;case 'b':case 'B': System.out.print(ch); break;case 'c':case 'C': System.out.print(ch); break;case 'd':case 'D': System.out.print(ch);}

A. bcd
B. a
C.
D. b
Answer» D. b
23.

What will be the output?public class Test{public static void main(String[] args){int x=10, y=0;if(x && y){System.out.print("TRUE");}else{System.out.print("FALSE");}}}

A. ALSE
B. RUE
C. ompilation Error
D. untime Error
Answer» D. untime Error
24.

Frames of 1000 bits are sent over a 106 bps duplex link between two hosts. The propagation time is 25 ms. Frames are to be transmitted into this link to maximally pack them in transit (within the link).What is the minimum number of bits (i) that will be required to represent the sequence numbers distinctly? Assume that no time gap needs to be given between the transmission of two frames.

A. i = 2
B. i = 3
C. i = 4
D. i = 5
Answer» E.
25.

In a token ring network, the transmission speed is 107 bps and the propagation speed is 200 m/μs. Then 1 bit delay in this network is equivalent to

A. 500 m of cable
B. 200 m of cable
C. 20 m of cable
D. 50 in of cable
Answer» D. 50 in of cable
26.

Consider a code with only four valid code words: 0000000000, 0000011111, 1111100000, and 1111111111. This code has distance 5. If the code word arrived is 0000000111 then the original code word must be ______.

A. 0000011111
B. 0000000000
C. 1111100000
D. 1111111111
Answer» B. 0000000000
27.

Calculate the link utilization (Efficiency) for stop and wait flow control mechanism if the frame size is 4800 bits, bit rate is 9600 bps, and distance between the devices is 2000 km. Given propagation speed is 200000 km/s.

A. 0.86
B. 0.82
C. 0.92
D. 0.96
Answer» E.
28.

What will be the output of the program? public class Delta { static boolean foo(char c) { System.out.print(c); return true; } public static void main( String[] argv ) { int i = 0; for (foo('A'); foo('B') && (i < 2); foo('C')) { i++; foo('D'); } } }

A. ABDCBDCB
B. ABCDABCD
C. Compilation fails.
D. An exception is thrown at runtime.
Answer» B. ABCDABCD
29.

What will be the output of the program? boolean bool = true; if(bool = false) /* Line 2 */ { System.out.println("a"); } else if(bool) /* Line 6 */ { System.out.println("b"); } else if(!bool) /* Line 10 */ { System.out.println("c"); /* Line 12 */ } else { System.out.println("d"); }

A. a
B. b
C. c
D. d
Answer» D. d
30.

What will be the output of the program? public class If1 { static boolean b; public static void main(String [] args) { short hand = 42; if ( hand < 50 && !b ) /* Line 7 */ hand++; if ( hand > 50 ); /* Line 9 */ else if ( hand > 40 ) { hand += 7; hand++; } else --hand; System.out.println(hand); } }

A. 41
B. 42
C. 50
D. 51
Answer» E.
31.

What will be the output of the program? int I = 0; outer: while (true) { I++; inner: for (int j = 0; j < 10; j++) { I += j; if (j == 3) continue inner; break outer; } continue outer; } System.out.println(I);

A. 1
B. 2
C. 3
D. 4
Answer» B. 2
32.

What will be the output of the program? int x = 3; int y = 1; if (x = y) /* Line 3 */ { System.out.println("x =" + x); }

A. x = 1
B. x = 3
C. Compilation fails.
D. The code runs with no output.
Answer» D. The code runs with no output.
33.

What will be the output of the program? int i = 0, j = 5; tp: for (;;) { i++; for (;;) { if(i > --j) { break tp; } } System.out.println("i =" + i + ", j = " + j);

A. i = 1, j = 0
B. i = 1, j = 4
C. i = 3, j = 4
D. Compilation fails.
Answer» E.
34.

What will be the output of the program? public class Test { public static void main(String [] args) { int I = 1; do while ( I < 1 ) System.out.print("I is " + I); while ( I > 1 ) ; } }

A. I is 1
B. I is 1 I is 1
C. No output is produced.
D. Compilation error
Answer» D. Compilation error
35.

What will be the output of the program? Float f = new Float("12"); switch (f) { case 12: System.out.println("Twelve"); case 0: System.out.println("Zero"); default: System.out.println("Default"); }

A. Zero
B. Twelve
C. Default
D. Compilation fails
Answer» E.
36.

What will be the output of the program? int x = l, y = 6; while (y--) { x++; } System.out.println("x = " + x +" y = " + y);

A. x = 6 y = 0
B. x = 7 y = 0
C. x = 6 y = -1
D. Compilation fails.
Answer» E.
37.

What will be the output of the program? int i = 0; while(1) { if(i == 4) { break; } ++i; } System.out.println("i = " + i);

A. i = 0
B. i = 3
C. i = 4
D. Compilation fails.
Answer» E.
38.

What will be the output of the program? public class Test { public static void main(String args[]) { int i = 1, j = 0; switch(i) { case 2: j += 6; case 4: j += 1; default: j += 2; case 0: j += 4; } System.out.println("j = " + j); } }

A. j = 0
B. j = 2
C. j = 4
D. j = 6
Answer» E.
39.

What will be the output of the program? public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z < 4; z++) { switch (z) { case x: System.out.print("0 "); default: System.out.print("def "); case x-1: System.out.print("1 "); break; case x-2: System.out.print("2 "); } } } }

A. 0 def 1
B. 2 1 0 def 1
C. 2 1 0 def def
D. 2 1 0 def 1 def 1
Answer» E.
40.

What will be the output of the program? int I = 0; label: if (I < 2) { System.out.print("I is " + I); I++; continue label; }

A. I is 0
B. I is 0 I is 1
C. Compilation fails.
D. None of the above
Answer» D. None of the above
41.

What will be the output of the program? public class SwitchTest { public static void main(String[] args) { System.out.println("value =" + switchIt(4)); } public static int switchIt(int x) { int j = 1; switch (x) { case l: j++; case 2: j++; case 3: j++; case 4: j++; case 5: j++; default: j++; } return j + x; } }

A. value = 2
B. value = 4
C. value = 6
D. value = 8
Answer» E.
42.

What will be the output of the program? for(int i = 0; i < 3; i++) { switch(i) { case 0: break; case 1: System.out.print("one "); case 2: System.out.print("two "); case 3: System.out.print("three "); } } System.out.println("done");

A. done
B. one two done
C. one two three done
D. one two three two three done
Answer» E.
43.

What will be the output of the program? public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z < 3; z++) { switch (z) { case x: System.out.print("0 "); case x-1: System.out.print("1 "); case x-2: System.out.print("2 "); } } } }

A. 0 1 2
B. 0 1 2 1 2 2
C. 2 1 0 1 0 0
D. 2 1 2 0 1 2
Answer» E.
44.

What will be the output of the program? int i = 1, j = 10; do { if(i > j) { break; } j--; } while (++i < 5); System.out.println("i = " + i + " and j = " + j);

A. i = 6 and j = 5
B. i = 5 and j = 5
C. i = 6 and j = 4
D. i = 5 and j = 6
Answer» E.
45.

What will be the output of the program? for (int i = 0; i < 4; i += 2) { System.out.print(i + " "); } System.out.println(i); /* Line 5 */

A. 0 2 4
B. 0 2 4 5
C. 0 1 2 3 4
D. Compilation fails.
Answer» E.
46.

What will be the output of the program? public class If2 { static boolean b1, b2; public static void main(String [] args) { int x = 0; if ( !b1 ) /* Line 7 */ { if ( !b2 ) /* Line 9 */ { b1 = true; x++; if ( 5 > 6 ) { x++; } if ( !b1 ) x = x + 10; else if ( b2 = true ) /* Line 19 */ x = x + 100; else if ( b1 | b2 ) /* Line 21 */ x = x + 1000; } } System.out.println(x); } }

A. 0
B. 1
C. 101
D. 111
Answer» D. 111
47.

What will be the output of the program? public class Switch2 { final static short x = 2; public static int y = 0; public static void main(String [] args) { for (int z=0; z < 3; z++) { switch (z) { case y: System.out.print("0 "); /* Line 11 */ case x-1: System.out.print("1 "); /* Line 12 */ case x: System.out.print("2 "); /* Line 13 */ } } } }

A. 0 1 2
B. 0 1 2 1 2 2
C. Compilation fails at line 11.
D. Compilation fails at line 12.
Answer» D. Compilation fails at line 12.
48.

What will be the output of the program? int i = l, j = -1; switch (i) { case 0, 1: j = 1; /* Line 4 */ case 2: j = 2; default: j = 0; } System.out.println("j = " + j);

A. j = -1
B. j = 0
C. j = 1
D. Compilation fails.
Answer» E.
49.

switch(x) { default: System.out.println("Hello"); } Which two are acceptable types for x? byte long char float Short Long

A. 1 and 3
B. 2 and 4
C. 3 and 5
D. 4 and 6
Answer» B. 2 and 4
50.

public class While { public void loop() { int x= 0; while ( 1 ) /* Line 6 */ { System.out.print("x plus one is " + (x + 1)); /* Line 8 */ } } } Which statement is true?

A. There is a syntax error on line 1.
B. There are syntax errors on lines 1 and 6.
C. There are syntax errors on lines 1, 6, and 8.
D. There is a syntax error on line 6.
Answer» E.