Default class with public constructor - why?

Noticed some code that had a class with package-level access and a public constructor - wondered what the benefit/use of that would be... Thanks!

GarudaJava wrote:
Noticed some code that had a class with package-level access and a public constructor - wondered what the benefit/use of that would be... Thanks!If the class itself doesn't need to be exposed, but it implements some interface, and is assumed to have a public no-arg consturctor, it could be created reflexively. This is a contrived situation, but it's the only one I can think of in Java where that'd be useful.
package foo;
class Foo implements SomeInterface {
  public Foo() {
package factory;
class Factory {
  public static SomeInterface create(Class<? extends SomeInterface> clazz) { // not sure if I got the generics right, but they're incidendtal to the example
    return clazz.newInstance();
package foo;
import factory.Factory;
public class Bar {
  public void bar() {
    SomeInterface si = Factory.create(Foo.class);
    si.doStuff();
}Like I said, pretty contrived, and I can't think of a real-world use case that matches it offhand, but structurally it'd look something like that.
You could also maybe imagine that the factory package might do more than just create and return an instance. It might create it and use that SomeInterface type for its own ends.

Similar Messages

  • Why can't classes with private constructors be subclassed?

    Why can't classes with private constructors be subclassed?
    I know specifying a private nullary constructor means you dont want the class to be instantiated or the class is a factory or a singleton pattern. I know the workaround is to just wrap all the methods of the intended superclass, but that just seems less wizardly.
    Example:
    I really, really want to be able to subclass java.util.Arrays, like so:
    package com.tassajara.util;
    import java.util.LinkedList;
    import java.util.List;
    public class Arrays extends java.util.Arrays {
        public static List asList(boolean[] array) {
            List result = new LinkedList();
            for (int i = 0; i < array.length; i++)
                result.add(new Boolean(array));
    return result;
    public static List asList( char[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Character(array[i]));
    return result;
    public static List asList( byte[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Byte(array[i]));
    return result;
    public static List asList( short[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Short(array[i]));
    return result;
    public static List asList( int[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Integer(array[i]));
    return result;
    public static List asList( long[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Long(array[i]));
    return result;
    public static List asList( float[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Float(array[i]));
    return result;
    public static List asList( double[] array) {
    List result = new LinkedList();
    for (int i = 0; i < array.length; i++)
    result.add(new Double(array[i]));
    return result;
    // Now that we extend java.util.Arrays this method is not needed.
    // /**JCF already does this so just wrap their implementation
    // public static List asList(Object[] array) {
    // return java.util.Arrays.asList(array);
    public static List asList(Object object) {
    List result;
    Class type = object.getClass().getComponentType();
    if (type != null && type.isPrimitive()) {
    if (type == Boolean.TYPE)
    result = asList((boolean[])object);
    else if (type == Character.TYPE)
    result = asList(( char[])object);
    else if (type == Byte.TYPE)
    result = asList(( byte[])object);
    else if (type == Short.TYPE)
    result = asList(( short[])object);
    else if (type == Integer.TYPE)
    result = asList(( int[])object);
    else if (type == Long.TYPE)
    result = asList(( long[])object);
    else if (type == Float.TYPE)
    result = asList(( float[])object);
    else if (type == Double.TYPE)
    result = asList(( double[])object);
    } else {
    result = java.util.Arrays.asList((Object[])object);
    return result;
    I do not intend to instantiate com.tassajara.util.Arrays as all my methods are static just like java.util.Arrays. You can see where I started to wrap asList(Object[] o). I could continue and wrap all of java.util.Arrays methods, but thats annoying and much less elegant.

    Why can't classes with private constructors be
    subclassed?Because the subclass can't access the superclass constructor.
    I really, really want to be able to subclass
    java.util.Arrays, like so:Why? It only contains static methods, so why don't you just create a separate class?
    I do not intend to instantiate
    com.tassajara.util.Arrays as all my methods are static
    just like java.util.Arrays. You can see where I
    started to wrap asList(Object[] o). I could continue
    and wrap all of java.util.Arrays methods, but thats
    annoying and much less elegant.There's no need to duplicate all the methods - just call them when you want to use them.
    It really does sound like you're barking up the wrong tree here. I can see no good reason to want to subclass java.util.Arrays. Could you could explain why you want to do that? - perhaps you are misunderstanding static methods.
    Precisely as you said, if they didn't want me to
    subclass it they would have declared it final.Classes with no non-private constructors are implicitly final.
    But they didn't. There has to be a way for an API
    developer to indicate that a class is merely not to be
    instantiated, and not both uninstantiable and
    unextendable.There is - declare it abstract. Since that isn't what was done here, I would assume the writers don't want you to be able to subclass java.util.Arrays

  • Private inner class with private constructor

    I read that if constructor is public then you need a static method to create the object of that class.
    But in the following scenario why I am able to get the object of PrivateStuff whereas it has private constructor.
    I am messing with this concept.
    public class Test {
          public static void main(String[] args) {          
               Test t = new Test();
               PrivateStuff p = t.new PrivateStuff();
          private class PrivateStuff{
               private PrivateStuff(){
                    System.out.println("You stuff is very private");
    }

    A member (class, interface, field, or method) of a reference (class, interface, or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:
    * Otherwise, if the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor. [Java Language Specification|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.1]
    Your main method is within the body of the top level class, so the type (the inner class) and method are accessible.
    eg:
    class ImInTheSameSourceFileAsInnerAccessTest {
        public static void main(String[] args) {          
            InnerAccessTest t = new InnerAccessTest();
            InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    public class InnerAccessTest {
          public static void main(String[] args) {          
               InnerAccessTest t = new InnerAccessTest();
               PrivateStuff p = t.new PrivateStuff();
          private class PrivateStuff{
               private PrivateStuff(){
                    System.out.println("You stuff is very private");
    }Result:
    $ javac -d bin src/InnerAccessTest.java
    src/InnerAccessTest.java:4: InnerAccessTest.PrivateStuff has private access in InnerAccessTest
    InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    ^
    src/InnerAccessTest.java:4: InnerAccessTest.PrivateStuff has private access in InnerAccessTest
    InnerAccessTest.PrivateStuff p = t.new PrivateStuff();
    ^
    2 errors
    Edited by: pm_kirkham on 20-Jan-2009 10:54 added example of 'in the same source file'

  • Class with no constructors

    The class javax.microedition.rms .RecordStore does not have a constructor. Why?
    Please note that I am not asking how to produce an instance of a RecordStore, I have read the documentation and am aware of the static openRecordStore method.
    Paul Hide

    javax.microedition.rms.RecordStore has no public or protected constructor so you can't extend it.
    If a private constructor is defined in a class then it is not exposed in documentation (usually), but at the other hand if you have not defined any constructor then non-argument public constructor is shown in the documentation.
    So it seems that javax.microedition.rms.RecordStore has private constructor.
    So you can't extend it.
    Following two type of classes are non-extendable:
    - Whose all constructors are made private. E.g. java.lang.Runtime, java.lang.System.
    - Final class (just final keyworkd is added in access specifiers). E.g. java.lang.String
    Following two type of classes are non-instantiable:
    - Whose all constructors are made private. These can be instantiated inside the class. E.g. java.lang.Runtime, java.lang.System
    - Abstract class (just abstract keyword is added in access specifiers). E.g. java.io.OutputStream
    Regards,
    Humayun.

  • No public constructor, why?

    The Pattern and Matcher classes in in java.uti.regex package do not have public constructors. Instead, an object for those classes can be retrieved by invoking their static methods, Pattern.compile() and Matcher.matcher() respectively.
    What is the reason? Why do they not have public constructor?
    It is not clearly an implementation of Singleton Pattern which is characterized by getInstance() method.
    Thanks in advance

    sosododo wrote:
    The Pattern and Matcher classes in in java.uti.regex package do not have public constructors. Instead, an object for those classes can be retrieved by invoking their static methods, Pattern.compile() and Matcher.matcher() respectively.
    What is the reason? Why do they not have public constructor?
    It is not clearly an implementation of Singleton Pattern which is characterized by getInstance() method.
    Thanks in advancePlease be aware that the singleton pattern is not characterized by a getInstance method (which is in fact a factory method) and nor is the presence of a method called getInstance any indicator of a singleton. Here is a perfectly valid (and more thread-safe) implementation of the singleton pattern
    public class ASingleton {
    public static final ASingleton INSTANCE = new ASingleton();
      private ASingleton() {}
    }Not a getInstance in sight

  • Class with private constructor can be extended or not

    Hi All,
    I have a doubt.
    if a class has private constructor and there are some methods in this class.Can this class be extended and if yes how can we call its method in subclass?
    Thanks
    Sumit

    Karanjit wrote:
    If a class contains only private constructors, then it cannot be extended.Err... not the whole story!
    public class Sabre20090603a
        static class Fred extends Sabre20090603a
            Fred()
                super();
        private Sabre20090603a()
    }

  • Creating a generic class with a constructor that takes an array of objects

    I am relatively new to java and want to build a quick utility class that can generate a Run Length Encoding of any object. The idea is to take an array of objects of type "O" and then encode a string of objects that are "equal" to each other as an integer that counts the number of such equal instances and a single copy of the instance. This has the potential to very quickly reduce the size of some objects that I want to store. I would like to implement this class as a generic.
    public class RunLengthEncoding<O> {
         private class RLEPair {
              private int length;
              private O object;
         public RunLengthEncoding(O[]) {
    }As you can see, I need to make a constructor that takes an array of type "O". Is this possible to do? I can't seem to find the right syntax for it.
    Thanks,
    Sean

    Sorry. Obvious answer:
    public RunLengthEncoding(O[] oarray) {Again, sorry for the noise.

  • Public Constructor in atg

    Hi ,
    i was going through the doc Public Constructor , why constructor without args is needed in creating a nucleus component. i create a component like
    Test.java
    name;
    getxx();
    setxx();
    Test.properties
    name=Kavi
    when i went to dyn/admin im able to see the value 'Kavi' under name property in Test Component,then what is the need of a default constructor.Please add your inputs
    Regards
    G.KaviMani

    Hi Joe,
    Oracle ATG Web Commerce - Public Constructor with No Arguments
    Public Constructor with No Arguments
    Nucleus can create a component automatically from a properties file if the component class is declared public and it implements a public constructor with no arguments. For example:
    public class Person {
      public Person () {}
    The constructor is not required to be empty. However, as shown later in this chapter, it is often a good idea to defer initialization functions until after the component starts.
    If the constructor for the component class requires arguments, you will need to supply additional information. See Parameterized Constructors.
    So this means the above highlighted statement is not mandatory correct ?? Pls correct me if am wrong.
    Regards
    G.KaviMani

  • Creating an instance of a class with no default constructor

    Hello gurus,
    I wrote my own serialization and RMI protocol for both C++ and Java that follows closely what the default Java version does. I'm trying to recreate an object on the Java side that was sent over the wire. The first step is to create an instance of the class. How do I create an instance of a class that has no constructor (i.e. the only instances are static, created by the class itself and returned by static methods) or one that has no default constructor (like Integer)? The Java serialization seems to support it but the reflection API doesn't seem to have any support for this (i.e. Class::newInstance() and Constructor::newInstance()). It seems that through the standard API you can only create an object via one of its constructors. There must be a "hidden" method somewhere that allows the Java serialization to create an object without calling a constructor - where is it?
    Dominique

    There must be a "hidden" method
    somewhere that allows the Java serialization to create
    an object without calling a constructor - where is
    it?You are correct, the way in which the Serialization creates Objects is "hidden" deep within the runtime.
    If it were not hidden, you would be able to find it, and use it to violate the integrity of the VM.

  • Instantiate class with a private constructor

    How do you call a class that happens to have a private constructor. how would one instantiate such a class? Generally constructors are supposed to be public.
    But in many cases the constructor for a class can be private, so how to call such a class?

    khurrumnas wrote:
    I dont think you would need to provide such a method (newInstance()), its there for you already in Class Class, so its suffice to just call
    newInstance() to get an instance of class that happens to have a private constructor, in the simplest case.False, as jverd rightly mentioned. Example: public class Foo {
        public static void main(String[] args) {
            Exception expectedException = null;
            try {
                Bar b = (Bar) Class.forName("Bar").newInstance(); // throws Exception
            } catch (Exception e) {
                expectedException = e;
            assert expectedException instanceof IllegalAccessException;
    class Bar {
        private Bar() {}
    }As mentioned several times now, one can get around this restriction, but it's considered poor form to do so.
    ~

  • Why should we not declare Class with protected modifier ?

    Why should we not declare Class with protected modifier ?

    jwenting wrote:
    georgemc wrote:
    Why we not research our endless questions?how else could you reach 14000 posts in under 3 years, a true achievement :) Congratulations.Ah, that reminds me. It was a long time ago since I posted some stats:
    Posts:
    jverd                        46427   2972   0,06
    DrClap                       36310   5222   0,14
    jschell                      32357   2583   0,08
    CeciNEstPasUnProgrammeur     31500   1438   0,05
    camickr                      29870   4783   0,16
    yawmark                      28729   1803   0,06
    kajbj                        24180   1829   0,08
    BalusC                       22857   2875   0,13
    warnerja                     21886   2188   0,10
    ejp                          19929   3247   0,16
    sabre150                     17537   1913   0,11
    paulcw                       16005   1724   0,11
    DrLaszloJamf                 14857   1840   0,12
    georgemc                     14000    889   0,06
    prometheuzz                  13466   1180   0,09
    cotton.m                     13409   1308   0,10
    ChuckBing                    12667   1735   0,14
    JosAH                        11926    842   0,07
    flounder                     11607   1201   0,10
    mlk                          10795    886   0,08
    Darryl.Burke                 10564   1787   0,17
    Encephalopathic              10203   1508   0,15
    tjacobs01                     9540   1658   0,17
    BigDaddyLoveHandles           8980    763   0,08
    dcminter                      8081    533   0,07
    tsith                         8049    704   0,09
    jwenting                      7831    249   0,03
    malcolmmc                     7539    819   0,11
    Michael_Dunn                  7392   2088   0,28
    PhHein                        7360   1207   0,16
    morgalr                       7081    703   0,10
    pbrockway2                    6471   1208   0,19
    BIJ001                        6179    322   0,05
    JoachimSauer                  5824    604   0,10
    abillconsl                    5777    943   0,16
    corlettk                      5671    544   0,10
    TuringPest                    5651    444   0,08
    masijade.                     5396    434   0,08
    YoGee                         4695    530   0,11
    gimbal2                       3642    315   0,09
    uncle_alice                   3496   1009   0,29
    bshannon                      3427    614   0,18
    tschodt                       3236    280   0,09
    sjasja                        3193    459   0,14
    SoulTech2012                  3005    109   0,04
    Peter__Lawrey                 2847    254   0,09
    Torgil                        2175    358   0,16
    Navy_Coder                    2119    648   0,31
    rukbat                        1951    252   0,13
    java_2006                     1913   1123   0,59
    baftos                        1808    665   0,37
    es5f2000                      1718    192   0,11
    AndrewThompson64              1716    973   0,57
    YAT_Archivist                 1713    230   0,13
    Aknibbs                       1693     86   0,05
    drvijayy2k2                   1574    266   0,17
    StanislavL                    1396   1117   0,80
    stefan.schulz                 1159    208   0,18
    JayDS                         1100    410   0,37
    dannyyates                    1094    211   0,19
    Joerg22                       1046     48   0,05
    uj_                           1033     49   0,05

  • ERROR:The applet Tennisball does not have a public constructor Tennisball()

    hi all...sorry...i encountered this java error msg with the following code.....n the error msg tat was generated is that i do not have a public constructor which i already have...can some1 please enlighten me..??
    import java.applet.*;
    import java.awt.*;
    public class Tennisball
         double x, y, oldx, oldy, xinc, yinc, v=2.0;
         int i,e,west,north,east,south,ry,rs,score,rx;
         int choice, zone;
         AudioClip ballout;
         boolean running,toggle,enough;
            Color ballcolor;
         Tennis t;
         Color bgColor = Color.black;
         public Tennisball(int w, int n, int e, int s, AudioClip bo)
                    west=w;
              east=e;
              south=s;
              north=n;
              ballout = bo;
              //this.t = t;
              xinc=1.7*v;
              yinc=0.7*v;
         public void getRacketPosition(int racket_y)
              ry=racket_y;
              rs=ry;
         public void newBall()
              ballcolor=Color.yellow;
              x=20;
              y=(int)(Math.random()*100+50);
              int angle=(int)(Math.random()*8+1);
              if(angle==1)yinc=-0.7*v;
              if(angle==2)yinc=-0.5*v;
              if(angle==3)yinc=-0.4*v;
              if(angle==4)yinc=-0.3*v;
              if(angle==5)yinc=0.3*v;
              if(angle==6)yinc=0.4*v;
              if(angle==7)yinc=0.5*v;
              if(angle==8)yinc=0.7*v;
              toggle=false;
              running=true;
              enough=false;
              e=0;
         public void move()
              if(running)
                   if(!toggle)
                        oldx=x;
                        oldy=y;
                        x+=xinc*v;
                        y+=yinc*v;
                   if(x<west && xinc<0)
                        int angle=(int)(Math.random()*8+1);
                        if(angle==1)yinc=-0.7*v;
                        if(angle==2)yinc=-0.5*v;
                        if(angle==3)yinc=-0.4*v;
                        if(angle==4)yinc=-0.3*v;
                        if(angle==5)yinc=0.3*v;
                        if(angle==6)yinc=0.4*v;
                        if(angle==7)yinc=0.5*v;
                        if(angle==8)yinc=0.7*v;
                       xinc=-xinc;
                        t.playClick();
                   else if(x>east-10)
                        x=east-10;
                        toggle=true;
                        running=false;
                        score++;
                        t.playBallout();
                   else if(y<north || y>south)
                       if(y<north&&yinc<0)
                             yinc=-yinc;
                        if(y>south&&yinc>0)
                             yinc=-yinc;
                        t.playClick();
                   else if(x>425 && xinc>0 && y>ry && y<rs+25)
                        if(y<ry+3)zone=1;
                        else if(y>=ry+3&&y<ry+6)zone=2;
                        else if(y>=ry+6&&y<ry+9)zone=3;
                        else if(y>=ry+9&&y<ry+12)zone=4;
                        else if(y>=ry+12&&y<ry+15)zone=5;
                        else if(y>=ry+15&&y<ry+18)zone=6;
                        else if(y>=ry+18&&y<ry+21)zone=7;
                        else if(y>=ry+21)zone=8;
                        if(zone==1)yinc=-0.7*v;
                        if(zone==2)yinc=-0.5*v;
                        if(zone==3)yinc=-0.4*v;
                        if(zone==4)yinc=-0.3*v;
                        if(zone==5)yinc=0.3*v;
                        if(zone==6)yinc=0.4*v;
                        if(zone==7)yinc=0.5*v;
                        if(zone==8)yinc=0.7*v;
                        xinc=-xinc;
                        t.playClick();
         public void toggle()
                        int i=t.j;
                        if(!enough)
                             if(i>-1&&i<11)ballcolor=Color.yellow;
                             if(i>10&&i<20){ballcolor=bgColor;e++;}
                        if (e>35){ballcolor=bgColor;enough=true;}
         public void paint(Graphics g)
              if(toggle)toggle();
              g.setColor(ballcolor);
              g.fillOval((int)x,(int)y,10,10);
    }

    I thought I should point out a few things
    The rule is that every class should have a no
    argument constructor that you need to specify
    explicitly if you have overloaded the default one.
    One of the reaons for that is the following:This is not true, there are many classes that do not have a no argument constructor (For example Integer). Integer is a perfect example of why you would not want a no argument constructor, having an Integer with no value is pointless (theres nothing you can do with it).
    public class A {
    private final int a ;
    public A(int b) {
    this.a = b ;
    }Now you realize that the variable
    n
    is getting initialized in the constructor. I see no variable n in the constructor but I take it you mean a
    Now if you
    refer to
    n
    somewhere else in you code you get a compile error because
    n
    might not have been initialized.This is not true, only local variables can cause a
    variable (a variable) might not have been initialized
    this is because all member fields are initialised with their default valuse. For example all pointers are intitialised to null, ints are intitialised to 0, booleans to false and so on.
    >
    So you need this:
    public class A {
    private final int a ;
    public A(int b) {
    this.a = b ;
    public A() {
    this(0) ; /* Calls the above constructor with some
    default parameter. */
    /* You can add some more code below but not above
    this(0) */
    Of course you know you are never calling the default
    constructor but it's still there so you need to
    ensure that the variables get initialized if some one
    calls it!
    As above classes can have no argument constructors
    Just add this to your code for example:
    public Tennisball() {
    this(0, 0, 0, 0, null) ;
    } Hope that helped you out!
    Thanks,
    Nikolas.
    PS any duke dollars would be much appreciated as i'm
    very poor at the moment :-)I dont mean to be offensive just thought I should clarify these points
    Michael

  • Problems with java constructor: "inconsistent data types" in SQL query

    Hi,
    I tried to define a type "point3d" with some member functions, implemented in java, in my database. Therefor I implemented a class Point3dj.java as you can see it below and loaded it with "loadjava -user ... -resolve -verbose Point3dj.java" into the database.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    package spatial.objects;
    import java.sql.*;
    public class Point3dj implements java.sql.SQLData {
    public double x;
    public double y;
    public double z;
    public void readSQL(SQLInput in, String type)
    throws SQLException {
    x = in.readDouble();
    y = in.readDouble();
    z = in.readDouble();
    public void writeSQL(SQLOutput out)
    throws SQLException {
    out.writeDouble(x);
    out.writeDouble(y);
    out.writeDouble(z);
    public String getSQLTypeName() throws SQLException {
    return "Point3dj";
    public Point3dj(double x, double y, double z)
    this.x = x;
    this.y = y;
    this.z = z;
    public static Point3dj create(double x, double y, double z)
    return new Point3dj(x,y,z);
    public double getNumber()
         return Math.sqrt(this.x*this.x + this.y*this.y + this.z*this.z);
    public static double getStaticNumber(double px, double py, double pz)
         return Math.sqrt(px*px+py*py+pz*pz);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Additionally, I created the corresponding type in SQL by
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CREATE OR REPLACE TYPE point3dj AS OBJECT EXTERNAL NAME
    'spatial.objects.Point3dj' LANGUAGE JAVA USING SQLDATA (
    x FLOAT EXTERNAL NAME 'x',
    y FLOAT EXTERNAL NAME 'y',
    z FLOAT EXTERNAL NAME 'z',
    MEMBER FUNCTION getNumber RETURN FLOAT
    EXTERNAL NAME 'getNumber() return double',
    STATIC FUNCTION getStaticNumber(xp FLOAT, yp FLOAT, zp FLOAT) RETURN FLOAT
    EXTERNAL NAME 'getStaticNumber(double, double, double) return double')
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    After that I tried some SQL commands:
    create table pointsj of point3dj;
    insert into pointsj values (point3dj(2,1,1));
    SELECT x, a.getnumber() FROM pointsj a;Now, the problem:
    Everything works fine, if I delete the constructor
    public Point3dj(double x, double y, double z)
    this.x = x;
    this.y = y;
    this.z = z;
    in the java class, or if I replace it with a constructor that has no input arguments.
    But with this few code lines in the java file, I get an error when executing the SQL command
    SELECT x, a.getnumber() FROM pointsj a;The Error is:
    "ORA-00932: inconsistent data types: an IN argument at position 1 that is an instance of an Oracle type convertible to an instance of a user defined Java class expected, an Oracle type that could not be converted to a java class received"
    I think, there are some problems with the input argument of the constructor, but why? I don't need the constructor in SQL, but it is used by a routine of another java class, so I can't just delete it.
    Can anybody help me? I would be very glad about that since I already tried a lot and also search in forums and so on, but wasn't successful up to new.
    Thanks!

    Dear Avi,
    This makes sense when it is a short code sample (and i think i've done that across various posts), but sometime this is too long to copy/paste, in these cases, i refer to the freely available code samples, as i did above on this forum; here is the quote.
    Look at examples of VARRAY and Nested TABLES of scalar types in the code samples of my book (chapter 8) http://books.elsevier.com/us//digitalpress/us/subindex.asp?maintarget=companions/defaultindividual.asp&isbn=9781555583293&country=United+States&srccode=&ref=&subcode=&head=&pdf=&basiccode=&txtSearch=&SearchField=&operator=&order=&community=digitalpress
    As you can see, i was not even asking people to buy the book, just telling them where to grab the code samples.
    I appreciate your input on this and as always, your contribution to the forum, Kuassi

  • Unusual use of interface defining static factory class with getInstance

    This question is prompted by a recent New to Java forum question ask about the differences between Interfaces and Abstract classes. Of course one of the standard things mentioned is that interfaces cannot actually implement a method.
    One of my past clients, one of the 500 group, uses interfaces as class factories. The interface defines a pubic static class with a public static method, getInstance, that is called to generate instances of a class that implements the interface.
    This architecture was very object-oriented, made good use of polymorphism and worked very well. But I haven't seen this architecture used anywhere else and it seemed a little convoluted.
    Here is a 'pseudo' version of the basic interface template and use
    -- interface that defines public static factory class and getInstance method
    public interface abc {
        public static class FactoryClass
            public static abc getInstance ()
                return (abc) FactoryGenerator(new abcImpl(), abc.class);
    -- call of interface factory to create an instance
    abc myABC = abc.Factory.getInstance();1. Each main functional area ('abc' in the above) has its own interface factory
    2. Each main functional area has its own implementation class for that interface
    3. There is one generator (FactoryGenerator) that uses the interface class ('abc.class') to determine which implementation class to instantiate and return. The generator class can be configured at startup to control the actual class to return for any given interface.
    I should mention that the people that designed this entire architecture were not novices. They wrote some very sophisticated multi-threaded code that rarely had problems, was high performance and was easy to extend to add new functionality (interfaces and implementing classes) - pretty much plug-n-play with few, if any, side-effects that affected existing modules.
    Is this a best-practices method of designing factory classes and methods? Please provide any comments about the use of an architecture like this.

    Thanks for the feedback.
    >
    I don't see how 'the generator class can be configured at startup to control the actual class to return for any given interface' can possibly be true given this pseudo-code.
    >
    I can see why that isn't clear just from what is posted.
    The way it was explained to me at the time is that the interface uses standard naming conventions and acts like a template to make it easy to clone for new modules: just change 'abc' to 'def' in three places and write a new 'defImpl' class that extends the interface and the new interface and class can just 'plug in' to the framework.
    The new 'defImpl' class established the baseline functionality that must be supported. This line
    return (abc) FactoryGenerator(new abcImpl(), abc.class);uses the initial version of the new class that was defined, 'abcImpl()', when calling the FactoryGenerator and it acted as a 'minimum version supported'. The generator class could use configuration information, if provided, to provide a newer class version that would extend this default class. Their reasoning was that this allowed the framework to use multiple versions of the class as needed when bugs got fixed or new functionality was introduced.
    So the initial objects would be an interface 'abc' and a class 'abcImpl'. Then the next version (bug fixes or enhancements) would be introduced by creating a new class, perhaps 'abcImpl_version2'. A configuration parameter could be passed giving 'abcImpl' as the base class to expect in the FactoryGenerator call and the generator would actually create an instance of 'abcImpl_version2' or any other class that extended 'abcImpl'.
    It certainly go the job done. You could use multiple versions of the class for different environments as you worked new functionality from DEV, TEST, QA and PRODUCTION environments without changing the basic framework.
    I've never seen any Java 'pattern' that looks like that or any pattern where an interface contained a class. It seemed really convoluted to me and seems like the 'versioning' aspect of it could have been accomplished in a more straightforward manner.
    Thanks for the feedback. If you wouldn't mind expanding a bit on one comment you made then I will mark this ANSWERED and put it to rest.
    >
    I don't mind interfaces containing classes per se when necessary
    >
    I have never seen this except at this one site. Would you relate any info about where you have seen or used this or when it might be necessary?

  • Applet - JavaPurse does not have a public constructor

    Hello,
    I'm starting playing with Javacard and I tried to compile a demo of Java purse Applet.
    I can compile it withou problem but once I try to start it with JBuilder 2006 I get the following error :
    The applet com.sun.javacard.samples.JavaPurse.JavaPurse does not have a public constructor com.sun.javacard.samples.JavaPurse.JavaPurse()
    Here is a part of my code
    public class JavaPurse extends javacard.framework.Applet {
    protected JavaPurse(byte[] bArray, short bOffset, byte bLength) {
    public static void install(byte[] bArray, short bOffset, byte bLength) {
    new JavaPurse(bArray, bOffset, bLength);
    Does anyone of you know why JBuilder is displaying this error message?
    Thanks in advance fo you reply.
    Alain.

    I don't think that's the error message; there is no class "java.awt.Applet". Are you sure it doesn't say "java.applet.Applet"?
    In any event, I don't know about javacard, but I suspect that javacard applets are not interchangeable with browser applets. My guess is that when JBuilder tries to build an applet, it's thinking about browser applets. Therefore it expects your applet to be a subclass of java.applet.Applet.
    I don't know how JBuilder works, but perhaps you can try using normal compilation instead of whatever JBuilder provides for applets.

Maybe you are looking for

  • Firewall blocks scanning from Epson Artisan 810

    I have a G5 Dual. I am just got an Epson Artisan All-in-One scan/fax/print machine with the ability to connect to my home network with wifi. I can scan with the Epson fine if I start the scanning software on my Mac and use the software controls from

  • Java.lang.NoSuchMethodError: oracle.adf.share.perf.StateTracker.isActive()Z

    I have recently upgraded from 10.1.3.1 to 10.1.3.3. The application uses form based authentication. The login worked fine in 10.1.3.1 but in the new version I get the following error when submitting the login details: 500 Internal Server Error java.l

  • IMac doesn't do scheduled shut down

    It's been getting hot here in the afternoons, and last week I came home from work and found my Al iMac 20" shut down. It was very hot in here, even after 8pm, so I figured it probably overheated and shut itself down. I've heard of overheating problem

  • MSI GP60 - Graphics question

    Hello, I bought a msi gp60 with a geforce gtx 740m, and i'm having some problems with games, they are not having a good performance, as if the dedicated graphics is never being used. I'm testing with a rocksmith 2014, which doesn't requires a heavy g

  • Load Issue to Cube

    Hi All, I need to load data to cube.there are two update rules. Can we load data from 2 update rules at a time to the same cube.Please suggest ASAP. Thanks Karuna