• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Difference between Java 5 adn Java 1.4

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the major difference between Java 5 and Java 1.4?

Thanks!!!
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tiger has invited lots of features that does not previously supported by J2SE 1.4, such as: Reflection and proxies, Generic, Annotations, Autoboxing, etc.

In addition, Tiger has simplified the coding for looping as well. You will find it amazing.

Nick
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For more information on new features, you might read SUN's article:
http://java.sun.com/developer/technicalArticles/releases/j2se15langfeat/

Nick
 
author
Posts: 284
35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, reflection has been in Java for a very long time (since 1.1 in fact). But generics are definitely a 5.0 feature.

The article http://java.sun.com/developer/technicalArticles/releases/j2se15/
has a nice overview of the new features.

My favorites are generic collections and the "for each" loop:



Cheers,

Cay
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cay,

The coding syntax is simplifying the coding effort, however, besides this, what features that we could adopt into our daily development work?

Nick
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
New Feature in Java 5.0
 
michael yeung
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Cay Horstmann:
Well, reflection has been in Java for a very long time (since 1.1 in fact). But generics are definitely a 5.0 feature.

The article http://java.sun.com/developer/technicalArticles/releases/j2se15/
has a nice overview of the new features.

My favorites are generic collections and the "for each" loop:



Cheers,

Cay



Will the "for each" loop support to get the key and the value of Map?

Thanks

Michael Yeung
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Will the "for each" loop support to get the key and the value of Map?


If the data type is a Map, then it will support.

Nick
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Before using for-each with Map , HashMap , you must get value of hashmap to Collection type such as Collection, Set by using values(), keySet() method.

Example

 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Collection<String> temp = h1.values();


I just have a question. Does I really need to specify the type of the Collection? How about if the collection contains different types? What should I do for this case?

As you know, in a HashMap, I can put in any objects as the value.

Nick
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:

I just have a question. Does I really need to specify the type of the Collection? How about if the collection contains different types? What should I do for this case?

As you know, in a HashMap, I can put in any objects as the value.

Nick



You could create a Collection of unkown type (wildcard).

This makes the Collection read-only.


 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That is to say, if I am sure what the object type is, I can specify it, like String, Integer, etc.

However, if I dont know what the object type is, I just simply put down <Object>.

But, do we really always know the type? If not, it seems that effort is duplicated for specifying the type as Object every time.

Nick
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

You mention annotations of one of the new to 1.5 things. I am having trouble grasping what this is and why I would use it. Do you know of any use cases where annotations would apply?
 
Cay Horstmann
author
Posts: 284
35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There was some discussion about iterating over a map. I think the best way to do this is to iterate over the entry set. It is cheaper than calling get for each key. Here is the code outline:



Cheers,

Cay
 
Cay Horstmann
author
Posts: 284
35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You wanted to know about annotations. Frankly, I found annotations the most confusing part of Java 5.0. The key observation is: An annotation is only useful when it is used in conjunction with a processing tool.

For example, you can define an annotation @TestMe that should be added to a method, perhaps with sample inputs and expected outputs. The user of your annotation would then decorate some methods with @TestMe. Then you would need to implement an annotation processor that acts on the annotation, perhaps generating JUnit test classes or simply running the tests. Implementing the annotation processor is the hard part.

There are three ways of implementing such a processor:
  • At the source level. The SDK has a tool skeleton called apt for this purpose.
  • At the bytecode level, for example by using Apache BCEL. This is wizard-level stuff.
  • In the VM. You can retrieve the annotation attributes through reflection.

  • This is all discussed in gory detail in Core Java vol. 2. I wrote a brief summary article for Amazon. They should have it on their web site real soon now.

    Cheers,

    Cay
     
    Nicholas Cheung
    Ranch Hand
    Posts: 4982
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator


    I wrote a brief summary article for Amazon.
    [/qoute]
    Cay, have you also written any technical articles or reviews on Tiger? If so, where could I find them?

    Nick

     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic