What is static nested class and usage in Java

Question -What is static nested class and usage in Java

Solutions– Many developers are confused and telling static nested class as static inner class.But in java, there is no static inner class. 😮

Ok.First we understand ,

what is inner class – inner class or nested class is a class declared entirely within the body of another class or interface.An instance of a normal or top-level class can exist on its own. By contrast, an instance of an inner class cannot be instantiated without being bound to a top-level class.

class OuterClass {

  class InnerClass {  }

}

Types of nested classes in Java

Member class – They are declared outside a function (hence a “member”) and not declared “static”.
Local class
Anonymous class

Nested or inner class is a member of its enclosing class.
Non-static nested classes (inner classes) have access to other members of the enclosing class, even if they are declared private. Static nested classes do not have access to other members of the enclosing class.A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.

Why we use– if a class does’nt depend on anything other than his outer class then we will create static nested class.for example – we have nThere is no need for LinkedList.Entry to be top-level class as it is only used by LinkedList (there are some other interfaces that also have static nested classes named Entry, such as Map.Entry – same concept). And since it does not need access to LinkedList’s members, it makes sense for it to be static – it’s a much cleaner approach.

Happy learning with Vinay in techartifact…

creating a basic skeleton to invoke an AM in Java Class in Oracle ADF

Here is a very cool way of quickly creating a basic skeleton to invoke an AM :

1) Create a Test java class.

2) Inside the mail class, type in keyword ‘bc4jclient’ :

package model;

public class Class1 {
public Class1() {
super();
}

public static void main(String[] args) {
Class1 class1 = new Class1();

bc4jclient
}
}</blockquote>
<div></div>
<blockquote>

3) Press Ctrl + Enter.4) Voila!! A small skeleton to invoke AM gets created:

package model;

import oracle.jbo.*;
import oracle.jbo.client.Configuration;
import oracle.jbo.domain.*;
import oracle.jbo.domain.Number;

public class Class1 {
public Class1() {
super();
}

public static void main(String[] args) {
Class1 class1 = new Class1();

String amDef = "test.TestModule";
String config = "TestModuleLocal";
ApplicationModule am = Configuration.createRootApplicationModule(amDef, config);
ViewObject vo = am.findViewObject("TestView");
// Work with your appmodule and view object here
Configuration.releaseRootApplicationModule(am, true);
}
}