Wednesday, September 14, 2005

Box with J2SE 5.0

Laila Ali
Wondering what Boxing's got to do with Java? And I didn't mean Laila Ali, the first woman to win a World Boxing Council title, either! You wouldn't like to mess with her, would you?

So, what is Boxing in Java? Boxing refers to the automatic conversion from a primitive to its corresponding wrapper type: Boolean, Byte, Short, Character, Integer, Long, Float or Double. Since this happens automatically, it's also referred to as autoboxing. The reverse is also true, ie. J2SE 5.0 automatically converts wrapper types to primitives and is known as unboxing.

Before you can try out this simple example, you must install and set the environment variables 'path' and 'classpath' for J2SE 5.0.

The example is quite trivial and you could try compiling it with an earlier version of J2SE, to see the compilation errors flagged out.
public class BoxingUnBoxing
public static void main(String[] args)
// Boxing
int var = 10;
Integer wInt = var;
int result = var * wInt;
System.out.println("Value of result = " + result);

// Unboxing
int conv = wInt;
if (conv < 100)
Boxing/Unboxing saves us the bother of converting from a primitive to it's wrapper and vice-versa. This feature is definitely a time-saver.

Update: Java 2 Platform, Standard Edition (J2SE 6.0), code name Mustang, is due in the first half of 2006. Also Dolphin, the Java SE 7 release is scheduled to follow Mustang in late 2007,
Technorati Tags:
Blogs linking to this article

Tuesday, September 13, 2005

Static imports in J2SE 5.0

Do you hate to type Java code? Static imports helps you save some typing. If you are using a static class or a static variable, you can import them and save some typing. The simple example below, should clarify this concept:
import static java.lang.Math.*;
import static java.lang.System.out;

public class MyMath5
public static void main(String[] args)
// returns a double between 0.0 thro' (but not
// including) 1.0
double r1 = random();
int r2 = (int) (random() * 5);
out.println("r1 = " + r1);
out.println("r2 = " + r2);

// Returns the absolute value of the argument
int x = abs(-240);
double d = abs(240.45);
out.println("x = " + x);
out.println("d = " + d);

// Returns an int or long (depending on whether
// the argument is foat or double)
// rounded to the nearest integer value
int p = round(-24.8f);
long q = round(24.45);
out.println("p = " + p);
out.println("q = " + q);

// Returns a value that is minimum of two values
int c = min(243, 240);
double dd = min(90876.5, 90876.49);
out.println("c = " + c);
out.println("dd = " + dd);

// Returns a value that is maximum of two values
int e = max(243, 240);
double f = max(90876.5, 90876.49);
out.println("e = " + e);
out.println("f = " + f);

Technorati Tags:
Blogs linking to this article

Monday, September 12, 2005

Head First Blog

If you are an ardent fan of the 'Head First' series of Java books, then you will find Kathy Sierra, Bert Bates and Eric Freeman's blog Creating Passionate Users a 'must read'. Do definitely read their blog entry Sample Java Exam Questions where you will find 11 mock exam questions from their upcoming update to their SCJP study guide (for the Java 5 version of the exam).
Technorati Tags:
Blogs linking to this article

Sunday, September 11, 2005

Earn Money with Java from Home

Looking to earn some extra money, from the comfort of your home? RentACoder helps you earn this extra income using your hard-won Java technical skills. It lets you locate and bid on coding projects and questions from around the world! By completing a free registration, you can publicize your skills on the online resume system and receive emails as new bid requests come in.

After you register, I suggest you read the Articles for Coders to understand how things work at RentACoder.

Technorati Tags: ,
Blogs linking to this article

Saturday, September 10, 2005

Enhanced for loop in J2SE 5.0

The enhanced for makes it easier to iterate over all the elements in an array or other kinds of collections. Look at this simple example:
public class EnFor
public static void main(String[] args)
String[] cities =
{"Pune", "Mumbai", "Bangalore", "Hyderabad"};

for (String name : cities)
If we analyse the for code, then the following happens:
(a) a String variable called name is created and set to null. The variable that you declare must be compatible with the elements in the array.
(b) Next, the first value in the cities array is assigned to name.
(c) The body of the loop is executed.
(d) The next value in the cities array is assigned to name. Remember, with each iteration, a different element in the array will be assigned to name.
(e) This is repeated as long as there are elements in the array.

Note: The : in the for, means "IN". Also, what follows the : must be a reference to an array or other collection.
Technorati Tags:
Blogs linking to this article

Friday, September 09, 2005

2005 ONJava Reader Survey

Announcing the 2005 ONJava Reader Survey by Chris Adamson -- The 2005 ONJava Reader Survey is underway. This is your opportunity to steer the site by helping them understand what you use, what you're interested in, and where you think Java is going.
Technorati Tags:
Blogs linking to this article

Monday, September 05, 2005

100 Best Practices to Improve performance in Java

Some of the best ways, put together in one place. A must read for medium to experienced J2EE programmers. A good example is for EJB - Message-driven Bean Life cycle.

The link.
Technorati Tags:
Blogs linking to this article

Cheat Sheet Roundup - Over 30 Cheatsheets for developers

Each developer has his/her own cheatsheet (most often used shortcuts, tips, clever hacks, etc). Here are 30 most often required ones.

My favourite one, of course, is the one for Vim. But you might want to check out the ones for JSP, Java, Regular Expressions or SQL.

If you have one, do share your pearls of wisdom ;-)
Technorati Tags:
Blogs linking to this article

Java Resources

Some excellent Java Resources are listed here. In case, you know of any other Java resource, please comment with the URL and a brief description.

(a) Sun's Official Java site For everything Java.

(b) Freshers Jobs and Placement Papers site claims it provides Fresher Jobs Walk-Ins, Technical Questions for Freshers, Aptitude Questions for getting a Fresher job, List of Companies offering jobs for Freshers, Latest Placement Papers, Sample Resumes for Freshers and many more things for Freshers across India. Do check this out and give me your feedback.

(c) GeekInterview is an Open Database where you can share interview questions, comment/answer any questions without any registration just by providing name and an optional email address.

(d) All India Jobs Search Engine

(e) Sun Certified Java Associate (SCJA) Certification - provides an ideal entry into an application development or a software project management career using Java technologies. Candidates for this exam include: entry level Java programmers, students studying to become Java programmers, project or program managers working with Java technology in the software development industry. Java Ranch covers this in more details.

(f) Java Ranch is the mother of all Java forums!

(g) has a Java forum and it hopes to bring together all Java people; to share their knowledge and ideas; to help each other and explore their capabilities.

(h) JavaRSS This site is a portfolio of websites rich in Java News, J2EE News, Java Articles, Java Blogs, Java Tags, Java Groups and Java Forums. Java developers, Java Architects and Java Managers can read daily news, articles and blogs through the convenience of their favorite browser.

(i) JavaLobby The heart of the Java Community.

(j) IndicThreads Java J2EE Portal.

(k) OnJava O'Reilly's Source for Enterprise Java.

(l) JavaWorld Online Magazine.

(m) JDJ Online Magazine.

(n) FTPOnline Java.

(o) dev2dev By developers, for developers.

(p) Sun Developer Network Products and Technologies.

(q) The source for Java Technology Collaboration.
Technorati Tags:
Blogs linking to this article

Sunday, September 04, 2005

Commonly Asked Definitions

I would like to post here, some Commonly Asked Definitions. If you would like more definitions, please post your comments to this blog entry.

A. J2EE Patterns
(a) Software Design Pattern: It's a repeatable solution for a commonly-occuring software problem. Definition credit goes to the book Head First Servlets and JSP.

(b) DataAccessObject (DAO): The DAO implements the access mechanism required to work with the data source. The data source could be a persistent store like an RDBMS, an external service like a B2B exchange, a repository like an LDAP database, or a business service accessed via CORBA Internet Inter-ORB Protocol (IIOP) or low-level sockets. The business component that relies on the DAO uses the simpler interface exposed by the DAO for its clients. The DAO completely hides the data source implementation details from its clients. Because the interface exposed by the DAO to clients does not change when the underlying data source implementation changes, this pattern allows the DAO to adapt to different storage schemes without affecting its clients or business components. Essentially, the DAO acts as an adapter between the component and the data source.

(c) BusinessObject (BO): represents the data client. It is the object that requires access to the data source to obtain and store data. A BusinessObject may be implemented as a session bean, entity bean, or some other Java object, in addition to a servlet or helper bean that accesses the data source.

(d) DataSource: This represents a data source implementation. A data source could be a database such as an RDBMS, OODBMS, XML repository, flat file system, and so forth. A data source can also be another system (legacy/mainframe), service (B2B service or credit card bureau), or some kind of repository (LDAP).

(e) TransferObject: This represents a Transfer Object used as a data carrier. The DataAccessObject may use a Transfer Object to return data to the client. The DataAccessObject may also receive the data from the client in a Transfer Object to update the data in the data source. Definitions (b) to (e) credit, goes to Sun Developer Network.

For more information on Design Patterns, refer the site Data and Object Factory
Technorati Tags:
Blogs linking to this article

Friday, September 02, 2005

Pune, Java Bloggers

Here are some bloggers who blog on Java and either hail from or reside in Pune, in no particular order.
(a) Narendra Naidu
(b) Null Pointer
(c) IndicThreads

If you do not know what a blog is and would like to know and start your own blog, then see this post.

If you know of any bloggers who hail from Pune or are based in Pune, please comment to this blog entry and give me their URL.

Technorati Tags:
Blogs linking to this article