Static nested class VS non-static nested class ??

we know static method can be called without creating an object and static variables are shared among objects.
what is the difference between static nested class and non-static nested class ? When do we use them? what is the advantages of static nested class over non-static nested class in term of performance?

From the JLS, chapter 8:
A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class.
This chapter discusses the common semantics of all classes-top level (?7.6) and nested (including member classes (?8.5, ?9.5), local classes (?14.3) and anonymous classes (?15.9.5)).
So "nested" iff "not top level".From the JLS, chapter 8:
An inner class is a nested class that is not explicitly or implicitly declared static.
So a "static" nested class is a bit redundant, since a "non-static" nested class -- a nested class is either static or it isn't -- is more specifically referred to as an "inner class". That's my story and I'm sticking to it. :o)
~

Similar Messages

  • Convertion of class variable (static) into instance variable(non-static)!

    Dear all,
    got a slight different question.
    Is that possible to convert class variable (static) into instance variable(non-static)?
    If so, how to make the conversion?
    Appreciating your replies :)
    Take care all,
    Leslie V
    http://www.googlestepper.blogspot.com
    http://www.scrollnroll.blogspot.com

    JavaDriver wrote:
    Anything TBD w.r.to pass by value/reference (without removing 'static' keyword)?Besides the use of acronyms in ways that don't make much sense there are two other large problems with this "sentence".
    1) Java NEVER passes by reference. ALWAYS pass by value.
    2) How parameters are passed has exactly zero to do with static.
    Which all means you have a fundamentally broken understanding of how Java works at all.
    Am I asking something apart from this?
    Thanks for your reply!
    Leslie VWhat you're asking is where to find the tutorials because you're lost. Okay. Here you go [http://java.sun.com/docs/books/tutorial/java/index.html]
    And also for the love of god read this [http://www.javaranch.com/campfire/StoryPassBy.jsp] There is NO excuse for not knowing pass-by in Java in this day and age other than sheer laziness.

  • How do I identify which is static and which is non static method?

    I have a question which is how can i justify which is static and which is non static method in a program? I need to explain why ? I think it the version 2 which is static. I can only said that it using using a reference. But am I correct or ?? Please advise....
    if I have the following :
    class Square
    private double side;
    public Square(double side)
    { this.side = side;
    public double findAreaVersion1()
    { return side * side;
    public double findAreaVersion2(Square sq)
    { return sq.side * sq.side;
    public void setSide(double s)
    { side = s;
    public double getSide()
    { return side;
    } //class Square
    Message was edited by:
    SummerCool

    I have a question which is how can i justify which is
    static and which is non static method in a program? I
    need to explain why ? I think it the version 2 which
    is static. I can only said that it using using a
    reference. But am I correct or ?? Please advise....If I am reading this correctly, that you think that your version 2 is a static method, then you are wrong and need to review your java textbook on static vs non-static functions and variables.

  • Static synchronized methods VS non-static synchronized methods ??

    what is the difference between static synchronized methods and non-static synchronized methods as far as the behavior of the threads is concerned? if a thread is in static synchronized method can another thread access simple (ie. non static) synchronized methods?

    javanewbie80 wrote:
    Great. Thanks. This whole explanation made a lot of sense to me.Cool, glad I was able to help!
    Probably I was just trying to complicate things unnecessarily.It's a classic case of complexity inversion. It seems simpler to say something like "synchronization locks the class" or "...locks the method" than to give my explanation and then extrapolate the implications. Just like the seemingly simpler, but incorrect, "Java passes objects by reference," vs. the correct "Java passes references by value," or Java's seemingly complex I/O vs. other languages' int x = readInt(); or whatever.
    In the seemingly complex case, the primitive construct is simpler, but the higher level construct requires more assembly or derivation of the primitive constructs, making that case seem more complicated.
    Okay, I just re-read that, and it seems like I'm making no sense, but I'll leave it, just in case somebody can get some meaning out of it. :-)

  • Error: Cannot make a static reference to the non-static method

    Below is a java code. I attempt to call method1 and method2 and I got this error:
    Cannot make a static reference to the non-static method but If I add the keyword static in front of my method1 and method2 then I would be freely call the methods with no error!
    Anyone has an idea about such error? and I wrote all code in the same one file.
    public class Lab1 {
         public static void main(String[] args) {
              method1(); //error
         public  void method1 ()
         public  void method2 ()
    }

    See the Search Forums at the left of the screen?
    If you had searched with "Cannot make a static reference to the non-static method"
    http://search.sun.com/search/onesearch/index.jsp?qt=Cannot+make+a+static+reference+to+the+non-static+method+&rfsubcat=siteforumid%3Ajava54&col=developer-forums
    you would have the answer. Almost every question you will ask has already been asked and answered.

  • Is Static Function faster than non-static function

    Hi,
    I am wondering the performances issues of static Vs non-static function.
    To prevent object creation, I wrote some static function in my class but I wonder if it really did faster.
    any pointers in this direction will be helpful
    Jacinle

    to mattbunch
    I still haven't pinpointed exactly the system
    bottleneck
    but I do think finding a better approach at the
    earliest time is betterActually, the generally accepted best practice is to start with good algorithms and data structures, write the code, test the code, profile the code, and then do this kind of nickel and dime optimization after specific bottlenecks have been pinpointed. You absolultely should not make a static/non-static decision based on performance considerations. In fact, the idea that non-static is slower due to object creation is rather muddy thinking. You'd either already have the object and invoke its non-static method, or you'd invoke a static method. In the static case, your design would probably be different anyway, so you can't predict whether time saved by not creating an object would be lost by executing other code paths.
    The case in which you count object creation time is if you're creating an object just to call this one method on it and get that method's result, and then not using the object anymore. In that case, the method should be static--not for performance reasons, but rather because the way you are using it suggests that the appropriate design is for it to be static.
    >
    so many decision to be made in designing software
    I wonder if there is any practise I can follow
    See "Thinking in Java" by Bruce Eckel, and "Practical Programming in Java" by Peter Haggar

  • Wondering how we can invoke static method g() from non-static method d()

    class A {
    final int x;
    A() {
    x = 1;
    int f() {
    return d(this,this);
    int d(A a1, A a2) {
    int i = a1.x;
    g(a1);
    int j = a2.x;
    return j - i;
    static void g(A a) {
    // uses reflection to change a.x to 2
    }

    public class A {
         final int x;
         A() {
              x = 1;
         int f() throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
              return d(this,this);
         int d(A a1, A a2) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
              int i = a1.x;
              g(a1);
              int j = a2.x;
              return j - i;
         static void g(A a) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException {
              // uses reflection to change a.x to 2
              //a.getClass().getField("x").setInt(a, 5);
              a.getClass().getDeclaredField("x").setInt(a, 5);
         public static void main(String[] args) throws IllegalArgumentException, SecurityException, IllegalAccessException, NoSuchFieldException{
              A a = new A();
              System.out.println(a.f());
    throws this exception:
    Exception in thread "main" java.lang.IllegalAccessException: Can not set final int field A.x to (int)5
         at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:55)
         at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:79)
         at sun.reflect.UnsafeQualifiedIntegerFieldAccessorImpl.setInt(UnsafeQualifiedIntegerFieldAccessorImpl.java:114)
         at java.lang.reflect.Field.setInt(Field.java:802)
         at A.g(A.java:22)
         at A.d(A.java:13)
         at A.f(A.java:9)
         at A.main(A.java:27)

  • Having Problem With "static" When Running a Stand Alone Java Class

    I have a Java class that recursively builds a 'tree' . This Java class works as I expected without problem. I am able to write out this 'tree" to the console "line by line" with proper indentation.
    The problem occurs when I try to iterate through this 'tree' in the public static void main(String[] arg) method -- Each line in the tree is an Array. And I have to declare this Array (called titleArray in my code) non-static; otherwise, I end up with picking up the very last line of my hard-coded data.
    Besides, I also have to declare the List (called recursiveTextArray in my code) non-static; otherwise, I end up with picking up the first Array that I ever build and run into endless iterations till the heap size is exhausted. Note that each element of that List is an Array object.
    Then, this non-static Array and this non-static List cannot be accessed in the public static void main(String[] arg) method.
    What should I do?
    Here is my code that works without problem (the one I do not access the 'titleArray' in the main(String[] arg) method):
    import java.util.Iterator;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Date;
    import java.awt.Color;
    import com.aspose.words.*;
    public class OplanPhase
         public static void main( String[] args)
              OplanPhase root = new OplanPhase( "", "Oplan 50XX - Phase I" );
              OplanPhase objective1 = new OplanPhase( "OO-3.1", "Destroy enemy conventional ground forces" );
              OplanPhase objective2 = new OplanPhase( "OO-3.2", "Destroy enemy conventional air forces" );          
              OplanPhase objective3 = new OplanPhase( "OO-3.3", "Destroy enemy conventional naval forces" );
              OplanPhase objective4 = new OplanPhase( "OO-3.4", "Influence opposition groups within enemy areas to support friendly forces" );
              OplanPhase effect1 = new OplanPhase( "TgtObj-3.1", "Locate, identify, and destroy key enemy C2 nodes" );
              OplanPhase effect2 = new OplanPhase( "TgtObj-3.2", "Locate, identify, and destroy key enemy C2 nodes" );          
              OplanPhase effect3 = new OplanPhase( "CFSOCC-3.2", "influence enemy opposition groups to support friendly forces campaign objectives" );
              OplanPhase effect4 = new OplanPhase( "JFMECC-3.3", "Destroy SLOC interdiction vessels" );
              OplanPhase effect5 = new OplanPhase( "CFSOCC-3.4", "Influence enemy opposition groups to support friendly forces campaign objectives" );     
              OplanPhase moe1 = new OplanPhase( "MOE-TO-3.1", "Conduct surveillance to locate and identify key enemy C2 nodes" );
              OplanPhase moe2 = new OplanPhase( "MOE-JFSOC-3.1", "Degree of cooperative effort with area opposition groups" );
              OplanPhase moe3 = new OplanPhase( "MOE-JFSOC-3.2", "Number of combined missions successfully completed with opposition groups" );
              OplanPhase moe4 = new OplanPhase( "MOE-JFSOC-3.3", "Number of combined missions successfully completed with opposition groups" );
              OplanPhase task1 = new OplanPhase( "TASK-TO-3.1", "Destroy key enemy C2 nodes" );
              OplanPhase task2 = new OplanPhase( "TASK-TO-3.2", "Conduct surveillance to locate and identify key enemy C2 nodes" );
              OplanPhase task3 = new OplanPhase( "TASK-TO-3.3", "Destroy key enemy C2 nodes" );
              OplanPhase task4 = new OplanPhase( "TASK-JFSOC-3.1", "Degree of cooperative effort with area opposition groups" );
              root.addSubLevel( objective1 );
              root.addSubLevel( objective2 );
              root.addSubLevel( objective3 );
              root.addSubLevel( objective4 );
              objective1.addSubLevel( effect1 );
              objective2.addSubLevel( effect2 );
              objective2.addSubLevel( effect3 );
              objective3.addSubLevel( effect4 );
              objective4.addSubLevel( effect5 );
              effect1.addSubLevel( moe1 );
              effect1.addSubLevel( task1 );
              effect2.addSubLevel( task2 );
              effect2.addSubLevel( task3 );
              effect3.addSubLevel( moe2 );
              effect3.addSubLevel( moe3 );
              effect5.addSubLevel( task4 );
              effect5.addSubLevel( moe4 );
              root.outputAllWithIndentation( 0 );
         private String[] titleArray = { "", "", "" };
         private int indentation = 0;
         private List<OplanPhase> subLevels = new ArrayList<OplanPhase>();
         private List recursiveTextArray = new ArrayList();
         public OplanPhase( String foo, String bar )
              titleArray[1] = foo;
              titleArray[2] = bar;
         public void addSubLevel( OplanPhase op )
              subLevels.add( op );
         public void outputAllWithIndentation( int level )
              indentation = level;
              titleArray[0] = indentString( indentation );
             System.out.println( titleArray[0] + "[" + titleArray[1] + "] " + titleArray[2] );
             recursiveTextArray.add( titleArray );
              for ( int i = 0; i < subLevels.size(); i++ )
                   ( ( OplanPhase )subLevels.get( i ) ).outputAllWithIndentation( level + 1 );
         private static String indentString( int count )
              String blank = "";
              for ( int i = 0; i < count; i++ )
                   blank = blank.concat( "   " );
              return blank;
    }And the code below gives me the static and non-static problem:
    import java.util.Iterator;
    import java.util.List;
    import java.util.ArrayList;
    import java.util.Date;
    import java.awt.Color;
    import com.aspose.words.*;
    public class OplanPhase
         public static void main( String[] args)
              OplanPhase root = new OplanPhase( "", "Oplan 50XX - Phase I" );
              OplanPhase objective1 = new OplanPhase( "OO-3.1", "Destroy enemy conventional ground forces" );
              OplanPhase objective2 = new OplanPhase( "OO-3.2", "Destroy enemy conventional air forces" );          
              OplanPhase objective3 = new OplanPhase( "OO-3.3", "Destroy enemy conventional naval forces" );
              OplanPhase objective4 = new OplanPhase( "OO-3.4", "Influence opposition groups within enemy areas to support friendly forces" );
              OplanPhase effect1 = new OplanPhase( "TgtObj-3.1", "Locate, identify, and destroy key enemy C2 nodes" );
              OplanPhase effect2 = new OplanPhase( "TgtObj-3.2", "Locate, identify, and destroy key enemy C2 nodes" );          
              OplanPhase effect3 = new OplanPhase( "CFSOCC-3.2", "influence enemy opposition groups to support friendly forces campaign objectives" );
              OplanPhase effect4 = new OplanPhase( "JFMECC-3.3", "Destroy SLOC interdiction vessels" );
              OplanPhase effect5 = new OplanPhase( "CFSOCC-3.4", "Influence enemy opposition groups to support friendly forces campaign objectives" );     
              OplanPhase moe1 = new OplanPhase( "MOE-TO-3.1", "Conduct surveillance to locate and identify key enemy C2 nodes" );
              OplanPhase moe2 = new OplanPhase( "MOE-JFSOC-3.1", "Degree of cooperative effort with area opposition groups" );
              OplanPhase moe3 = new OplanPhase( "MOE-JFSOC-3.2", "Number of combined missions successfully completed with opposition groups" );
              OplanPhase moe4 = new OplanPhase( "MOE-JFSOC-3.3", "Number of combined missions successfully completed with opposition groups" );
              OplanPhase task1 = new OplanPhase( "TASK-TO-3.1", "Destroy key enemy C2 nodes" );
              OplanPhase task2 = new OplanPhase( "TASK-TO-3.2", "Conduct surveillance to locate and identify key enemy C2 nodes" );
              OplanPhase task3 = new OplanPhase( "TASK-TO-3.3", "Destroy key enemy C2 nodes" );
              OplanPhase task4 = new OplanPhase( "TASK-JFSOC-3.1", "Degree of cooperative effort with area opposition groups" );
              root.addSubLevel( objective1 );
              root.addSubLevel( objective2 );
              root.addSubLevel( objective3 );
              root.addSubLevel( objective4 );
              objective1.addSubLevel( effect1 );
              objective2.addSubLevel( effect2 );
              objective2.addSubLevel( effect3 );
              objective3.addSubLevel( effect4 );
              objective4.addSubLevel( effect5 );
              effect1.addSubLevel( moe1 );
              effect1.addSubLevel( task1 );
              effect2.addSubLevel( task2 );
              effect2.addSubLevel( task3 );
              effect3.addSubLevel( moe2 );
              effect3.addSubLevel( moe3 );
              effect5.addSubLevel( task4 );
              effect5.addSubLevel( moe4 );
              root.outputAllWithIndentation( 0 );
              try
                  Iterator it = recursiveTextArray.iterator(); //compilation error
                  while ( it.hasNext() )
                       for ( int i=0; i<titleArray.length; i++ ) //compilation error
                            if ( i == 0 )
                                 System.out.println( titleArray[0] ); //compilation error
                            } else if ( i == 1 )
                                 System.out.println( "[" + titleArray[1] + "] " ); //compilation error                             
                            } else if ( i == 2 )
                                 System.out.println( titleArray[2] ); //compilation error
              } catch (Exception e)
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         private String[] titleArray = { "", "", "" };
         private int indentation = 0;
         private List<OplanPhase> subLevels = new ArrayList<OplanPhase>();
         private List recursiveTextArray = new ArrayList();
         public OplanPhase( String foo, String bar )
              titleArray[1] = foo;
              titleArray[2] = bar;
         public void addSubLevel( OplanPhase op )
              subLevels.add( op );
         public void outputAllWithIndentation( int level )
              indentation = level;
              titleArray[0] = indentString( indentation );
             System.out.println( titleArray[0] + "[" + titleArray[1] + "] " + titleArray[2] );
             recursiveTextArray.add( titleArray );
              for ( int i = 0; i < subLevels.size(); i++ )
                   ( ( OplanPhase )subLevels.get( i ) ).outputAllWithIndentation( level + 1 );
         private static String indentString( int count )
              String blank = "";
              for ( int i = 0; i < count; i++ )
                   blank = blank.concat( "   " );
              return blank;
    }

    What should I do?If you feel you need to cross-post, you should have the courtesy to provide a
    link to the other post/s.
    http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=1&t=016129

  • Static calling non-static

    What is the best way aroung a static main method trying to call a non static method?

    Fixing the design of the program, IMHO. This kind of a
    think does not happen in a poperly designed program.Exactly. IF a static method needs to access a non-static variable, it needs to specify which instance of its class owns the variable.
    public static void main(Sting EAGLES[]))
       MyJDialog  mjd = new MyJDialog();
       mjd.setSomeParameter(true);
    }Here's the Reader's Digest Condensed Version&#169; of the rules (with grammatical license):
    1. A static method may only access the static data of it's class, not non-static data.
    2. static methods can only call static methods, not non-static.
    3. There ain't no this in static methods.
    4. You can't override a static method to be non-static.

  • Static to non-static

    Hello.
    I am trying a small die rolling program which pompts the user to enter the number of rolls in a specified range and print the frequency. Now, I want the results to be printed in a JTextArea but it doesn't work. I get cannot make a static reference to the non-static. If I use println() instead of setText(), it does print though.
    public static void main(String[] args){
              JFrame tFrame = new Roll();
              tFrame.setSize(600, 300);
              tFrame.setVisible(true);
              Random dice = new Random();
              int freq[] = new int[7];
              final int first = 1;
              final int limit = 10000;
         try{
              String enter = JOptionPane.showInputDialog(null, "Enter number of
                              rolls in range 1-10000");
              int range = Integer.parseInt(enter);
              if (range > limit){
                   JOptionPane.showMessageDialog(null, "You are not allowed
                             to enter an integer greater than 10000", "Error", JOptionPane.ERROR_MESSAGE);
                   System.exit(0);;
              if (range < first){
                   JOptionPane.showMessageDialog(null, "You cannot enter 0
                               or less than 1", "Error", JOptionPane.ERROR_MESSAGE);
                   System.exit(0);
              for(int i = 1; i < range+1; i++){
                   ++freq[1 + dice.nextInt(6)];
                   txt.setText("Result\tFrequency"); //<<<<cannot make a static reference
                   for (int result = 1; result < freq.length; result++){
                   txt.setText(result + "\t" + freq[result]);  //<<<<cannot make a static reference
              catch (final NumberFormatException nfe) {
                   JOptionPane.showMessageDialog(null, "Please
                              enter integer!", "Error", JOptionPane.ERROR_MESSAGE);
                   System.exit(0);
    }Help please?

    Whatever txt is: you can't call instance attributes or instance methods without actually having the instance first. That's what the compiler is trying to tell you.
    Consider having a main method like
    MyClass mc = new MyClass();
    mc.doStuff();In doStuff() you can then access all the non-static attributes and methods you defined.

  • Why a static class can implements a non-static interface?

    public class Test {
         interface II {
              public void foo();
         static class Impl implements II {
              public void foo() {
                   System.out.println("foo");
    }Why a static class can implements a non-static interface?
    In my mind, static members cann't "use" non-static members.

    Why a static class can implements a
    non-static interface?There's no such thing as a non-static member interface. They are always static even if you don't declare them as such.
    An interface defines, well, a public interface to be implemented. It doesn't matter whether it is implemented by a static nested class or by an inner class (or by any class at all). It wouldn't make sense to enforce that it should be one or the other, since the difference between a static and non-static class is surely an irrelevant detail to the client code of the interface.
    In my mind, static members cann't "use" non-static
    members.
    http://java.sun.com/docs/books/jls/third_edition/html/classes.html#246026
    Member interfaces are always implicitly static. It is permitted but not required for the declaration of a member interface to explicitly list the static modifier.

  • Using a non-static vector in a generic class with static methods

    I have a little problem with a class (the code is shown underneath). The problem is the Assign method. This method should return a clone (an exact copy) of the set given as an argument. When making a new instance of a GenericSet (with the Initialize method) within the Assign method, the variables of the original set and the clone have both a reference to the same vector, while there exists two instances of GenericSet. My question is how to refer the clone GenericSet's argument to a new vector instead of the existing vector of the original GenericSet. I hope you can help me. Thanks
    package genericset;
    import java.util.*;
    public class GenericSet<E>{
    private Vector v;
    public GenericSet(Vector vec) {
    v = vec;
    private <T extends Comparable> Item<T> get(int index) {
    return (Item<T>) v.get(index);
    public static <T extends Comparable> GenericSet<T> initialize() {
    return new GenericSet<T>(new Vector());
    public Vector getVector() {
    return v;
    public static <T extends Comparable> GenericSet<T> insert (GenericSet<T> z, Item<T> i){
    GenericSet<T> g = assign(z);
    Vector v = g.getVector();
    if (!member(g,i))
    v.addElement(i);
    return g;
    public static <T extends Comparable> GenericSet<T> delete(GenericSet<T> z, Item<T> i){
    GenericSet<T> g = assign(z);
    Vector v = g.getVector();
    if (member(g,i))
    v.remove(i);
    return g;
    public static <T extends Comparable> boolean member(GenericSet<T> z, Item<T> i) {
    Vector v = z.getVector();
    return v.contains(i);
    public static <T extends Comparable> boolean equal(GenericSet<T> z1, GenericSet<T> z2) {
    Vector v1 = z1.getVector();
    Vector v2 = z2.getVector();
    if((v1 == null) && (v2 != null))
    return false;
    return v1.equals(v2);
    public static <T extends Comparable> boolean empty(GenericSet<T> z) {
    return (cardinality(z) == 0);
    public static <T extends Comparable> GenericSet<T> union(GenericSet<T> z1, GenericSet<T> z2) {
    GenericSet<T> g = assign(z1);
    for(int i=0; i<cardinality(z2); i++) {
    Item<T> elem = z2.get(i);
    insert(g, elem);
    return g;
    public static <T extends Comparable> GenericSet<T> intersection(GenericSet<T> z1, GenericSet<T> z2) {
    GenericSet<T> g = initialize();
    for(int i=0; i<cardinality(z2); i++) {
    Item<T> elem = z2.get(i);
    if(member(z1, elem))
    insert(g, elem);
    return g;
    public static <T extends Comparable> GenericSet<T> difference(GenericSet<T> z1, GenericSet<T> z2) {
    GenericSet<T> g = initialize();
    for(int i=0; i<cardinality(z1); i++) {
    Item<T> elem = z1.get(i);
    if(!member(z2, elem))
    insert(g, elem);
    for(int i=0; i<cardinality(z2); i++) {
    Item<T> elem = z2.get(i);
    if(!member(z1, elem))
    insert(g, elem);
    return g;
    public static <T extends Comparable> GenericSet<T> assign(GenericSet<T> z) {
    GenericSet<T> g = initialize();
    for(int i=0; i<cardinality(z); i++) {
    Item<T> elem = z.get(i);
    insert(g, elem);
    return g;
    public static <T extends Comparable> boolean subset(GenericSet<T> z1, GenericSet<T> z2) {
    for(int i=0; i<cardinality(z1); i++) {
    Item<T> elem = z1.get(i);
    if(!member(z2, elem))
    return false;
    return true;
    public static <T extends Comparable> int cardinality(GenericSet<T> z){
    Vector v = z.getVector();
    return v.size();
    }

    The issue is not "reference a non-static interface", but simply that you cannot reference a non-static field in a static method - what value of the field ed would the static method use? Seems to me your findEditorData should look something like this:   public static EditorBean findEditorData( String username, EditorBean editorData )
          return editorData.ed.findEditor( username );
       }

  • Calling a non-static method from another Class

    Hello forum experts:
    Please excuse me for my poor Java vocabulary. I am a newbie and requesting for help. So please bear with me! I am listing below the program flow to enable the experts understand the problem and guide me towards a solution.
    1. ClassA instantiates ClassB to create an object instance, say ObjB1 that
        populates a JTable.
    2. User selects a row in the table and then clicks a button on the icon toolbar
        which is part of UIMenu class.
    3. This user action is to invoke a method UpdateDatabase() of object ObjB1. Now I want to call this method from UIMenu class.
    (a). I could create a new instance ObjB2 of ClassB and call UpdateDatabase(),
                                      == OR ==
    (b). I could declare UpdateDatabase() as static and call this method without
         creating a new instance of ClassB.With option (a), I will be looking at two different object instances.The UpdateDatabase() method manipulates
    object specific data.
    With option (b), if I declare the method as static, the variables used in the method would also have to be static.
    The variables, in which case, would not be object specific.
    Is there a way or technique in Java that will allow me to reference the UpdateDatabase() method of the existing
    object ObjB1 without requiring me to use static variables? In other words, call non-static methods in a static
    way?
    Any ideas or thoughts will be of tremendous help. Thanks in advance.

    Hello Forum:
    Danny_From_Tower, Encephalatic: Thank you both for your responses.
    Here is what I have done so far. I have a button called "btnAccept" created in the class MyMenu.
    and declared as public.
    public class MyMenu {
        public JButton btnAccept;
         //Constructor
         public MyMenu()     {
              btnAccept = new JButton("Accept");
    }     I instantiate an object for MyMenu class in the main application class MyApp.
    public class MyApp {
         private     MyMenu menu;
         //Constructor     
         public MyApp(){
              menu = new MyMenu();     
         public void openOrder(){
               MyGUI MyIntFrame = new MyGUI(menu.btnAccept);          
    }I pass this button all the way down to the class detail02. Now I want to set up a listener for this
    button in the class detail02. I am not able to do this.
    public class MyGUI {
         private JButton acceptButton;
         private detail02 dtl1 = new detail02(acceptButton);
         //Constructor
         public AppGUI(JButton iButton){
         acceptButton = iButton;
    public class detail02{
        private JButton acceptButton;
        //Constructor
        public detail02(JButton iButton){
          acceptButton = iButton;
          acceptButton.addActionListener(new acceptListener());               
       //method
        private void acceptListener_actionPerformed(ActionEvent e){
           System.out.println("Menu item [" + e.getActionCommand(  ) + "] was pressed.");
        class acceptListener implements ActionListener {       
            public void actionPerformed(ActionEvent e) {
                   acceptListener_actionPerformed(e);
    }  I am not able to get the button Listener to work. I get NullPointerException at this line
              acceptButton.addActionListener(new acceptListener());in the class detail02.
    Is this the right way? Or is there a better way of accomplishing my objective?
    Please help. Your inputs are precious! Thank you very much for your time!

  • Usage of non static members in a static class

    Can you explain the usage of nonstatic members in a static class?

    Skydev2u wrote:
    I just recently started learning Java so I probably know less than you do. But from what I've learned so far a static class is a class that you can only have one instance of, like the main method. As far as non static members in a static class I think it allows the user to modify some content of the class(variables) even though the class is static. A quick Google help should help though.Actually the idea behind a static class is that you dont have any instances of it at all, its more of a place holder for things that dont have anywhere to live.
    Non-static members in a static class wouldnt have much use

  • Why a non static member class can be defined in an interface

    Non-static member classes are defined as instance members of other classes, just like fields and instance methods are defined in a class. An instance of a non-static member class always has an enclosing instance associated with it.
    An interface can't be instantiated then how a non static member class will have an enclosing instance associated with it.
    interface outer
            public  class inner{
            public void p()
                System.out.println("inside interface's non static member class");
        public  static class inner1{
                public void p(){System.out.println("inside interface's  static member class");
    public class Client {                                           // (11)
        public static void main(String[] args) {                    // (12)
        outer.inner nonStatic = new outer.inner();
            nonStatic.p();
        outer.inner1 stat = new outer.inner1();
          stat.p();
    }inner is a non static member class even then " outer.inner nonStatic = new outer.inner();" working fine ?????????????

    class outer
            public  class inner{
            public void p()
                System.out.println("inside interface's non static member class");
    public class Client {                                           // (11)
        public static void main(String[] args) {                    // (12)
        outer.inner nonStatic = new outer.inner();
        nonStatic.p();
    }on compiling the above code the error message i got is
    "not an enclosing class: outer"
    the reason of this compilation error is "outer.inner nonStatic = new outer.inner();
    it should be "outer.inner nonStatic = new outer(). new inner();"
    now my question is
    interface outer
            public  class inner{
            public void p()
                System.out.println("inside interface's non static member class");
    public class Client {                                           // (11)
        public static void main(String[] args) {                    // (12)
        outer.inner nonStatic = new outer.inner();
        nonStatic.p();
    }on compiling the above code why compilation error is not coming??????????
    i think now it is more clear what i am asking

Maybe you are looking for

  • Old compy's hard drive erased-how do i get songs back on new compy?

    kinda complicated... had itunes and ipod mini for about 1 1/2 years. My lovely computer's hard drive was completely wiped out by a virus (and i wasnt maintaining it well =/) and my parents bought me a new compy. I still listen to my ipod mini... but

  • "Place video from URL" not working in InDesign CC 9.1

    Has anyone come across why an H.264 encoded mp4 file won't embed into InDesign CC, but will in CS6? Last week I upgraded from Indesign 9.0 (where it was working) to Indesign 9.1 (where it no longer works). Specifically, I'm using the "Place video fro

  • Federated Portal Remove Delta Links

    I have two portals running Netweaver 04S running SP10.   I have them up as a federated portal.  I cannot however copy items as remote delta links in the Portal Content Catalog.   I can do a regular copy but not the delta link.  What am I missing?   I

  • Premiere Pro CS6 - video noise in the exported file

    Hi everyone, Im trying to make the transition from FCP7 to Premiere Pro CS6. I edited my first project with Premiere Pro and exported the sequence. However I noticed that the exported file had more video noise than the original clips. The material is

  • PHOTOSHOP ELEMENT 13 PROBLEMS

    How do i stop Photoshop opening every time I view an image. I have 30 day trial ad now considering taking it off after only 3 days really getting on my nerves I am a student and not as yet familiar with Photoshop Element 13 so this is causing me all