Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Thursday, July 21, 2016

Java version history from 1.4 to 1.8




1) Java 4 Features :
The important feature of J2SE 4 is assertions. It is used for testing.


  • Assertion (Java 4)




2) Java 5 Features :
The important features of J2SE 5 are generics and assertions. Others are autoboxing, enum, var-args, static import, for-each loop (enhanced for loop etc.


  • For-each loop (Java 5)
  • Varargs (Java 5)
  • Static Import (Java 5)
  • Autoboxing and Unboxing (Java 5)
  • Enum (Java 5)
  • Covariant Return Type (Java 5)
  • Annotation (Java 5)
  • Generics (Java 5)



Monday, October 13, 2014

Try-with-resources in Java 7

Try-with-resources in Java 7

Try-with-resources in Java 7 is a new exception handling mechanism that makes it easier to correctly close resources that are used within a try-catch block.

Resource Management With Try-Catch-Finally, Old School Style 

Managing resources that need to be explicitly closed is somewhat tedious before Java 7.
private static void printFile() throws IOException {
    InputStream input = null;

    try {
        input = new FileInputStream("file.txt");

        int data = input.read();
        while(data != -1){
            System.out.print((char) data);
            data = input.read();
        }
    } finally {
        if(input != null){
            input.close();
        }
    }
}
The code marked in bold is where the code can throw an Exception. As you can see, that can happen in 3 places inside the try-block, and 1 place inside the finally-block.

The finally block is always executed no matter if an exception is thrown from the try block or not. That means, that the InputStream is closed no matter what happens in the try block. Or, attempted closed that is. TheInputStream's close() method may throw an exception too, if closing it fails.

Thursday, September 11, 2014

Method Overriding with Exception Handling

Method Overriding with Exception Handling

There are many rules if we talk about method overriding with exception handling. The Rules are as follows:
  • If the super class method does not declare an exception
    • If the super class method does not declare an exception, subclass overridden method cannot declare the checked exception but it can declare unchecked exception.
  • If the super class method declares an exception
    • If the super class method declares an exception, subclass overridden method can declare same, subclass exception or no exception but cannot declare parent exception. 

Friday, January 31, 2014

What is different between web server and application server?

The different between web server and application server :

A web server responsibility is to handler HTTP requests from client browsers and respond with HTML response. A web server understands HTTP language and runs on HTTP protocol.

Apache Web Server is kind of a web server and then we have specific containers that can execute servlets and JSPs known as servlet container, for example Tomcat.

Application Servers provide additional features such as Enterprise JavaBeans support, JMS Messaging support, Transaction Management etc. So we can say that Application server is a web server with additional functionalities to help developers with enterprise applications.

Tuesday, December 17, 2013

Abstract Factory Pattern

Abstract Factory patterns works around a super-factory which creates other factories. This factory is also called as Factory of factories. This type of java design pattern comes under creational pattern as this pattern provides one of the best ways to create an object. 
In Abstract Factory pattern an interface is responsible for creating a factory of related objects, without explicitly specifying their classes. Each generated factory can give the objects as per the Factory pattern.

Implementation of Abstract Factory Pattern

We're going to create a Shape and Color interfaces and concrete classes implementing these interfaces. We creates an abstract factory class AbstractFactory as next step. Factory classesShapeFactory and ColorFactory are defined where each factory extends AbstractFactory. A factory creator/generator class FactoryProducer is created.
AbstractFactoryPatternDemo, our demo class uses FactoryProducer to get a AbstractFactory object. It will pass information (CIRCLE / RECTANGLE / SQUARE for Shape) to AbstractFactory to get the type of object it needs. It also passes information (RED / GREEN / BLUE for Color) to AbstractFactory to get the type of object it needs.

Thursday, December 12, 2013

static keyword in java

The static keyword is used in java mainly for memory management. We may apply static keyword with variables, methods, blocks and nested class. The static keyword belongs to the class than instance of the class.
The static can be:
  1. variable (also known as class variable)
  2. method (also known as class method)
  3. block
  4. nested class

Tuesday, December 10, 2013

Modifiers In Java

It is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers:

  • Access Control Modifiers : default, public, protected, private
  • Non Access Modifiers : static, final, abstract, synchronized

Monday, December 09, 2013

Difference between length and length() in Java

length - This is a instance variable of array in java. It returns the length of an array, number of elements stored in an array.

length() -  This is a method in java. It is a static method of String class. It returns the length of a string object.

Tuesday, December 03, 2013

JAVA main method

1. You can have more than one method named main(...), as long as they all have different method signatures.

i.e.  Note that the final main(...) method in the demonstration code below will not compile, as a method's return type does not count as part of its signature.

public class ManyMains {
    public static void main(String[ ] args) {  }

    public static void main(String args) {  }

    public void main(String[ ][ ] args) {  }
    // public static String main(String[  ] args)  { return " ";  }          // will not compile: return type doesnt count in signature
}

Constructors

1 You cannot invoke constructors directly except from within other constructors.

2  Constructors invoking each other - by either super( ) or this(...) -  must be the first statement in the constructor code body.  Explicitly calling super( ) is entirely optional.  The JVM will do it anyway.

Java Inner Classes

Inner classes, also called Nested Classes, are nothing but classes that are defined within other classes. The nesting is a relationship between classes, not objects.
Inner classes have clearly two benefits, name control & access control. In Java, this benefit is not as important because Java packages give the name control.
Java inner classes have feature that makes them richer and more useful. An object of an inner class has an implicit reference to the outer class object that instantiated it. Through this pointer, it gains access to any variable of the outer object. Only static inner classes don’t have this pointer. It is actually invisible when we write the code, but compiler takes care of it. Inner classes are actually a phenomenon of the compiler and not the JVM.

Eclipse “Not Declare Static Final SerialVersionUID” Warning


Whenever you write a Java class in Eclipse which implements java.io.Serializable interface, you’ll get this warning:
The serializable class XXXX does not declare a static final serialVersionUID field of type long

Why do we need serialVersionUID?

Understanding Essential DNS Record Types for Web Administrators

  Understanding Essential DNS Record Types for Web Administrators Introduction The Domain Name System (DNS) acts as the backbone of the inte...