How To Get Super Class Name From Object

java-thumbnail

This example illustrates how to get the super class name from its instance. If you are aware of the java.lang.Class, it has methods for knowing the details of a class. One of the method defined in that class is Class.getSuperclass() which is useful for getting the super class’s java.lang.Class object. With that object, you can […]

How To Get Class Name From Object

java-thumbnail

This example illustrates how to get the class name from its object. If you are aware of the java.lang.Class, it has methods for knowing the details of a class. One of the method defined in that class is Class.getName() which is useful for getting the name of the class. Note that, each instance has “class” […]

How To Resolve java.lang.IllegalAccessException

java-thumbnail

This example shows when the java.lang.IllegalAccessException is thrown in your application. When an application tries to reflectively create an instance (other than an array), set or get a field, or invoke a method, if that method is not accessible to your application (probably the modifier is private or not accessible one), then your application will […]

Static Initializer In Java

java-thumbnail

This example shows how to use the static initializer in Java. The following are the few features of static blocks. Static initializers are block of code with static keyword. These are executed when the class is loaded or accessed first time by any application. Only static variables can be initialized inside static blocks. Instance variables […]

Java ScriptEngineFactory Example

java-thumbnail

This example shows how to get the details of the script engines supported by your JVM. Java supports the different script engines that can be retrieved and used depends upon the client side scripts. Java provides javax.script.ScriptEngineFactory for storing all the script engine details like script engine name, version, default script engine, language, etc. You […]

How To Import Java Package Inside JavaScript using ScriptEngine

java-thumbnail

This example show how to import Java package inside JavaScript. We can import the Java package and use the classes inside the scripts. In this example, I have imported the java.util package and use java.util.Date class to print today’s date. Lets look at the example. JavaScriptEngineImportPackageExample.java Output…

How To Run External JavaScript File using ScriptEngine

java-thumbnail

This example is to show how to load the script files to ScriptEngine and evaluate it. In our previous example I have explained how to write script in the Java file and use it in the Java method. In real scenario, scripts written in the external files with bunch of code. We have load the […]

Invoke Script Function using ScriptEngine

java-thumbnail

This is an example of invoking a method in the Script using Java. We have to create javax.script.ScriptEngineManager and javax.script.ScriptEngine to invoke the methods. In this example I have created two methods one without parameter and one with two parameters. Once we have created the script engine instances, then we need to get javax.script.Invocable instance […]

How To Get Java ScriptEngine By MimeType

java-thumbnail

This example shows how to get the script engine by using the mimetype. This is the first step when you are using the Java script engines for executing the scripts. Before your run the scripts, you must get the javax.script.ScriptEngine instance from javax.script.ScriptEngineManager. The engines are registered using the Names ,Extensions and Mimetype. This example […]

How To Get Java ScriptEngine By Extension

java-thumbnail

This example shows how to get the script engine by using the extension. This is the first step when you are using the Java script engines for executing the scripts. Before your run the scripts, you must get the javax.script.ScriptEngine instance from javax.script.ScriptEngineManager. The engines are registered using the Names ,Extensions and Mimetypes. This example […]