Wednesday, November 16, 2011

Tuesday, November 1, 2011

static nested class and non-static nested (inner) class

http://stackoverflow.com/questions/70324/java-inner-class-and-static-nested-class

-----------------------------------static nested---------------------------------------

package pizza;
public class Rhino {

    ...

    public static class Goat {
        ...
    }
}
 
### 

Rhino.Goat goat = new Rhino.Goat(); 
 
###
NOTE: 
A non-static nested class (or 'inner class') has full access to the members of the class within which it is nested.
    
-----------------------------------non-static nested (inner)---------------------------------------

package pizza;
public class Rhino {

    public class Goat {
        ...
    }

    private void jerry() {
        Goat g = new Goat();
    }
}
 
### 
Rhino rhino = new Rhino();
Rhino.Goat goat = rhino.new Goat();
 
###
A static nested class does not have a reference to a nesting instance, so a static nested class cannot invoke non-static methods or access non-static fields of an instance of the class within which it is nested. 

http://stackoverflow.com/questions/1353309/java-static-vs-non-static-inner-class

http://www.brpreiss.com/books/opus5/html/page601.html

Friday, October 21, 2011

Declaring Constructors, Methods, and Variables in an enum

NOTE: the order of the line of the code is important for the following:

public enum SORT_ORDER
{
  ACCESSED_ASCENDING("accessed_ascending"),   
  ACCESSED_DESCENDING("accessed_descending");
   
  private SORT_ORDER(String p_value)
  {
   this.m_value = p_value;
  }

  private final String m_value;

  @Override
  public String toString()
  {
    return m_value;
  }
}

Wednesday, October 12, 2011

Linux: java.io.IOException: Too many open files

http://lj4newbies.blogspot.com/2007/04/too-many-open-files.html
http://www.karakas-online.de/forum/viewtopic.php?t=9834

1. check max file descriptor

cat /proc/sys/fs/file-max

change to higher if needed

2. add to
/etc/security/limits.conf

something like

* soft nofile 65535
* hard nofile 65535
 
3. log out and log back in  

Thursday, September 22, 2011

Singleton, Thread Safety, Volatile, Synchronized

On the singleton 'getter', add 'synchronized' for thread safety

otherwise, findbugs will say something like "Incorrect lazy initialization of static field ..."

More explanation:

http://www.ibm.com/developerworks/java/library/j-dcl/index.html

http://en.wikipedia.org/wiki/Singleton_pattern

Private Constructor

http://www.javapractices.com/topic/TopicAction.do?Id=40

If the programmer does not provide a constructor for a class, then the system will always provide a default, public no-argument constructor. To disable this default constructor, simply add a private no-argument constructor to the class. This private constructor may be empty.

In these cases, the lack of an accessbile constructor says to the caller : "There are no use cases for this class where you need to build an object. You can only use static items. I am preventing you from even trying to build an object of this class."

Friday, September 16, 2011

64bit Ubuntu won't run java

As of  Ubuntu 10.04 LT - the Lucid Lynx

you can't run a 32 bit jre on it, will tell you something like

exec: 1: ../../../bin/java: not found

In fact, 32 bit eclipse won't work either, and imaginable many other 32bit applications