583). Which object Java application uses to create a new process?
[A]Process
[B]Builder
[C]ProcessBuilder
[D]CreateBuilder
Show Answer
Correct Answer: ProcessBuilder
Notes:
Answer: c
Explanation: Java application uses ProcessBuilder object to create a new process. By default, same set of environment variables passed which are set in application’s virtual machine process.
584). Which of the following is true about Java system properties?
[A]Java system properties are accessible by any process
[B] Java system properties are accessible by processes they are added to
[C]Java system properties are retrieved by System.getenv()
[D]Java system properties are set by System.setenv()
Show Answer
Correct Answer: Java system properties are accessible by processes they are added to
Notes:
Answer: b
Explanation: Java system properties are only used and accessible by the processes they are added.
585). Java system properties can be set at runtime.
[A]True
[B]False
[C]none
[D]none
Show Answer
Correct Answer: True
Notes:
Answer: a
Explanation: Java system properties can be set at runtime using System.setProperty(name, value) or using System.getProperties().load() methods.
586). Which system property stores installation directory of JRE?
[A]user.home
[B] java.class.path
[C]java.home
[D]user.dir
Show Answer
Correct Answer: java.home
Notes:
Answer: c
Explanation: java.home is the installation directory of Java Runtime Environment.
587). What does System.getProperty(“variable”) return?
[A]compilation error
[B]value stored in variable
[C]runtime error
[D]null
Show Answer
Correct Answer: null
Notes:
Answer: d
Explanation: System.getProperty(“variable”) returns null value. Because, variable is not a property and if property does not exist, this method returns null value.
588). 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
Show Answer
Correct Answer: setProperties method changes the set of Java Properties which are not persistent
Notes:
Answer: c
Explanation: The changes made by the setProperties method are not persistent. Hence, it does not affect future invocation.
589). How to use environment properties in the class?
[A] @Environment
[B] @Variable
[C]@Property
[D]@Autowired
Show Answer
Correct Answer: @Autowired
Notes:
Answer: d
Explanation:
@Autowired
private Environment env; This is how environment variables are injected in the class where they can be used.
590). 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;
Show Answer
Correct Answer: @Value("${my.property}") private String prop;
Notes:
Answer: a
Explanation: @Value are used to inject the properties and assign them to variables.
591). Which environment variable is used to set java path?
[A]JAVA
[B]JAVA_HOME
[C]CLASSPATH
[D]MAVEN_HOME
Show Answer
Correct Answer: JAVA_HOME
Notes:
Answer: b
Explanation: JAVA_HOME is used to store a path to the java installation.
592). 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”);
Show Answer
Correct Answer: InputStream in = this.getClass().getResourceAsStream(“SomeTextFile.txt”);
Notes:
Answer: c
Explanation: This method can be used to load files using relative path to the package of the class.