Monday, June 17, 2013

Web Services are distributed applications that expose an xml interface defined in xml. As the key-role in Web Service is xml, its implementation and platform is independent.For example, implement the service in java and provide the WSDL url and Web Service fully qualified name to invoke the service from any other platform like .net, php etc(This can be explained in Invoking web service from client program. Also if you want to develop web service in different platform, using WSDL and Top-Down approach we can write the same service in different platforms like ,net, php and can be deployed on server and can be consumed from different paltform. Web Service mainly consists of Service Provider, Service Broker and Service Requester.













Service Provider:

Service Provider defines an abstract service description using the web services description language(WSDL). 
Service Provider provide concrete Service from the abstract service description yielding concrete service description in WSDL.
This Service can be published to registry such as UDDI(Universal Description, Discovery and Integration).

Service Requester: 

Service Requester use the registry to locate the service and using the service description to select and use a concrete implementation of the service.

Service Broker:

Service Broker allows a web service to be 
  • Registered
  • Categorized
  • Searched
Service Broker will allows Service Requester to search for particular service from the registry using Service Description(WSDL) and a Uniform Resource Identifier (URI) that points to the service itself and Service Requester  can then use this information to bind to service and invoke it.

I do hear many of them say installing Maven on the machines. But maven is not a software(not a .exe file or any executable file) to be installed in Operating system. Its a tool which will simplifies the build process.

Below are the steps required to configure Maven on Machines.

Tools Required

  1. JDK 1.6
  2. Maven 3.0.5

Configuring JDK

Install JDK and set the "JAVA_HOME" variable in Windows Environment and point to JDK folder.






















a) Download Maven from Maven Site . Select the version you desired to download.
e.g apache-maven-3.0.5-bin.zip
b) Extract the zip file to any of the drives let take it as C drive. That it, Installation is not required.
c) Configure M2_HOME in Windows environment, point it to Maven folder.





















d)Update path variable with "Maven bin folder path". With this you can run maven commands everywhere on the machine.





















e)Now verify whether the Maven is configured properly or not by running below command on command prompt.
 mvn -version
 If you see below meesage on command prompt,  then maven got installed properly.
E:\Tools\IDEs\eclipse-jee-indigo-SR2-win32\eclipse> mvn -version
Apache Maven 3.0.4 (r1232337; 2012-01-17 14:14:56+0530)
Maven home: C:\PROGRA~1\Apache Software Foundation\apache-maven-3.0.4
Java version: 1.7.0_03, vendor: Oracle Corporation
Java home: C:\PROGRA~1\Java\jdk1.7.0_03\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "x86", family: "windows" 

Saturday, June 15, 2013

Java Server Faces 2.0

JSF 2.0 is a MVC framework, which provide very rich reusable UI components for Java Web Applications. 
In JSF 2.0 for navigation in between pages we use annotations. but for complex navigation, suggested to configure the navigation in faces-config.xml.

Below tutorial will help you in step by step implementation of simple JSF application.

The required tools and Technologies for building the applicatoin are as below.

  1. JDK 1.6
  2. Eclipse 3.7
  3. JSF 2.1.7
  4. Tomcat 7.0
Creating workspace in Eclipse.

a) Create a Dynamic web project.

b) Select target environment as Apache Tomcat 7.0 and Configuration is JavaServer Faces v2.0 project .

c)Check generate web.xml deployment descriptor .

Check the JSF librarys above and click on finish button.
Create the package for managed bean and create a Java class by name HelloBean.java in that package.

Managed Beans

  1. Managed Bean is simple java bean class managed by the JSF framework. This class contains getter and setter methods of the attributes of the form, business logic or baking bean too.
  2. Managed bean is nothing but Model for UI component and can be accessed from JSF page.
  3. In JSF1.2 version , Managed Bean is configured in the faces-config.xml.
  <managed-bean>
  <managed-bean-name>helloWorld</managed-bean-name>
  <managed-bean-class>com.tutorialspoint.test.HelloWorld</managed-bean-class>
  <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>
4. JSF 2.0 on words, Managed beans can be registered using annotations.
package com.managedbean;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean
@SessionScoped
public class HelloBean  implements Serializable{

private static final long serialVersionUID = -3312527179446303127L;
private String message;

public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

JSF 2.0 Pages 

In JSF 2.0, jsf pages are created by XHTML file format. A file with .xhtml extension.
To import JSF 2.0 components in to jsf pages, declare the JSF namespace in the jsf pages at the top of the page.
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:c="http://java.sun.com/jsf/core"    
      xmlns:h="http://java.sun.com/jsf/html">
This tutorial contains two JSF pages, hello.xhtml and message.xtml. When user inputs message on hello.xtml page and submit the page. The message will be displayed on the message.xhtml page.

hello.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:c="http://java.sun.com/jsf/core"    
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Hello World</title>
    </h:head>
    <h:body>
    <h3>Hello World Example</h3>
    <h:form>
      <h:inputText value="#{helloBean.message}"></h:inputText>
      <h:commandButton value="Welcome Message" action="welcome"></h:commandButton>
    </h:form>
    </h:body>
</html>

message.xhtml 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  
      xmlns:h="http://java.sun.com/jsf/html">
     <h:head>
    <title>Message Page</title>
    </h:head>
    <h:body bgcolor="white">
    <h3>Hello World Example</h3>
    <h4>Welcome #{helloBean.message}</h4>
    </h:body>
</html>

JSF Expression Language 

In the above xhtml pages, #{..} this is the JSF expression language.  #{helloBean.message}, when page is submitted from hello.xhtml, container will find the corresponding Managed bean helloBean and set the value entered in the text box via setMessage() method. When message.xhtml page is displayed, container will find the same helloBean session and display the submitted text in message.xhtml page via getMessage() method.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>sampleJSF</display-name>
  <welcome-file-list>
    <welcome-file>faces/hello.xhtml</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
  </servlet-mapping>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <description>
This parameter tells MyFaces if javascript code should be allowed in
the rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default is 'true'</description>
    <param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <description>
If true, rendered HTML code will be formatted, so that it is 'human-readable'
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default is 'true'</description>
    <param-name>org.apache.myfaces.PRETTY_HTML</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
    <param-value>false</param-value>
  </context-param>
  <context-param>
    <description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default is 'false'
</description>
    <param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
    <param-value>true</param-value>
  </context-param>
  <listener>
    <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
  </listener>
</web-app>

Now deploy the code in tomcat server, when code is published it open the hello.xhtml page.
Note : In the above image , notice container creating instance of HelloBean on displaying the hello.xhtml.

On entering message and submitting the page, message.xhtml page will be displayed with entered message.


Friday, June 14, 2013

The Number object contains only the default methods that are part of every object's definition.

MethodDescription
constructor()Returns the function that created this object's instance. By default this is the Number object.
toExponential()Forces a number to display in exponential notation, even if the number is in the range in which JavaScript normally uses standard notation.
toFixed()Formats a number with a specific number of digits to the right of the decimal.
toLocaleString()Returns a string value version of the current number in a format that may vary according to a browser's locale settings.
toPrecision()Defines how many total digits (including digits to the left and right of the decimal) to display of a number.
toString()Returns the string representation of the number's value.
valueOf()Returns the number's value.

Sunday, June 9, 2013

What are legacy classes and interfaces in Java?

Before Java 1.2 version there is no Collection framework in java, instead java consists of some classes and interfaces to hold the objects those are called Legacy Classes and Interface
Legacy Class :
  • Dictionary
  • HashTable
  • Properties
  • Stack
  • Vector
Legacy Interface :
  • Enumeration
Dictionary :
Dictionary is a abstract class, which holds the data as Key/value pair. It works as Map collection.

The abstract methods and its description that are available in Dictionary class are in below figure.


Dictionary Class






















HashTable :

  • HashTable is a part of java.util package and it is a concrete class which extends the Dictionary class.
  • In Java 1.2 version on ward HashTable class implemented the Map interface and it is as part of Collection Framework.
  • HashTable is synchronized.

Properties :

Properties class will hold the set of properties in Key/value pair. Properties class extends HashTable class . This class is thread-safe , multiple threads can share single Properties object without making externally Synchronization.

Stack :

Stack represents the Last-In-First-Out(LIFO). Stack class extends the Vector class.

Vector :

Vector class is a grow-able array and is similar to ArrayList class with two difference. 
Vector is a Synchronized.
Vector is used where programmer didn't have knowledge of what the size of the Array is.It means you can ignore the size of the Vector, even still Vector will work without any exceptions.


Enumeration :

A class that implements Enumeration interface will generate series of elements, one at a time.
  • This interface is used to enumerate elements of Vector, keys/values of HashTable and properties in the Properties class.
  • Enumeration operations are duplicated by the Iterator interface and some more operations like remove() etc are added. For new implementations should consider Iterator instead of Enumeration.

Saturday, June 1, 2013

What is serialization?

Serialization is the conversion of an object to a series of bytes, so that the object can be easily saved to persistent database or streamed across a communication media. The byte stream can be serialized and converted into original object.

What is the difference between web server and app server?

A Web server exclusively handles HTTP requests, whereas an application server serves business logic to application programs through any number of protocols.

What are difference between final finally and finalize?

final :final keyword is used along the variables in java. If you make variable as final, then it value can't be alerted.
If method is final, then that method can't be overridden.
If a class is final, then that class can't be extended.

finally : finally is used in the Exception handling using try , catch and finally blocks.
finally block has some special features like, finally block will be executed all the time even if the exception is occurred in the method.
finally block is mainly used to close/kill the resources opened in the try or any part of the method body.
finally block wont be called if JVM got killed wanted by using System.exist();

finalize() : finalize() method is called Garbage collection thread to collect the un-referenced java objects and 

What is a transient variable in Java?

A transient variable is a variable that may not be serialized. If you don't want some field to be serialized, you can mark that field transient or static.

What are different types of access modifiers?

Access specifiers are keywords that determine the type of access to the member a class.
Public      
Protected
Private
Default

What is String Pooling?
Below prints true,
String str1="st"+"r";
String str2="s"+"tr";
System.out.println(str1==str2);
 When compiler optimizes your string literals, it sees that both str1 and str2 have same value and thus you need only one string object.
Name 'string pool' comes from the idea that all already defined string are stored in some 'pool' and before creating new String object compiler checks if such string is already defined.As result, both str1 and str2 point to the same object and some little memory saved.

Why String id Immutable?

The mail reason behind the String is immutable is
a) Security - As most of the parameters requried in our dialy life programming such as database connection url, port number, host name, file name supplied to the I/O operation in creating of files, userid and passwords all the above will be declared by String object because, as String is final and cannt be changed in middle of code excution.
b) String Pooling - Name 'string pool' comes from the idea that all already defined string are stored in some 'pool' and before creating new String object compiler checks if such string is already defined
c) Faster - As String variables cannot be manuplated, its hashcode will be one, so it can be retrieved fast every time

Friday, August 6, 2010

Encapsulation:
Means putting the data and the function that operates on that data in a single unit(information hiding) .Encapsulation prevents clients from seeing its inside view, where the behavior of the abstraction is implemented.
Encapsulation is the mechanism that binds together code and the data it manipulates,and keeps both safe from outside interference and misuse.in java encapsulation is achieved by making use of access modifiers( keeping variables as private and providing public getters and setters.

Eg:-
automatic transmission of an automobile.
It encapsulates lots of information about the engine, such acceleration, the pitch of the surface , and the position of the shift
lever. Being a user,we have only one method of affecting this complex encapsulation: moving the gear-shift lever.

Inheritance:
Inheritance is the process by which one object acquires the properties of another object.

Eg:-Vehicle->motorized->4wheeled.

Polymorphism:
Polymorphism (from the Greek, meaning “many forms”) is a feature that allows one interface to be used for a general class of actions.

Eg. Car's steering ->one interface many implementations(power or rack and pinion)

Abstraction:
Means hiding the internal details and just exposing the functionality.

Eg:-When we change the gear of a car, we know the gears will be changed without knowing how they are functioning internally.
Abstraction focuses on the outside view of an object (i.e. the interface).Kindle Wireless Reading Device, Free 3G, 6" Display, White - 2nd Generation

Followers

Is this helps u

Subscribe to RSS Feed