3 September 2017

Method Overriding VS Method Hiding

We Know that the Polymorphism is of two types
1.Static
2.Dynamic

In Dynamic Polymorphism the method which executes will be decided based on the object stored in the reference variable.

This is regarding instance methods

public class Animal {
    public void foo() {
        System.out.println("Animal");
    }
}

public class Cat extends Animal {
    public void foo() { // overrides Animal.foo()
        System.out.println("Cat");
    }
}

Then the following will happen:

class Test{

public static void main(String args[]){
Animal a = new Animal();
Animal b = new Cat();
Animal c = new Cat();
Animal d = null;

a.foo(); // prints Animal
b.foo(); // prints Cat
c.foo(); // prints Cat
d.foo(): // throws NullPointerException
    }
}

Instance methods, which are polymorphic and are thus overridden. The method called depends on the concrete, run time type of the object:

But for static methods it won't work.
The static methods will executes as follows....

public class Animal {
    public static void foo() {
        System.out.println("Animal");
    }
}

public class Cat extends Animal {
    public static void foo() { // overrides Animal.foo()
        System.out.println("Cat");
    }
}

class Test{

public static void main(String args[]){
Animal a = new Animal();
Animal b = new Cat();
Cat c = new Cat();
Animal d = null;

a.foo(); // prints Animal
b.foo(); // prints Animal
c.foo(); // prints Cat
d.foo(): // throws NullPointerException
      }
}

Here, Cat.foo() is said to hide Animal.foo(). Hiding does not work like overriding, because static methods are not polymorphic.
This is called Method Hiding Concept.

Calling static methods on instances rather than classes is a very bad practice, and should never be done.

23 July 2017

SOAP Web Services Example Using JAX-WS

Here is an Example for SOAP Web Services using JAX-WS

The Project Architecture is like this



Its a normal Java Project:
From Eclipse file--new--java project--SoapWSProj
And you know how to create the packages, classes etc. It has no external jars included.

ws.Demo.java

package ws;

import javax.jws.*;

@WebService
public interface Demo {

@WebMethod
public String helloWorld();

@WebMethod
public String hi(String name);

}

ws.DemoImpl



 * ProductWS.java

package ws;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;

import entities.Product;

@WebService
public interface ProductWS  {

@WebMethod
    public Product find() ;

@WebMethod
public List<Product> findAll();
}









2 July 2016

Java Introduction

Java




Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!


 Java is free to download. Get the latest version at java.com. or from www.oracle.com/technetwork/java/index.html


If you are building an embedded or consumer device and would like to include Java, please contact Oracle for more information on including Java in your device




Gosling is generally credited with having invented the Java programming language in 1994. He created the original design of Java and implemented the language's original compiler and virtual machine. Gosling traces the origins of the approach to his early graduate-student days, when he created a pseudo-code (p-code) virtual machine for the lab's DEC VAX computer, so that his professor could run programs written in U C SD Pascal. Pascal compiled into p-code to foster precisely this kind of portability. In the work leading to Java at Sun, he saw that architecture-neutral execution for widely distributed programs could be achieved by implementing a similar philosophy: always program for the same virtual machine.
For his achievement the National Academy of Engineering in the United States elected him as a Foreign Associate member. He has also made major contributions to several other software systems, such as NeWS and Gosling Emacs. He co-wrote the "bundle" program, a utility thoroughly detailed in Brian Kernighan and Rob Pike's book The Unix Programming Environment.

JAVA SetUp in System

JAVA ENVIRONMENT SET UP  =========================== In System Variables JAVA_HOME : C:\Program Files\Java\jdk1.8.0_144 JDK_HOME  : %J...