This set of Java Multiple Choice Questions & Answers (MCQs) on “System Class Advance”.
1. Which of these exceptions is thrown by methods of System class? Answer: c 2. Which of these methods initiates garbage collection? Answer: a 3. Which of these methods loads the specified dynamic library? Answer: a 4. Which of these method can set the out stream to OutputStream? Answer: c 5. Which of these values are returns under the case of normal termination of a program? Answer: a 6. What will be the output of the following Java program? a) 0 7. What will be the output of the following Java program? a) ABCDEF ABCDEF 8. What will be the output of the following Java program? a) ABCDEF ABCDEF 9. What will be the output of the following Java program? a) ABCDEF ABCDEF 10. What will be the output of the following Java program? a) 0 Answer: d
a) IOException
b) SystemException
c) SecurityException
d) InputOutputException
Clarification: System class methods throw SecurityException.
a) gc()
b) garbage()
c) garbagecollection()
d) Systemgarbagecollection()
Clarification: None.
a) load()
b) library()
c) loadlib()
d) loadlibrary()
Clarification: load() methods loads the dynamic library whose name is specified.
a) setStream()
b) setosteam()
c) setOut()
d) streamtoOstream()
Clarification: None.
a) 0
b) 1
c) 2
d) 3
Clarification: None.
import java.lang.System;
class Output
{
public static void main(String args[])
{
long start, end;
start = System.currentTimeMillis();
for (int i = 0; i < 10000000; i++);
end = System.currentTimeMillis();
System.out.print(end - start);
}
}
b) 1
c) 1000
d) System Dependent
Clarification: End time is the time taken by loop to execute it can be any non zero value depending on the System.
Output:
$ javac Output.java
$ java Output
78
import java.lang.System;
class Output
{
public static void main(String args[])
{
byte a[] = { 65, 66, 67, 68, 69, 70 };
byte b[] = { 71, 72, 73, 74, 75, 76 };
System.arraycopy(a, 0, b, 0, a.length);
System.out.print(new String(a) + " " + new String(b));
}
}
b) ABCDEF GHIJKL
c) GHIJKL ABCDEF
d) GHIJKL GHIJKL
Clarification: System.arraycopy() is a method of class System which is used to copy a string into another string.
Output:
$ javac Output.java
$ java Output
ABCDEF ABCDEF
import java.lang.System;
class Output
{
public static void main(String args[])
{
byte a[] = { 65, 66, 67, 68, 69, 70 };
byte b[] = { 71, 72, 73, 74, 75, 76 };
System.arraycopy(a, 0, b, 3, a.length - 3);
System.out.print(new String(a) + " " + new String(b));
}
}
b) ABCDEF GHIJKL
c) ABCDEF GHIABC
d) GHIJKL GHIJKL
Clarification: System.arraycopy() is a method of class System which is used to copy a string into another string.
Output:
$ javac Output.java
$ java Output
ABCDEF GHIABC
import java.lang.System;
class Output
{
public static void main(String args[])
{
byte a[] = { 65, 66, 67, 68, 69, 70 };
byte b[] = { 71, 72, 73, 74, 75, 76 };
System.arraycopy(a, 2, b, 3, a.length - 4);
System.out.print(new String(a) + " " + new String(b));
}
}
b) ABCDEF GHIJKL
c) ABCDEF GHIABC
d) ABCDEF GHICDL
Clarification: System.arraycopy() is a method of class System which is used to copy a string into another string.
Output:
$ javac Output.java
$ java Output
ABCDEF GHICDL
import java.lang.System;
class Output
{
public static void main(String args[])
{
System.exit(5);
}
}
b) 1
c) 4
d) 5
Clarification: None.
