View RSS Feed

Hibernate

  1. Packages, accessibility/visibility, synthetic access and protected constructors

    by , 08-12-2011 at 07:21 PM
    In Java it is common to use packages, especially for libraries.
    Two common packages, that are built in to Java, are java.io and java.util.
    (Another, even more common is java.lang, but that one is imported automatically.)

    Before you can use a package [without using the reflection classes] you most import it in
    the file (not class) that uses it. To import the package java.io, you add the line
    Java Code:
    import java.io.*;
    just below your package line (if any; otherwise ...
    Categories
    Java's syntax
  2. Linux terminal magick, part 2

    by , 08-12-2011 at 05:05 AM
    In the previous part if ”Linux terminal magick” we show how to let use user use ^C and ^\ in the terminal, that was the last part of creating a graphical terminal user interface. The parts are [almost] not ordered!

    For this part we add two more functions:
    Java Code:
    /**
     * Sets the the value of the ECHO flag; iff on the input to the terminal will be echoed back while typing.
     * This can be used to hide what the user is type, for example when a password is requested.
    ...

    Updated 08-12-2011 at 05:42 AM by Hibernate

    Categories
    Terminal cues , Linux
  3. The Multiton pattern

    by , 08-12-2011 at 04:39 AM
    The Multiton pattern is a pattern missing from ”the pattern bible”. It is extensive to dual layer (and beyond), but that is left for you to use intuitively when needed, it is not too difficult to do so.

    The Multiton pattern is an extension of Singleton pattern.
    Multiton lets you create and get any number of instances, they are distinguished by keys,
    so if you want instance "a" it creates it for you the first time, and returned the created instance the next ...

    Updated 08-12-2011 at 06:16 PM by Hibernate

    Categories
    Patterns
  4. The Singleton pattern

    by , 08-12-2011 at 04:29 AM
    In mathematics a singleton (not to be confused with a simpleton) is a set with exactly one element.
    In computer science Singleton is a pattern which enforces the existence of only up to one instance of a class.

    Singleton is sometimes considered an anti-pattern, and it's famous for being considered unnecessary in the world of Python (where you duck type).
    Singleton is however useful, it is a nice and clean why to restrict the number of instances, to only one.
    In ...

    Updated 08-12-2011 at 06:13 PM by Hibernate (typo)

    Categories
    Patterns
  5. Linux terminal magick, part 1

    by , 08-12-2011 at 01:15 AM
    Are you a hardcore GNU/Linux user like me?
    Then you are probably sick of Java (natively) not letting you print in the terminal with colours.
    In a series of Web logs, I will describe how to, in GNU/Linux, print in the terminal with colours and other stuff.
    Keep in mind that you need a TTY (e.g. gnome-terminal, xterm, Linux VT (linux)), Eclipse's built in console will not do.

    We will begin with letting Java accept ^C and ^\ (also know as ^4) from the terminal. ...

    Updated 08-12-2011 at 05:42 AM by Hibernate

    Categories
    Terminal cues , Linux
  6. Variadic functions (varargs)

    by , 08-12-2011 at 12:47 AM
    Ever heard of variadic functions of varargs.
    It is my favourite synthetic sugar (although I must admit i prefer cane sugar).

    Variadic functions have undefine arity (the parameter is called a "vararg" (variadic argument)), meaning
    that it lets you use any amount of parameters when invoking it.

    For example:
    Java Code:
    public class MyClass
    {
        private static void print(final String prefix, final int... lines)
        {
    ...

    Updated 08-12-2011 at 05:44 AM by Hibernate

    Categories
    Java's syntax
  7. Unusual members, part 2

    by , 08-12-2011 at 12:22 AM
    Just like there is a static, otherwise headless, method, the class initialiser, this is an object initialiser (or just initialiser), that is a non-static and completely headless.

    Java Code:
    public class MyClass
    {
        public static class Subclass extends MyClass
        {
            {
                System.out.println("Subclass Initialiser 1");
            }
            public Subclass()
            {
                System.out.println("Subclass
    ...

    Updated 08-12-2011 at 05:45 AM by Hibernate

    Categories
    Java's syntax
  8. Unusual members, part 1

    by , 08-12-2011 at 12:09 AM
    Did you ever want to run something the first, and only first, time a class was being used.
    Perhaps wanted to do some complex calculations and assign it to a constant.

    One way to do this is by writing, for example:
    Java Code:
    public class YourClass
    {
        public static final int YOUR_CONSTANT = constantValue();
    
        private static int constantValue()
        {
            int value1 = 0, value2 = 1;
            int value = 0;
            for
    ...

    Updated 08-12-2011 at 05:45 AM by Hibernate

    Categories
    Java's syntax
  9. Legal forward reference assignment weirdness on declarations

    by , 08-11-2011 at 11:38 PM
    Observer the glorious code by your's truly Hibernate:

    Java Code:
    public class YetAnotherClass
    {
        //public static final int YET_ANOTHER_CONSTANT = YET_ANOTHER_CONSTANT; //Compile-time error: illegal forward reference
        public static final int ANOTHER_CONSTANT = YetAnotherClass.ANOTHER_CONSTANT; //OK!
    
        //public int yetAnotherVariable = yetAnotherVariable; //Compile-time error: illegal forward reference
        public int anotherVariable = this.anotherVariable
    ...

    Updated 08-12-2011 at 05:46 AM by Hibernate

    Categories
    Java's syntax