Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

New Features in Java 5 – From Programmers Point of View

By Exforsys | on November 26, 2005 |
J2EE

New Features in Java 5 – From Programmer’s Point of View

With emergence of Java 5, a set of new features is included in Java technology. Many programmers working on Java technology were excited before its release about its new features. In this article, new features of Java 5 are summarized which are important from programmer’s point of view.

Language Features

Get Rid of ClassCastException With Generics

It is very common experience among programmers to face ClassCastException at run time while integrating different parts (modules) of application which are interacting with each other in form of collections where collections are passed as parameters to methods or returned from methods or set and get in a common place holder mechanism like session. To avoid this scenario Generics are introduced in Java 5. Here is one example how to use Generics with collection classes.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/* Note that there is no need to cast the object to Integer class any more*/;;
void userOfCollection(Collection pInt) {;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
…..for (Iterator< Integer > i = pInt.iterator(); i.hasNext(); ) ;;;;;;;;;;;;
……….if (i.next().intValue() == 4);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
……….i.remove();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Generic is most important and quite hyped feature of Java 5. Prior to this, there was no way to know which type of object is residing there in the collection. Generic helps programmers to integrate their stuff with each other in a declarative manner.

New Convenient for Loop

The “for” loop in Java language has been enhanced to iterate through collections. Here is the example how it works with collections.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/*Old way of iterating through collections*/;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void oldForLoop(Collection c) {;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
…..for (Iterator< Integer > i = c.iterator(); i.hasNext(); );;;;;;;;;;;;;;;;
……….if (i.next().intValue() == 4);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
……….i.remove();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}……….;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
/* New way of iterating through collections*/;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void newForLoop(Collection c) {;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
…..for (Integer i : c);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
……….if (i.next().intValue() == 4);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
……….i.remove();;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
}…..;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

If you notice here, to iterate through a collection using a “for” loop has been very simple now. Prior to this, most time Iterator and Enumerator classes were used to iterate through collection objects. And in most implementations people need to iterate through collection objects.

This new implementation also helps in avoiding NoSuchElementException at run time. It also makes the code more readable and maintainable.

Autoboxing of Primitives

In the example we have discussed in the previous topic, we did something which is not required in Java 5

if(i.next.intValue() == 4)

Here in this assertion, we have to take primitive int type value from the Integer type object using intValue() method. Even to store any primitive value such as int or long in a collection object one needs to wrap it in wrapper class first and store it.

This overhead is no more required in Java 5. With autoboxing, wrapper objects can directly act as primitive type values as and when required. So we can write the above assertion statement this way also.

if(i.next == 4)

The same mechanism can be used to place primitive values in collections without wrapping them in wrapper classes.

Introduction of Enums

Type safe enum was long awaited feature in Java language. It has been introduced in Java 5.

To represent a constant custom type there was no way except definition String or int constant literals like

public static final String DAY_MONDAY = “Monday”;
public static final String DAY_TUESDAY = “Tuesday”;

But now with the introduction of enums in Java, there is a type safe and standard mechanism of defining custom types for multiple values.

Example:

enum DAY { MONDAY, TUESDAY }

This way, Monday and Tuesday are no longer String literals and also String operations cannot be performed on them (which are actually not required).

Varying Arguments – Varargs

Varargs is another step towards Java community’s commitment for object orientation and convenience of programming. We know that when we need to pass multiple values to a method as parameter, array of values (or objects) is efficient and convenient way. But, with the introduction of Varargs it has been more convenient to pass arrays or set of arguments to methods.

E.g. If a method is defined like

void doSomeThing(String[] args){}

As a client to call this method, one has to first create an array containing Strings and then call the method with that array of string as argument.

doSomeThing({“A”,”B”,”C”});

But, with varargs

void doSomeThing(String… args){}

This method can be called in two different ways.

doSomeThing({“A”,”B”,”C”});

or

doSomeThing(“A”,”B”,”C”);

Here String… in method declaration indicates that at a placeholder here either an array of String should be passed or String literals can directly be passed.But it is not advisable to override a method with vararg because it may lead confusion while calling.

Avoid Using Constant Interface Antipattern

Prior to Java 5, there was an ugly approach in using constant values named as Constant Interface Antipattern. To keep constants at one place and make them accessible in different classes of the application, it was a custom to define an interface containing all constants, other classes had to implement the interface wherever those constants were required. Actually this approach conflicts with the object orientation of Java language. Such constants are implementation details for a class but if the class accesses them by implementing an interface they become a part of public access (API) of the class. It means implementation details are being linked as API here.

To avoid this behavior, Constant Imports are introduced in Java 5. Using constant imports one can avoid implementing such interfaces.

E.g. import static com.mycompany.MyClass.MyConstant;

This constant can then be used without class qualificationint l = 5* MyConstant;

Enhancements in Libraries

Language and Utility (lang and util packages)

  • ProcessBuilder: Introduced as enhancement to be used in place of Runtime.exec method. It offers more flexibility.
  • Formatter: This new class has been introduced to improve formatting facility in Java language for String, Date, Time, and Number etc.
  • Scanner: This new class is based in regex implementation. It can be used to read and search from streams for a particular pattern or into a particular primitive type or String.

Networking

  • Ipv6 on Windows Xp and 2003 server is supported.
  • Timeout can be enabled and customized for any connection.
  • InetAdderess API has been improved in a way that it can be used to verify if host is reachable or not.
  • CookieHandler API has been introduced for better handling of cookies.

I18N (Internationalization)

  • Unicode Standard Versions 4.0 now forms basis for character handling.
  • DecimalFormat class has been improved in a way that precision is not lost while parsing BigDecimal and BigInteger values.
  • New language support: Vietnamese

Enhancements in Integration Libraries

Java Naming and Directory Interface (JNDI)

  • NameClassPair has been improved to access full name from directory or service.
  • More standard LDAP controls are being supported now e.g. Manage Referral Control, Paged Results Control and Sort Control
  • Improved functionality to modify LDAP names

JDBC

Five new implementation of RowSet interface has been provided with Java 5.

  • Straightforward implementation of RowSet functionality is JdbcRowSet.
  • CachedRowSet is a lightweight implementation in a way that it dose not hold connection to the data source all time. Once any operation is performed on the data source, it ends the connection and caches data offline.
  • Another implementation of CachedRowSet is FilteredRowSet. This can be used to derive subset of data from cached data of CachedRowSet.
  • JoinRowSet is also one of implementations of CachedRowSet. It can be used to derive data from multiple RowSets based on a SQL join.
  • To describe XML data in tabular format using standard XML schema, WebRowSet has been implemented. It is also extending CachedRowSet.

RMI

  • Stub classes can be generated dynamically in Java 5. With introduction of dynamic stub class generation, one does not need to run rmic compiler to generate stub classes for RMI applications. But, to be prior versions compliance, still one has option to run rmic for older version clients.
  • Standard APIs for SSL and TLS has been added to standard RMI library. So now RMI applications can communicate over secured Socket Layer or Transport Layer Security.

Summary

From programmer’s point of view there are some revolutionary improvements in Java 5. These changes are aimed to improve convenience, stability and performance of application development using Java technology. Also one can opt to make applications more robust by going for features of Java 5 like Enums, Generics, for-each loop and Autoboxing. These features are more targeted to make the code simpler and easy to maintain. Library enhancements are going to help programmers in implementing their ideas in better way. And JDBC enhancements are aimed to support separate data access layer in web and enterprise applications.But, some people never like to change things around them, for them they can always program Java applications the way they have been doing prior to release of Java 5.

« « New Features In Java 5.0 – From Managers Point of View
Planning to Install SQL Server 2005 » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 392 Followers
  • Popular
  • Recent
  • Servlet Basics

    December 6, 2005 - 0 Comment
  • A Java TOC2 Class Which Can Contact Aim

    July 12, 2006 - 0 Comment
  • Servlets Advanced

    December 12, 2005 - 0 Comment
  • Quickly Develop Java Programs With Tapestry

    July 12, 2006 - 0 Comment
  • How to Install and Use NetBeans for Java Development

    June 26, 2005 - 0 Comment
  • JSP Basics

    May 7, 2006 - 0 Comment
  • How To Run J2ME Programs on Palm Devices

    July 14, 2006 - 0 Comment
  • .NET and J2EE – A Comparsion Study

    November 26, 2005 - 0 Comment
  • Antipatterns In Java Programs

    July 1, 2006 - 0 Comment
  • How To Use Java DB as Your Client Mobile Database

    July 14, 2006 - 0 Comment
  • Why It is Important To Focus On Java Exceptions For Your Programs

    July 27, 2006 - 0 Comment
  • Important Features of Java – Multithreading, AWT

    July 26, 2006 - 0 Comment
  • What You Should Know About Java XML

    July 25, 2006 - 0 Comment
  • What You Can Do To Deal With Java’s Memory Retention Problems

    July 22, 2006 - 0 Comment
  • Java Overview

    July 17, 2006 - 0 Comment
  • How To Use Java DB as Your Client Mobile Database

    July 14, 2006 - 0 Comment
  • How To Run J2ME Programs on Palm Devices

    July 14, 2006 - 0 Comment
  • Java Virtual Machine

    July 13, 2006 - 0 Comment
  • Quickly Develop Java Programs With Tapestry

    July 12, 2006 - 0 Comment
  • A Java TOC2 Class Which Can Contact Aim

    July 12, 2006 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Why It is Important To Focus On Java Exceptions For Your Programs
  • Important Features of Java – Multithreading, AWT
  • What You Should Know About Java XML
  • What You Can Do To Deal With Java’s Memory Retention Problems
  • Java Overview

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT