Java on net

Collection of references and notes on Java and J2EE

Sunday, August 30, 2009

Auto Tweet on Twitter Using Java @PCQuest

Article: Auto Tweet on Twitter Using Java
Author: Rahul Sah
Link: http://pcquest.ciol.com/content/Developer/2009/109070401.asp
Summary:
Twitter4J is a Java library for Twitter API. It is completely implemented in Java and spares you the hassles of creating your own wrapper for Twitter APIs for your Java application to access Twitter. This article shows how you can it be used to access Twitter through a Servlet Web application.

Additional Link: Twitter4J (http://yusuke.homeip.net/twitter4j/en/index.html)

Powered by ScribeFire.

Saturday, August 29, 2009

How to Use Spring Web Service @JavaLobby

A How-To article (http://java.dzone.com/articles/spring-ws-how) to expose a simple web service using Spring Web Services at JAVALOBBY (http://java.dzone.com) - author Biju Kunjummen.



Powered by ScribeFire.

Monday, August 10, 2009

Spring source bought by VMware

Two companies or rather movements I have come to admire, are coming together. Spring source have been bought up by VMware.

See link: VMware to Buy SpringSource for $420M at Gigaom.com


Powered by ScribeFire.

Monday, November 10, 2008

Article on REST WebServices

Jeremy Deane of Collaborative Consuluting has two part article "RESTful Web Services: Development and Testing
" published at bpminstitute.org. Article covers introduction of REST Web Services and explains development of an example using Restlet framework. Few points from that article -

REST (Represntational State Transfer)
 * Simpler than SOAP, has less steps than SOAP development.
 * Provides access to resources identified by URI using HTTP.
 * Resources are abstraction of information
 * Supports HTTP operations - GET, PUT, POST and DELETE (analogous to CRUD)
 * Each interacion updates the state (except GET).
 * Interactions are idempotent
 * Security is provided by authentication, authorization and auditing
 
Design considerations
 * What are the entities (resources)?
 * What are the resource representations formats?
 * How are entities related to each others (links)?
 * What ids resources (ids should be descriptive and scalable)?
 * How to use HTTP status code? (Should avoid for lose coupling between provider and consumer)
 
Important classes of Restlet framework
 * Converter
 * Router
 * Resource
 * Guard

Monday, November 03, 2008

Java WebServices Standards

Java Standards related to WebServices (Note: not in any particular order)

1. Java API for XML Web Services (JAX-WS) [JSR 224]
2. Java Architecture for XML Binding (JAXB) [JSR 222]
3. WSEE [JSR 109]
4. WS-Metadata [JSR 181]
5. Java Business Integration (JBI) [JSR 208]

Reference:
* SOA Using Java(TM) Web Services by Mark D. Hansen (http://soabook.com/)
* The JAVA EE5 Tutorial (http://java.sun.com/javaee/5/docs/tutorial/doc/)
* Java Standards at SearchSOA.com (http://searchsoa.techtarget.com/topics/0,295493,sid26_tax305810,00.html)

Tuesday, April 08, 2008

Portlet Specification V2.0 at IBM developerworks

Detailed article about portlet specification v2.0 at IBM developerworks -
What's new in the Java Portlet Specification V2.0 (JSR 286)?

Thursday, February 14, 2008

Proxy setting in Eclipse

I have been asked again - "Where is the proxy setting in Eclipse?"

In Eclipse 3.3 - Windows -> Preferences -> General -> Network Connections

In Eclipse 3.2 - Windows -> Preferences -> Internet -> Proxy Settings

Tuesday, February 05, 2008

Reference for JSF, Spring and JPA

I referred to Carol McDonald's Blog entry -
Sample Application using JSF, Spring 2.0, and Java Persistence APIs (http://weblogs.java.net/blog/caroljmcdonald/archive/2007/06/sample_applicat.html) for reference on JSF, Spring and JPA.


Powered by ScribeFire.

Monday, August 20, 2007

Eclipse Basic Shortcuts

Eclipse comes with basic tutorial and it could also be found online at -

http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jdt.doc.user/gettingStarted/qs-BasicTutorial.htm

Outlining few shortcuts for the some features explained there -

* Navigate Outline (Ctrl+O) 2 times for inherited items

* Content Assist (Ctrl+Space)

* Run As (Alt+Shift+X) Java Application +J

* Show line numbers -> Windows->Preferences->General->TextEditors

* Source > Organize Imports (Ctrl+Shift+O)

* Restore from local history

* Refactor (Alt+Shit+T)

* Creation and configuration of generated comments in the Java > Code Style > Code Templates preference page.

* Source (Alt+Shift+S) ->
+v: Override/Implement methods
+r: Generate Getters and Setters

* View declaration (Ctrl+G)

* View Type Hierarchy (Ctrl+T) or Navigate > Quick Type Hierarchy
Ctrl+T to toggle between supertype hierarchy and subtype hierarchy.

* Evaluating snippets: New > Other > Java > Java Run/Debug > Scrapbook Page

Wednesday, August 15, 2007

Integration Pattern

Integration is an essential part of most of the enterprise systems now a days. Here is a quick guide for enterprise integration patterns, nicely explained with diagrams :

Enterprise Integration Patterns - Table of Contents (http://www.enterpriseintegrationpatterns.com/toc.html)

This is Table of Contents for the book - Enterprise Integration Patterns (http://www.enterpriseintegrationpatterns.com/index.html) which explains each of
patterns in detail. A sample chapter of the book can be downloaded from:
http://www.enterpriseintegrationpatterns.com/docs/EnterpriseIntegrationPatterns_HohpeWoolf_ch03.pdf




Powered by ScribeFire.

Friday, July 06, 2007

Decoupling user and creator in Factory Pattern

It is a good idea to decouple user and creator in factory pattern. This technique is also mentioned as Simple Factory Pattern/Idiom.

Following is diagram from "Manufacturing Java Objects with the Factory Method Design Pattern by Barry Burd and Michael P. Redlich" (http://javaboutique.internet.com/tutorials/factory/) explaining basic factory pattern.


Here, Creator is also user of the Product. This creation and use is tightly coupled.

A "SimpleProductFactory" element can be added to Creator class (composition), which would be responsible of creating Product. Thus, decoupling use and creation of the Product.

Links:-
* Sun Developer Forums: Problem understanding Factory Method Pattern
* Manufacturing Java Objects with the Factory Method Design Pattern by Barry Burd and Michael P. Redlich (http://javaboutique.internet.com/tutorials/factory/)

Friday, June 15, 2007

JUNIT 4 Tutorial on IBM Developerworks

Look at Jump into JUnit 4 by Andrew Glover, for introduction on JUnit 4.
JUnit 4 is complete makeover of JUnit with excellent use of annotations. Working with test cases has been made easier by relaxing stringent requirements of earlier versions.
Tutorial covers fundamental concepts, new features along with examples.
Article do points that "Many argue that JUnit 4's use of annotations was influenced by TestNG as well as .NET's NUnit."

Other resources:

1. Junit offical website (http://www.junit.org/index.htm)
2. Junit 4.3 JavaDoc (http://www.junit.org/junit/javadoc/4.3/index.htm)
3. JUnit Reloaded by Ralf Stuckert on java.net (http://today.java.net/pub/a/today/2006/12/07/junit-reloaded.html)

Powered by ScribeFire.

Friday, March 23, 2007

Java: Static methods are not overriden

In Java, sub-class static method can have same signature as super-class static method. But it does not mean that super-class static method is overridden by sub-class static method. Look at the following code (from reference)
-------------------------------------------
/*

* SubClass.java

*

* Created on den 23 juni 2005, 21:13

*/

package sample;

/**

*

* @author Thomas

*/

public class SubClass extends SuperClass{

public static Long getStaticLongId(){

return 2L;

}

public Long getInstanceLongId(){

return 20L;

}

public static final void main(String args[]){

SubClass subClassInstance = new SubClass();

System.out.println("Static overloading:\t" +

SubClass.getStaticLongId() + "\t" +

SubClass.getStaticStringId());

System.out.println("Instance overloading:\t"+

subClassInstance.getInstanceLongId() + "\t" +

subClassInstance.getInstanceStringId());

}

}

/*

* SuperClass.java

*

* Created on den 23 juni 2005, 21:09

*/

package sample;

/**

*

* @author Thomas

*/

public class SuperClass {

public static Long getStaticLongId(){

return 1L;

}

public static String getStaticStringId(){

return getStaticLongId().toString();

}

public Long getInstanceLongId(){

return 10L;

}

public String getInstanceStringId(){

return getInstanceLongId().toString();

}
}
------------------------------------------------------

Output will be -
Static overloading: 2 1
Instance overloading: 20 20

For detailed reason about it, look at the reference.

As a side-note, if you put this code in eclipse, you will see little triangle by the side of overridden instance method "getInstanceLongId()". This sign will be missing for static method "getStaticLongId()".

Reference:
* Overriding static methods - why doesn´t it work?

Thursday, March 15, 2007

TSS Article on SOA

Article ESB, Service Implementation and the Return of the EJB on TheServerSide by Frank Teti, tells about SOA in general. Good to read, to know what different options you have in SOA.

It has also a mention about MULE (http://www.mulesource.com/), this open-source ESB solution has recently crossed 500K download mark (http://www.mulesource.com/company/press_releases/500K_011707.php).

Friday, August 11, 2006

Eclipse to test WSDL

With Eclipse you can test WSDL without writting code.
Link: http://help.eclipse.org/help32/topic/org.eclipse.jst.ws.consumption.ui.doc.user/tasks/ttestwsdl.html

Annotations in Java 1.5

Annotations are metadata used in source code to be interpreted by the tools and libraries without affecting the execution of the program. Annotations can be interpreted at compile-time or run-time. A use of annotation could be, mark a method as deprecated; use of deprecated can then be interpreted by the compiler to generate warnings. Another use could be pass configuration values for the tool to be process, generate or modify configuration files. Annotations are beneficial in documentation, code-analysis and compiler checking.

Example:
@deprecated public void foo(){}

Annotations consist of '@' sign followed by type of annotation and a parenthesized list of name-value pair of elements. Annotations can be used everywhere where other modifiers like public or static can be used. As a convention annotation is preceded by other modifiers.


Declaration of annotation type:
Example: public @interface breaksStandard {
public String reviewer();
public String reviewDate;
public String reason default "";}

Similar to interface declaration, modifier '@' sign prefixed to keyword interface. Return types can only be primitives, String, Class, enums and annotations (and arrays of these).

Usage: @breaksStandard(reviewer="XYZ", reviewDate="Aug 10, 2006") public void FOO(){}

Types:
1. In built annotations -
i. The Override annotation
ii. The Deprecated annotation
iii. The SuppressWarnings annotation

2. User Defined annotations

Categories:
1. Marker annotations
2. Single-value annotations
3. Full annotations

Meta-Annotation:
Annotations of annotations are meta-annotation. e.g. @Target, @Retention, @Documented.

Exercise: Work with @Deprecated or @Override annotation in Eclipse.

References:

[1] http://java.sun.com/j2se/1.5.0/docs/guide/language/annotations.html Annotations
[2] http://www-128.ibm.com/developerworks/java/library/j-annotate1/ , Annotations in Tiger, Part 1: Add metadata to Java code, Author: Brett McLaughlin
[3] http://www-128.ibm.com/developerworks/java/library/j-annotate2.html, Annotations in Tiger, Part 2: Custom annotations, Author: Brett McLaughlin
[4] http://www.infoq.com/articles/Annotation-Hammer Annotation Hammer, Author: Venkat Subramaniam
[5] http://www.javaworld.com/javaworld/jw-03-2005/jw-0321-toolbox.html An annotation-based persistence framework, Author:Allen Holub

Friday, July 14, 2006

Controversy controversy controversy

Its every where I see. So many links that I lost count. Can you guess what is IT??

* Richard Monson-Haefel: It's too late to save Java EE (http://www.infoq.com/news/Java-EE-Demise-Report)
* Is Java EE's Complexity Its Worst Enemy?(http://www.internetnews.com/dev-news/article.php/3618166)
* The Beginning of the End for Java Starts(Date.Time.NOW()); (http://www.oreillynet.com/windows/blog/2006/07/the_beginning_of_the_end_for_j.html)
* Analysts see Java EE dying in an SOA world (http://searchwebservices.techtarget.com/originalContent/0,289142,sid26_gci1198211,00.html)
* Analysts see Java EE dying in an SOA world (http://www.theserverside.com/news/thread.tss?thread_id=41283)

Controversies are good sometime. Personally I don't believe that JEE dying. My 2 cents, 'May the best one win'. People!! you have much choices now then say couple of years back. Evaluate and find which one fits best to you. May you choose JEE over others. Complexities will be there with all the Enterprise level projects. There are lot other factors to consider. Resources involved, total cost of ownership, return of investment, maintainability etc etc.

Wednesday, July 05, 2006

Links for eclipse 3.2 Callisto

Will add more soon
1. Eclipse Callisto http://www.eclipse.org/callisto/
2.
What's New in Eclipse 3.2 Java Development Tools http://www.onjava.com/pub/a/onjava/2006/06/28/whats-new-in-eclipse-3-2-java-development-tools.html?page=3
3. Ten coolest Eclipse 3.2 features http://blogs.zdnet.com/Burnette/?p=136
4. Customize Your Callisto Experience http://www.eclipse.org/callisto/custom.php
5. Eclipse Updates 10 Open-Source Projects in 'Callisto' http://www.eweek.com/article2/0,1895,1981651,00.asp
6. Step-by-step Eclipse Callisto http://www.ebernie.net/blog/2006/06/21/step-by-step-eclipse-callisto/

-----------------------------------------------------
New:
7. Series of Callisto podcasts http://www.eclipsezone.com/spotlights.jsp
-----------------------------------------------------

Trivia:
* Release Date: June 30, 2006
* Callisto, named for a moon of Jupiter
* The 10 projects included in the Callisto release are:
1. Business Intelligence and Reporting Tools (BIRT) 2.1
2. C/C++ IDE (CDT) 3.1
3. Data Tools Platform (DTP) 1.0
4. Graphical Editor Framework (GEF) 3.2
5. Graphical Modeling Framework (GMF)1.0
6. Eclipse Project 3.2
7. Test and Performance Tools Platform (TPTP) 4.2
8. Web Tools Platform (WTP) 1.5
9. Visual Editor (VE) 1.2
10. Eclipse Modeling Framework (EMF) 2.2

Tuesday, June 06, 2006

Links for JUnit on Eclipse

List of links for JUnit on Eclipse. Looking forward for more additions.

1. Unit Testing in Eclipse Using JUnit (http://open.ncsu.edu/se/tutorials/junit/#section6_0)
Date: Aug 29, 2005
To the point tutorial.

2. Using JUnit in Eclipse (www.cs.umanitoba.ca/~eclipse/10-JUnit.pdf)
Date: Oct 30, 2003
With a quick example

3. Eclipse Junit testing tutorial (http://www.laliluna.de/eclipse-junit-testing-tutorial.html)
Date: April, 12 2005
Definations, examples and source code

Friday, June 02, 2006

Quick reference of Autoboxing in JDK 1.5

Boxing is simply converting primitive type to wrapper class. e.g. Integer intObj = new Integer(100). Autoboxing is compiler taking care of boxing. WIth autoboxing following is a legal statement:
Integer intObj=100;

Vice-versa is called unboxing. JDK 1.5 supports autoboxing and auto-unboxing.

Following is legal with autoboxing
1. Integer intObj1=100; Integer intObj2=200;
2. Integer intObj3=intObj1+intObj2;
3. map.put("zero", 0); //map is defined as Map
4. int z=map.get("zero");
5. Boolean result= (intObj1==intObj2);
6. int intValue = intObj1; //throws nullPointerException
7. foo(intValue); //foo is defined as - public void foo(Integer intObj1){}
8. bar(intObj1); //bar is defined as - public void bar(int intValue){}
9. if(booleanObj){} //booleanObj is of type Boolean
10. int intValue = -intObj1;


Following is illegal
1. Integer intObj=shortVal; // shortVal is of type short
2. Double doubleObj = 10; //Can not convert from int to Double

Advantage of autoboxing and auto-unboxing is concise code. But careless use might result in poor performance of the code. Certain primitives are cached and autoboxing returns same wrapper objects. This value may depend on jvm used, normally this value are:
1. The boolean values true and false.
2. The byte values.
3. The short and int values between -128 and 127.
4. The char values in the range '\u0000' to '\u007F'.

It means, if intObj1=127 and intObj2=127 then intObj1==intObj2 returns true. But, if if intObj1=128 and intObj2=128 then intObj1==intObj2 returns false.

Best practices compiled by Brian Pontarelli at http://brian.pontarelli.com/2004/07/15/jdk-5-auto-boxing-best-practices [3]

If you can use primitives do it, if you can’t don’t.
1. Avoid using wrapper classes whenever possible.
2. Never do math with wrappers.
3. Try not to use any of the comparison operators (<, >, <=, >=, ==, etc) with wrappers.
4. Avoid usage in loop statements.
5. Always check for null values.


References:

[1] SCJP 5 : Chapter 3. API Contents (Part-1) http://www.exforsys.com/content/view/1885/362/
[2] Autoboxing surprises from J2SE 5 http://www.theserverside.com/news/thread.tss?thread_id=27129
[3] JDK 5 - auto-boxing best practices http://brian.pontarelli.com/2004/07/15/jdk-5-auto-boxing-best-practices/
[4] J2SE 5.0 in a Nutshell http://java.sun.com/developer/technicalArticles/releases/j2se15/
[5] Autoboxing http://java.sun.com/j2se/1.5.0/docs/guide/language/autoboxing.html
[6] Object type http://en.wikipedia.org/wiki/Autoboxing

Thursday, June 01, 2006

TheServerSide @ JavaOne 2006

Enterprise Java Community: TheServerSide @ JavaOne 2006

Above link is TheServerSide report on JavaOne2006 By Nitin Bharti, Frank Cohen and Rich Seeley.

Thursday, May 25, 2006

Two Java Thread Models

Java Thread Models; at this webpage Dr. Robert Kline discussed two Java Thread Models.

Model 1. Thread created from the same base
Model 2. Thread with separate bases sharing an object.

While at that page, check out his comparison of C++ and Java at http://www.cs.wcupa.edu/~rkline/cppjava.html.

Wednesday, May 17, 2006

"It's not a question of whether, but a question of how,"

Information Week article "Sun's Pledge To Make Java Open Source Leaves Key Questions Unanswered"
states
"Sun hasn't said who will manage the code or when it will become open source. "

Read more reactions at eWeek Article: "
Sun's Open-Source Outreach Met with Mixed Emotions"

So, will open-source Java mean a lot of different flavors of Java? Will it mean a personalize lean JVM for me? Will it mean I can replace core libraries? May be I will have choice of different Garbage Collector. Well! choice will be endless.

Friday, April 14, 2006

Parsing with StAX in JDK 6.0 - Tutorial and other links

Parsing with StAX in JDK 6.0: by Deepak Vohra, published at JavaBoutique, is a tutorial about Streaming API for XML (StAX) in Java6.0. StAX is a streaming, pull-parsing API for XML., is a new feature in JDK 6.0.

From this tutorial - " A push model parser generates events until the XML document is completely parsed. But pull parsing is regulated by the application—so parse events are generated by the application. This means with StaX, you can suspend parsing, skip elements while parsing, and parse multiple documents. With the DOM API, you end up parsing the complete XML document into a DOM structure, thus reducing parsing efficiency. With StAX, parsing events get generated as the XML document gets parsed. "

Another link:

Chapter 3: Streaming API for XML of Sun Java Web Service Tutorial

From this link:
XML Parser API Feature Summary
Feature
StAX
SAX
DOM
TrAX
API Type
Pull, streaming
Push, streaming
In memory tree
XSLT Rule
Ease of Use
High
Medium
High
Medium
XPath Capability
No
No
Yes
Yes
CPU and Memory Efficiency
Good
Good
Varies
Varies
Forward Only
Yes
Yes
No
No
Read XML
Yes
Yes
Yes
Yes
Write XML
Yes
No
Yes
Yes
Create, Read, Update, Delete
No
No
Yes
No

Another useful link:
Does StAX Belong in Your XML Toolbox? By Jeff Ryan , to understand pros, cons and uses of different xml parsers. The above table can be find in this article.

Tuesday, April 11, 2006

Links for new features of JDK 5

The Server Side featured entry
JDK 5 in Practice by Cedric Beust has list of JDK 5 features,
JDK 1.5 from Joshua and Neal has list of JDK 5 features and when to use it.