Java Questions & Answers – Environment Properties

This set of Java Multiple Choice Questions & Answers (MCQs) focuses on “Environment Properties”.

1. Which object Java application uses to create a new process?
a) Process
b) Builder
c) ProcessBuilder
d) CreateBuilder
View Answer

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.

2. 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()
View Answer

Answer: b
Explanation: Java system properties are only used and accessible by the processes they are added.

3. Java system properties can be set at runtime.
a) True
b) False
View Answer

Answer: a
Explanation: Java system properties can be set at runtime using System.setProperty(name, value) or using System.getProperties().load() methods.

4. Which system property stores installation directory of JRE?
a) user.home
b) java.class.path
c) java.home
d) user.dir
View Answer

Answer: c
Explanation: java.home is the installation directory of Java Runtime Environment.

5. What does System.getProperty(“variable”) return?
a) compilation error
b) value stored in variable
c) runtime error
d) null
View Answer

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.
Note: Join free Sanfoundry classes at Telegram or Youtube

6. 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
View Answer

Answer: c
Explanation: The changes made by the setProperties method are not persistent. Hence, it does not affect future invocation.

7. How to use environment properties in the class?
a) @Environment
b) @Variable
c) @Property
d) @Autowired
View Answer

Answer: d

	     private Environment env;

This is how environment variables are injected in the class where they can be used.


8. How to assign values to variable using property?

private String prop;


private String prop; 


private String prop;


private String prop;
View Answer
Answer: a
Explanation: @Value are used to inject the properties and assign them to variables.

9. Which environment variable is used to set java path?
View Answer

Answer: b
Explanation: JAVA_HOME is used to store a path to the java installation.

10. 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”);
View Answer

Answer: c
Explanation: This method can be used to load files using relative path to the package of the class.

Sanfoundry Global Education & Learning Series – Java Programming Language.

To practice all areas of Java language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.