Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Explain the changes made to JDK for Java 9


Download 1.52 Mb.
Pdf ko'rish
bet104/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   100   101   102   103   104   105   106   107   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

Explain the changes made to JDK for Java 9.
Answer:
Java 9 has made some fundamental changes which takes
advantage of modules. Prior to Java 9, after installing the JDK a
folder called jre\lib was created. This had all the core jar files.
When you install Java 9, the jre\lib folder is no longer created.
Instead a folder called jmods is created in the root of the JDK
installation. The jmods folder has modules corresponding to all
the core Java files. So instead of having a big far rt.jar, JDK 9 has
separate modules.


266.
267.
Consider the following code snippet:
package mypackage;
public class MyClass {
public void doSomething() {
}
}
In order for this code to be deployed as part of a module,
what needs to be done?
Answer:
The code above specifies a class called MyClass as part of a
package called mypackage. In order for this code above to be
deployed as part of a module, a module descriptor needs to be
created as follows:
module mymodule {
exports mypackage;
}
So, this specifies a module called mymodule. It uses the exports
directive with the package mypackage indicating that
mypackage will be available to other modules.
Explain the requires static module directive. When should
it be used?
Answer:
The requires static directive is used to specify optional
dependencies, that is dependencies that are required at compile
time but not required at runtime. Suppose you have developed a
module and require some third–party library which the end users


of your module will never require. In such a case, you can specify
the third–party library via the requires static directive while
defining your module. So, the users of your module will need to
have the third–party library at compile time, but they do not need
it at runtime.




Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   100   101   102   103   104   105   106   107   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling