Showing posts with label Keyword. Show all posts
Showing posts with label Keyword. Show all posts

Monday, 23 May 2016

'final' keyword

A 'final' keyword can be applied on a variable
Maybe a class variable or an instance variable. It means that once the variable is initialized, its value cannot be modified, or changed. Meaning that its value is considered as a constant. Therefore, a final variable must be initialized, as it is declared,  Otherwise, compiler will pop up an error. It won't be automatically initialized as a null or a zero by Java.

final class variable should be initialized in a static block; final instance variable can be initialized in a constructor.

A 'final' keyword can be applied on a method 
Maybe a class method or an instance method. Final methods can be inherited by sub-classes. However, for a class method it means that the method cannot be hidden; for an instance method it means that the method cannot be overridden.

A 'final' keyword applied on a class 
It means that the class cannot be extended; there is no kids allowed.


/**
 *
 * @author YNZ
 */
public final class KeyFinal {

    public static final int A = 10;
    public static final int B;
    public final int x;

    static {
        B = 30;
    }

    public KeyFinal() {
        this.x = 20;
    }

    public final void doSome() {
        System.out.println("" + this.x);
    }

    public static void main(String[] args) {
        KeyFinal kf = new KeyFinal();
        System.out.println("" + A);
        kf.doSome();

    }

}


Thursday, 19 May 2016

keyword strictfp


The strictfp keyword is used to force the precision of floating point calculations (float or double) in Java conform to IEEE’s 754 standard, explicitly. Without using strictfp keyword, the floating point precision depends on target platform’s hardware, i.e. CPU’s floating point processing capability. In other words, using strictfp ensures result of floating point computations is always same on all platforms.

The strictfp keyword can be applied for classes, interfaces and methods.


Rules


  • strictfp cannot be applied for constructors.
  • If an interface or class is declared with strictfp, then all methods and nested types within that interface or class are implicitly strictfp.
  •  strictfp cannot be applied for interface methods.

Can Jackson Deserialize Java Time ZonedDateTime

Yes, but must include JSR310. Thus ZonedDateTime can be deserialized directly from JSON response to POJO field. <dependency> <g...