Friday, November 14, 2008

Final, Finally and Finalize

Here I would like to discuss about some Keywords of Core Java. Here I am going to give you the basic idea about these keywords. This question is frequently asked in the interviews in the earlier stage of Career. Ok let's get into the business.

Final : Final is a keyword can be used in 3 scenarios. Firstly declare a class as Final as given below.

"public final class Test " If you declare a class like this that means you can not extend this class. That means "public class TestTwo extends Test" will NOT compile.
Second, You can declare method as final. If you declare a method final, you can't override the Final method in your subclasses. what if you do overload the final method. Yes, you can over load the final method.
Lastly, if the Final variable is declared you can not change the value of this. This indirectly means once you assign the value to any Final variable you can not change or modify the value of it. Generally these final variables are used while declaring constants with the combination of Static, Eg : PI value.

Finally : Finally is a block used in Exception handling. We all know about try and catch blocks where we put the statements where error could occur in try block and and we catch the exceptions in the catch block by passing the Exception object as argument. after all catch blocks you can put this Finally block. This will be executed in either case of exception. So, you can put the mandatory closing statements of files or connections you opened in the beginning.

Finalize() : Finalize is a method of class java.lang.object. This has to be overridden in the class you want according to your requirement. This method will be executed before the object get garbage collected. So, this would be executed when there will be no reference remain for the object.
protected void finalize() throws Throwable {
try {
close(); // close open files
} finally {
super.finalize();
}
}

Saturday, October 18, 2008

Read Only

Read Only

We often get in trouble with small problems like making the things read only.
This is very useful to restrict the concurrency issues it could be a request or a result set or a data entry like HTML.
Even some times we want to make the files read only too on the fly.

This sample code makes a file read only.

import java.io.File;

public class ReadOnlyExp {
public static void main(String[] args) {
File file=new File("c:\\MyFile");
file.setReadOnly();
}
}

How to make the HTML element read only.

READONLY = true;


You can also use DISABLED=”true” for any HTML Element.



Hope this was useful.

Thursday, July 17, 2008

People Soft Overview

PeopleSoft is a pioneer in creating an application which integrates all the HR functions of an enterprise into one.PeopleSoft founded by David Duffield in 1987 became one of the most implemented ERP solutions for HR and Finance across the world. PeopleSoft provides ERP packages for HR, Finance, CRM, Student Administration, Learning and Performance managements for Enterprises and Universities.

PeopleSoft when initially launched was a client server architecture based system. However, the entire suite currently is migrated and works on web based architecture called the PIA (Pure Internet Architecture). It provides for all the HR functionalities like Recruting, Time and Labor, Payroll, Benefits etc. It also provides extensions for each country payroll so that an employee's pay is calculated based on tax laws of his location. PeopleSoft can be implemented on a variety of Database platforms like Informix, DB2, MS-SQL Server, Sybase and Oracle.It also provides ease for the developers to customize the solution with an integrated development environment. The solution can be customized as per the needs of the organization by changing the configuration from the web or changing the code using the IDE.

PeopleSoft PIA uses a three tier architecture where the webserver interacts with the application server and application server interacts with the database server. The typical request is handled in the following manner. A user requests for a page on the application which is sent in HTTP format to the webserver. The webserver inturn sends the message to the application server using JOLT Api. The application server retrieves the information regarding the webpage from the database and sends information to the webserver again via JOLT. The webserver then creates the necessary HTML for the page dynamically and sends it to the user. In Peoplesoft all the information regarding webpages, the code etc is all stored in the database and not in individual files. All the information can be accessed and modified easily from the IDE. The changed information can be immediately viewed from the webclient and validated.PeopleSoft uses BEA Tuxedo Server as Application server for all its applications.

PeopleSoft was the pioneer in providing effective dated logic in ERP systems. The effective dated logic simplifies and enhances the way of storing history information about a particular object of data. For example, all the job history of the employee can be stored in a single table where Effective date also is a key along with the Employee Identification number. The effective dated logic is being used by all the ERP systems of the current day to maintain histories of same data.

With the launch of latest versions of applications, Peoplesoft also moved the internal technology completely to an Object Oriented manner which makes the access of data very secure and also making the solution more configurable and easily customizable according to customer's needs from the web.PeopleSoft HR and Finance systems continues to zoom forward into the next decade with more implementations and is being used despite the take over by Oracle.

This Article is Written by Rahul Pantula, who has wast experience and expertise in People Soft for around 8 years. He developed and designed solutions for the organizations like Polaris, Accenture and IBM.

Tuesday, July 15, 2008

HIBERNATE – With Example

Hibernate in Short:

Hibernate is an open source object/relational mapping tool for Java. Hibernate lets you develop persistent classes following common Java idiom - including association, inheritance, polymorphism, composition and the Java collections framework.
Hibernate not only takes care of the mapping from Java classes to database tables (and from Java data types to SQL data types), but also provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC.
Hibernates goal is to relieve the developer from 95 percent of common data persistence related programming tasks.


Overview:


High level architecture of Hibernate can be described as shown in following illustration.



Hibernate makes use of persistent objects commonly called as POJO (POJO = "Plain Old Java Object".) along with XML mapping documents for persisting objects to the database layer. The term POJO refers to a normal Java objects that does not serve any other special role or implement any special interfaces of any of the Java frameworks (EJB, JDBC, DAO, JDO, etc...).

Rather than utilize byte code processing or code generation, Hibernate uses runtime reflection to determine the persistent properties of a class. The objects to be persisted are defined in a mapping document, which serves to describe the persistent fields and associations, as well as any subclasses or proxies of the persistent object. The mapping documents are compiled at application startup time and provide the framework with necessary information for a class. Additionally, they are used in support operations, such as generating the database schema or creating stub Java source files.

Typical Hibernate code

sessionFactory = new Configuration().configure().buildSessionFactory();

Session session = sessionFactory.openSession();

Transaction tx = session.beginTransaction();

Customer newCustomer = new Customer();
newCustomer.setName("New Customer");
newCustomer.setAddress("Address of New Customer");
newCustomer.setEmailId("NewCustomer@NewCustomer.com");

session.save(newCustomer);
tx.commit();

session.close();

First step is hibernate application is to retrieve Hibernate Session; Hibernate Session is the main runtime interface between a Java application and Hibernate. SessionFactory allows applications to create hibernate session by reading hibernate configurations file hibernate.cfg.xml.

After specifying transaction boundaries, application can make use of persistent java objects and use session for persisting to the databases.

Features:

Ø Transparent persistence without byte code processing

Ø Object-oriented query language

Ø Object / Relational mappings

Ø Automatic primary key generation

Ø Object/Relational mapping definition

Ø HDLCA (Hibernate Dual-Layer Cache Architecture)

Ø High performance

Ø J2EE integration

We will take up an simple java example that authenticates users based on the credentials to get started with hibernate.

Preparing Database

Let’s consider a simple database schema with a singe table as APPLABSUSER.

CREATE TABLE `applabsuser` (
`USER_ID` int(11) NOT NULL default '0',
`USER_NAME` varchar(25) NOT NULL default '',
`USER_PASSWORD` varchar(25) NOT NULL default '',
`USER_FIRST_NAME` varchar(25) NULL default,
`USER_LAST_NAME` varchar(25) NULL default,
`USER_EMAIL` varchar(25) NULL default,
`USER_CREATION_DATE` date NULL default,
`USER_MODIFICATION_DATE` date NULL default,
PRIMARY KEY (`USER_ID`),
UNIQUE KEY `USER_NAME` (`USER_NAME`)
) ;

Creating persistent java objects

Hibernate works best with the Plain Old Java Objects programming model for persistent classes.
Hibernate is not restricted in its usage of property types, all Java JDK types and primitives (like String, char and Date) can be mapped, including classes from the Java collections framework. You can map them as values, collections of values, or associations to other entities. The id is a special property that represents the database identifer (primary key) of that class, Hibernate can use identifiers only internally, but we would lose some of the flexibility in our application architecture.
No special interface has to be implemented for persistent classes nor do you have to subclass from a special root persistent class. Hibernate also doesn't require any build time processing, such as byte-code manipulation, it relies solely on Java reflection and runtime class enhancement (through CGLIB). So, without any dependency of the POJO class on Hibernate, we can map it to a database table.
Following code sample represents a java object structure which represents the AppLabsUser table. Generally these domain objects contain only getters and setters methods. One can use Hibernate extension toolset to create such domain objects.

AppLabsUser.java

package org.applabs.quickstart;

import java.io.Serializable;
import java.util.Date;
import org.apache.commons.lang.builder.ToStringBuilder;

public class AppLabsUser implements Serializable {

public void setName(String name) {
private Long id;/** identifier field */

/** persistent fields*/
pivate String userName;
private String userPassword;
private String userFirstName;
private String userLastName;
private String userEmail;
private Date userCreationDate;
private Date userModificationDate;

/** full constructor */
public Applabsuser(String userName, String userPassword, String userFirstName, String userLastName, String userEmail, Date userCreationDate, Date userModificationDate) {
this.userName = userName;
this.userPassword = userPassword;
this.userFirstName = userFirstName;

this.userLastName = userLastName;
this.userEmail = userEmail;
this.userCreationDate = userCreationDate;
this.userModificationDate = userModificationDate;
}

/** default constructor */
public Applabsuser() {}

public Long getId() {return this.id;}
public void setId(Long id) {this.id = id;}

public String getUserName() {return this.userName;}
public void setUserName(String userName) {
this.userName = userName;}

public String getUserPassword() {return this.userPassword;}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;}

public String getUserFirstName() {return this.userFirstName;}
public void setUserFirstName(String userFirstName) {
this.userFirstName = userFirstName;}

public String getUserLastName() {return this.userLastName;}
public void setUserLastName(String userLastName) {this.userLastName = userLastName;}

public String getUserEmail() {return this.userEmail;}
public void setUserEmail(String userEmail) {this.userEmail = userEmail;}

public Date getUserCreationDate() {return this.userCreationDate;}
public void setUserCreationDate(Date userCreationDate) {
this.userCreationDate = userCreationDate;}

public Date getUserModificationDate() {
return this.userModificationDate;}

public void setUserModificationDate(Date userModificationDate) {
this.userModificationDate = userModificationDate;}

public String toString() {

return new ToStringBuilder(this).append("id", getId()).toString();}
} // End of class

Mapping POJO with persistence layer using hibernate mapping document

Each persistent class needs to be mapped with its configuration file. Following code represents Hibernate mapping file for AppLabsUser class.

One can also generate Hibernate mapping documents using Hibernate extension toolset. Hibernate mapping documents are straight forward. The element maps a table with corresponding class. The element represents the primary key column, and its associated attribute in the domain object. The elements represent all other attributes available in the domain object.
Hibernate Configuration File

Hibernate configuration file information needed to connect to persistent layer and the linked mapping documents. You can either specify the data source name or JDBC details that are required for hibernate to make JDBC connection to the database. The element refers to the mapping document that contains mapping
for domain object and hibernate mapping document.






true
org.hibernate.dialect.MySQLMyISAMDialect
org.gjt.mm.mysql.Driver
jdbc:mysql://localhost:3306/applabs
root
r00Tp@$wd





Hibernate Sample Code (Inserting new record)

Here is how you can use Hibernate in your programs. Typical Hibernate programs begin with configuration that is required for Hibernate. Hibernate can be configured in two ways. Programmatically and Configuration file based. In Configuration file based mode, hibernate looks for configuration file “hibernate.cfg.xml” in the claspath. Based on the resource mapping provided hibernate creates mapping of tables and domain objects. In the programmatic configuration method, the details such as JDBC connection details and resource mapping details etc are supplied in the program using Configuration API.

Following example shows programmatic configuration of hibernate.

Configuration config = new Configuration()
.addResource("org/applabs/hibernate/quickstart/Applabsuser.hbm.xml")

Configuration config = new Configuration()
.addClass(org.hibernate.quickstart.Applabsuser.class)
.setProperty("hibernate.dialect", "org.hibernate.dialect. MySQLMyISAMDialect")
.setProperty("hibernate.connection.driver_class", " org.gjt.mm.mysql.Driver")
. . . SessionFactory sessions = config.buildSessionFactory();


In configuration file based approach, “hibernate.cfg.xml” is placed in the classpath, Following Hibernate code can be used in this method.


SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
AppLabsUser user = new AppLabsUser();
Transaction tx = session.beginTransaction();
user.setUserCreationDate(new Date());
user.setUserEmail("user@allapplabs.com");
user.setUserFirstName("userFirstName");
user.setUserLastName("userLastName");
user.setUserName("userName-1");
user.setUserPassword("userPassword");
session.saveOrUpdate(user);
tx.commit();
session.close();


Hibernate Sample Code (Querying the database)

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

Session session = sessionFactory.openSession();

ArrayList arrayList = null;

String SQL_STRING = "FROM AppLabsUser as users";

Query query = session.createQuery(SQL_STRING);

ArrayList list = (ArrayList)query.list();

for(int i=0; i

System.out.println(list.get(i));

}

session.close();

Hibernate O/R Mapping

Object/relational mappings are usually defined in XML document. The mapping language is Java-centric, meaning that mappings are constructed around persistent class declarations, not table declarations.

AppLabsUser.hbm.xml

This is the short and simple hibernate example. I hope this will help you to start hibernate learning.


This article is submitted by Sandip K Mante.

Friday, July 11, 2008

Webservices

Web services Architecture:

Web services technology is changing the Internet rapidly, Fully equipped with capabilities to produce the transactional web. Earlier the web is dominated by program-to-user business-to-consumer (B2C) transitions. The transactional web will be limited to program-to-program business-to-business (B2B) exchanges. This transformation is being fueled by the program-to-program communication model of Web services built on existing and emerging standards such as Hypertext Transfer Protocol (HTTP), Extensible Markup Language (XML), Simple Object Access Protocol (SOAP),Web Services Description Language (WSDL), and the Universal Description, Discovery, and Integration (UDDI) project. Web services technologies provide a language-independent, environment-independent programming model that accelerates application integration inside and outside of the enterprise. Application integration through Web services yields flexible loosely coupled business systems. Because Web services are easily applied as
a wrapper technology around existing applications and information technology assets, new solutions can be deployed quickly and recomposed to address new opportunities. As adoption of Web services accelerates, the pool of services will grow, fostering development of more dynamic models of just-in-time application and business integration over the Internet.

http://www.w3.org/TR/ws-arch/


Web services overview

A Web service is an interface that describes a collection of operations that are network-accessible through standardized XML messaging. A Web service performs a specific task or a set of tasks. Web service is described using a standard, formal XML notation, called its service description, that provides all of the details necessary to interact with the service, including message formats (that detail the operations), transport protocols, and location. Web service descriptions are expressed in WSDL. This paper describes Web services in terms of a service-
oriented architecture. As depicted in Figure 1, this architecture sets forth three roles and three operations.

The three roles are the service provider the service requester, and the service registry. The objects acted upon are the service and the service description, and the operations performed by the actors on these objects are publish, find, and bind.















A service provider creates a Web service and its service definition and then publishes the service with a service registry based on a standard called the Universal Description, Discovery, and Integration (UDDI) specification. Once a Web service is published, a service requester may find the service via the UDDI interface. The UDDI registry provides the service requester with a WSDL
service description and a URL (uniform resource locator) pointing to the service itself. The service requester may then use this information to directly bind to the service and invoke it.


Based on the above architecture here is the three most common styles of use are RPC, SOA and REST.

Remote procedure calls

Rpc web services present a distributed function (or method) call interface that is familiar to many developers. Typically, the basic unit of RPC Web services is the WSDL operation.
The first Web services tools were focused on RPC, and as a result this style is widely deployed and supported. However, it is sometimes criticised for not being loosely coupled, because it was often implemented by mapping services directly to language-specific functions or method calls. Many vendors felt this approach to be a dead end.

Service-oriented architecture

Web services can also be used to implement an architecture according to Service Oriented Architecture (SOA) concepts, where the basic unit of communication is a message, rather than an operation. This is often referred to as "message-oriented" services.
SOA Web services are supported by most major software vendors and industry analysts. Unlike RPC Web services, loose coupling is more likely, because the focus is on the "contract" that WSDL provides, rather than the underlying implementation details.

Representational state transfer

Finally, Restful webservices attempt to emulate HTTP and similar protocols by constraining the interface to a set of well-known, standard operations (e.g., GET, PUT, DELETE). Here, the focus is on interacting with stateful resources, rather than messages or operations. RESTful Web services can use WSDL to describe SOAP messaging over HTTP, which defines the operations, or can be implemented as an abstraction purely on top of SOAP (e.g., WS-Transfer).
WSDL Version 2.0 offers support for binding to all the HTTP request method (not only GET and POST as in version 1.1) so it enables a better implementation of Restful webservices. However support for this specification is still poor.

Criticisms

Critics of non-RESTful Web services often complain that they are too complex and based upon large software vendors or integrators, rather than open source implementations.
One big concern of the REST Web Service developers is that the SOAP WS toolkits make it easy to define new interfaces for remote interaction, often relying on introspection to extract the WSDL and service API from Java, C# or VB code. This is viewed as a feature by the SOAP stack authors (and many users) but it is feared that it can increase the brittleness of the systems, since a minor change on the server (even an upgrade of the SOAP stack) can result in different WSDL and a different service interface. The client-side classes that can be generated from WSDL and XSD descriptions of the service are often similarly tied to a particular version of the SOAP endpoint and can break if the endpoint changes or the client-side SOAP stack is upgraded. Well designed SOAP endpoints (with handwritten XSD and WSDL) do not suffer from this but there is still the problem that a custom interface for every service requires a custom client for every service.
There are also concerns about performance due to Web services' use of XML as a message format and SOAP and HTTP in enveloping and transport.




Cited references
1. The document Web Services Conceptual Architecture is located at http://www.ibm.com/software/solutions/webservices/documentation.html.
2. For more information on HTTP from the World Wide Web Consortium, see http://www.w3.org/Protocols/.
3. For more information on SOAP from the World Wide Web Consortium, see http://www.w3.org/TR/SOAP/.
4. For more information on WSDL from the World Wide Web Consortium, see http://www.w3.org/TR/wsdl.
5. The UDDI project is a cross-industry initiative to create an open framework for describing, discovering, and integrating Web services across the Internet. For more information on UDDI, see http://www.uddi.org.
6. For more information on WSFL, see the document titled Web Services Flow Language Guide at http://www.ibm.com/software/solutions/webservices/documentation.html.

Thursday, July 10, 2008

What is Web 2.0?

Web 2.0 is like an all encompassing technology / term. Its elements include Collaboration through Wikis, Blogs, Social software, rich user experiences, expanded reach through mobile interfaces, feeds & syndication, mashups, Integration through lightweight REST-ful APIs, Collective Intelligence (light weight reporting to heavy data mining), may be even Search. It would be interesting to explore how businesses will benefit from or use Web 2.0. I would love to get your views.

I think the 'Web 2.0' strategy isn't about the technology or activities by themselves. It's a theory on which communication is based. Instead of the company forcing it's ideas or thoughts outward (Web 1.0), we can now create an open dialog and communication, giving the user a voice. With this communication, we are able to capture data straight from the consumer and learn about their wants, needs, desires, dreams, and behaviors, then react accordingly. We can integrate our companies and brands into the actual lifestyle of each and every consumer, building Brand Awareness, Brand Loyalty, and Brand Saturation.

Brands are now becoming extremely dynamic in nature. The power is switching hands from the company to the consumer. It is a great and exciting time to be alive.

Aside from the consumer now being armed with an infinite knowledge base and having the power of the internet to spread word-of-mouth faster and far more reaching than ever before, businesses should look internally at how their employees would benefit from 2.0 culture.

As the baby boomers retire and the nexters join in to the corporate mix, companies should be prepared to communicate with their employee base in a manner that addresses how they have been raised - online and on demand.

Further that with the capture of knowledge in a collaborative endeavor and you have the business case for implementing social media in the workplace. Grass roots and "lead from any chair" initiatives are the way we are moving as a society. Companies that rely solely on traditional methods of marketing and chain of command will be at a loss to compete in that world.

Attracting and retaining talent as well as keeping in step with customers is key to survival; employees and customers are no longer in a position to be controlled, they need to be understood and responded to. That's how companies will benefit from Web 2.0. It's not the specifics of the technology; they are merely the vehicle. It's adapting to the culture that is the imperative.

The importance of Web 2.0 is providing users the ability to engage and participate. How best to accomplish this is relevant to the user base of the organization and how they can most effectively engage. In my experience too many organizations are viewing Web 2.0 as a virtual Chinese menu of features to plug into their Web properties. This is the absolute wrong way to add value to your Web presence.

For example, one of my clients is a help/support site for a rather large media entity. Allowing their users the simple ability to comment on help articles increases the effectiveness of their content and the value to their community. Web 2.0 doesn't need to be super complex or extraordinarily new and innovative. You just have to provide an effective vehicle for your users and community to interact. This provides more value to your users which ultimately will equal success for your business.

Reference: http://www.spurcommunications.com/

How do these Web 2.0 companies generate revenue?

I have been mulling over some 'fun' things that I'd like to put up on the internet but, I cannot seem to figure out how some of these online sites make their revenue. Can it all be from ad revenue?

For example, break.com is now even paying for content. And can bestparking.com be making it from listing parking lots (and shaking down the lot management)? Granted they only service 3 cities so maybe that's doable. I didn't notice any ads.

Then there's those 43things.com guys: funded by amazon + ads by google

I could go on but I think you get the point. Can these sites really survive on ad revenue? Are they waiting for someone to buy them for their user base? Am I mixing up a few different revenue models here?

you can find out the 25 companies and about them by visiting here http://money.cnn.com/galleries/2007/biz2/0702/gallery.nextnet.biz2/index.html
I work closely with a lot of Business 2.0 and social media startups(and juggernauts)... so it is interesting to get insight from all of the brilliant peers on here about what upcoming companies they really see exploding! If you have one that isn't on the list tell us about it!

I recently read a post entitled "If Facebook or Twitter Charged $30/Month Would You Pay?" it has got such an outstanding response from all of you on all of my questions (thank you so much by the way), I thought I would share this one with you as well.

The link to the post can be found below. I have outlined a few of my arguments as to why I think social media platforms may not want to charge. Please feel free to read the post. I would love to hear some of your thoughts and ideas. I will make a post about the responses I receive and will publish them live in a few weeks for all to see (names are anonymous).

Below is the Conclusion I could get from reading many articles.

I just reopened the question to provide a quick summary of what I have learned:

- many of these sites are _definitely_ using ad revenue as their main (or only) source
- plentyoffish.com is one of the posterboys for making this work. See this interview:
http://www.workhappy.net/2006/06/interview_with_.html
- a big user base is also valuable to people
- SEO is very important
- and finally, yes, I am naive (but, hopefully, a little less so now)

Thanks for all of the feedback from all of you , too.

Read up on SEO techniques and visit this site:

http://www.cre8asiteforums.com/

I haven't looked through it yet but it seems helpful. I also bought a bunch of books last week including:

- web marketing for dummies (came highly recommended) (plus plain marketing)
- lucrative list building
- instant income

And I'm considering:

- http://seobook.com (can anyone comment on this book?)

The books just showed up in the mail. Thus, still have to read them so I can't actually comment on them yet.