Java Programming MCQ (Multiple Choice Questions) - SchoolingAxis

Java Programming MCQ (Multiple Choice Questions)

 Que-  Which system property stores installation directory of JRE?

a. user.home

b. java.class.path

c. java.home

d. user.dir


Answer- java.home


Que-  What does System.getProperty("variable") return?

a. compilation error

b. value stored in variable

c. runtime error

d. null


Answer- null


Que-  What is true about the setProperties method?

a. setProperties method changes the set of Java Properties which are persistent

b. Changing the system properties within an application will affect future invocations

c. setProperties method changes the set of Java Properties which are not persistent

d. setProperties writes the values directly into the file which stores all the properties


Answer- setProperties method changes the set of Java Properties which are not persistent


Que-  How to use environment properties in the class?

a. @Environment

b. @Variable

c. @Property

d. @Autowired


Answer- @Autowired


Que-  How to assign values to variable using property?

a.@Value("${my.property}") private String prop;

b.@Property("${my.property}") private String prop; 

c.@Environment("${my.property}") private String prop;

d.@Env("${my.property}") private String prop;


Answer-@Value("${my.property}") private String prop;


Que-  Which environment variable is used to set java path?

a. JAVA

b. JAVA_HOME

c. CLASSPATH

d. MAVEN_HOME


Answer- JAVA_HOME


Que-  How to read a classpath file?

a. InputStream in = this.getClass().getResource("SomeTextFile.txt");

b. InputStream in = this.getClass().getResourceClasspath("SomeTextFile.txt");

c. InputStream in = this.getClass().getResourceAsStream("SomeTextFile.txt");

d. InputStream in = this.getClass().getResource("classpath:/SomeTextFile.txt");


Answer- InputStream in = this.getClass().getResourceAsStream("SomeTextFile.txt");


Que-  Which of these is a process of writing the state of an object to a byte stream?

a. Serialization

b. Externalization

c. File Filtering

d. All of the mentioned


Answer- Serialization


Que-  Which of these process occur automatically by the java runtime system?

a. Serialization

b. Garbage collection

c. File Filtering

d. All of the mentioned


Answer- Serialization


Que-  Which of these is an interface for control over serialization and deserialization?

a. Serializable

b. Externalization

c. FileFilter

d. ObjectInput


Answer- Externalization


Que-  Which of these interface extends DataOutput interface?

a. Serializable

b. Externalization

c. ObjectOutput

d. ObjectInput


Answer- ObjectOutput


Que-  Which of these is a method of ObjectOutput interface used to finalize the output state so that any buffers are cleared?

a. clear()

b. flush()

c. fflush()

d. close()


Answer- flush()


Que-  Which of these is method of ObjectOutput interface used to write the object to input or output stream as required?

a. write()

b. Write()

c. StreamWrite()

d. writeObject()


Answer- writeObject()


Que-  How an object can become serializable?

a. If a class implements java.io.Serializable class

b. If a class or any superclass implements java.io.Serializable interface

c. Any object is serializable

d. No object is serializable


Answer- If a class or any superclass implements java.io.Serializable interface


Que-  What is serialization?

a. Turning object in memory into stream of bytes

b. Turning stream of bytes into an object in memory

c. Turning object in memory into stream of bits

d. Turning stream of bits into an object in memory


Answer- Turning object in memory into stream of bytes


Que-  What is deserialization?

a. Turning object in memory into stream of bytes

b. Turning stream of bytes into an object in memory

c. Turning object in memory into stream of bits

d. Turning stream of bits into an object in memory


Answer- Turning stream of bytes into an object in memory


Que-  How many methods Serializable has?

a.1

b.2

c.3

d.0


Answer-0


Que-  What type of members are not serialized?

a. Private

b. Protected

c. Static

d. Throwable


Answer- Static


Que-  If member does not implement serialization, which exception would be thrown?

a. RuntimeException

b. SerializableException

c. NotSerializableException

d. UnSerializedException


Answer- NotSerializableException


Que-  Default Serialization process cannot be overridden.

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-FALSE


Que-  Which of the following methods is used to avoid serialization of new class whose super class already implements Serialization?

a. writeObject()

b. readWriteObject()

c. writeReadObject()

d. unSerializaedObject()


Answer- writeObject()


Que-  Which of the following methods is not used while Serialization and DeSerialization?

a. readObject()

b. readExternal()

c. readWriteObject()

d. writeObject()


Answer- readWriteObject()


Que-  Serializaed object can be transferred via network.

a.TRUE

b.FALSE

c.Nothing Can be Said

d.None of the mentioned


Answer-TRUE

Previous Post Next Post