poniedziałek, 16 lipca 2012

Definitions

Software component - self-contained, reusable software unit that can be integrated into an application. Clients interact with components via well-defined contract.

sobota, 1 października 2011

mod_jk

Using mod_jk with apache 2.2.x and Tomcat


1. Download mod_jk connector from Apache Tomcat website ( http://tomcat.apache.org/connectors-doc/ )
2. Copy mod_jk.so library to modules directory of apache server.
3. Add to apache httpd.conf  file the following records (e.g. to the bottom of the file):


# Load mod_jk module
LoadModule jk_module modules/mod_jk.so 
# Declare the module for <IfModule directive>
#AddModule mod_jk.c 
# Where to find workers.properties
JkWorkersFile conf/workers.properties 
# Where to put jk logs
JkLogFile logs/mod_jk.log 
# Set the jk log level [debug/error/info]
JkLogLevel info 
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] " 
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories 
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T" 
# Send servlet for context /examples to worker named worker1
JkMount /* worker1 


4. Create workers.properties file:


  # Define 1 real worker using ajp13
  worker.list=worker1
  # Set properties for worker1 (ajp13)
  worker.worker1.type=ajp13
  worker.worker1.host=localhost
  worker.worker1.port=8009

5. Restart Apache Tomcat server.

Using mod_jk with apache 2.2.x and GlassFish 3.1


1. Do steps 1-4 as for Tomcat, and additionally:
2. Login to admin panel, and add JVM parameter:

-Dcom.sun.enterprise.web.connector.enableJK=8009
3. Restart server

Should work...

czwartek, 15 września 2011

IO

1. If directory in which the file should be created does not exist, method createNewFile() throws IOException.

        try {
            File f = new File("test", "test.txt");
            f.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
----------------------------------------------------------------------------------------------------------

2. Method renameTo accepts only File objects not String!

Prototype of the method:
public boolean renameTo(File dest)
----------------------------------------------------------------------------------------------------------

3.  If there is no directory structure, PrintWriter throws FileNotFoundException.


    try {
        PrintWriter pw = new PrintWriter("test/test/test.xml");
    }catch(FileNotFoundException e) {
        e.printStackTrace();
    }


  when the directory structure exists, the physical file is created by PrintWriter


    try {
        PrintWriter pw = new PrintWriter("test.xml");
    }catch(FileNotFoundException e) {
        e.printStackTrace();
    }
----------------------------------------------------------------------------------------------------------
4. flush() method is only available in writers: FileWriter, BufferedFileWriter, PrintWriter.
    flush() method is not available in readers.

poniedziałek, 12 września 2011

INITIALIZATION BLOCKS

1. It is legal to create instance of outer class within both: static and instance initialization blocks.
    E.g.:

    class X {
         { X x = new X();}
          static { X x = new X();}
      }

2. It is legal to use this in initialization (non-static) block:

    class X {

        int a;
       {this.a = 4;}
    }

3.

   class X{
       {x = 4}
        int x;
     
        public X() {
           System.out.println(x);         //prints 4
         }
    }



     class X{
       {x = 4}
        int x = 1;
     
        public X() {
           System.out.println(x);         //prints 1
         }
    }



     class X{

        int x=1;
       {x = 4}

        public X() {
           System.out.println(x);         //prints 4
         }
    }

   exactly the same is in case of static initialization blocks

niedziela, 11 września 2011

COLLECTIONS

1. Collections methods such as: sort(), binarySerach() or reverse() accepts only Lists not Sets.
Notice also that sort() and binarySerach() methods accept only Lists containing Comparable elements of the same type. If you try to sort lists containing non-comparable elements compilation fails. If the elements are of different types ClassCastException is thrown at runtime (unless you use your own Comparator).
To reverse order you do need have list of Comparable objects.

sobota, 10 września 2011

INNER CLASSES

1. Inner non-static class must not have static fields or methods.
2. Inner static class may have static fields and methods
3. It is illegal to add/hide static methods in anonymous inner class

eg.

class X {
      public static void do() {}
}

class Y{

public void method() {
    X x = new X() {
           public static void do() {}             //compile error
   };
}

GENERICS

1.

It is incorrect:


-using wildcards in type variable declaration, eg.


public <?> void methods() {
....
}


public <? extends T> void methods() {
....
}


public <? super Comparable> void method() {
....
}




- using super:

public <T super Comparable> T get() {
....
}


It is correct:

public <T> T get() {
....
}

public <T extends Comparable> T get() {
....
}
------------------------------------------------------------------------------------------------------------

2. Return types

Notice also that the last example method can return only T - type object.

public <T extends Comparable> T get() {
    return (T) new String("");  //correct
}

public <T extends Comparable> T get() {
    return new String("");                    //incorrect
}


public <T extends Comparable> T get(T t) {
        return t;           //correct
}
------------------------------------------------------------------------------------------------------------

3.

It is correct, int[] is a Object!
List<?> l = new ArrayList<int[]>();

This one is incorrect:
List<?> l = new ArrayList<int>();
------------------------------------------------------------------------------------------------------------

4. Compiler warning  is thrown every time one tries to assign non-generic element to generic one.


       public static void main(String... s) {
List<Object> l = null;
                ArrayList l2 = null;
                 l = l2;    //warning
}


the exception is ? :


        public static void main(String... s) {
List<?> l = null;
                ArrayList l2 = null;
                 l = l2;    //no warning
       }

------------------------------------------------------------------------------------------------------------
5. Cannot create objects using wildcards, eg.:

new ArrayList<?>();
new ArrayList<? extends Number>();
new ArrayList<? super Number>();
new HashMap<String, ? extends Number>();
------------------------------------------------------------------------------------------------------------

6. One has to declare the type before return type and after method modifiers, e.g.:


    public static <E> void add(E e) {}
    public <E> static  void add(E e) {}   //incorrect
    public static  void <E> add(E e) {}    //incorrect