permaculture playing cards*
The moose likes Java in General and the fly likes Difference between Java 5 adn Java 1.4 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Difference between Java 5 adn Java 1.4" Watch "Difference between Java 5 adn Java 1.4" New topic
Author

Difference between Java 5 adn Java 1.4

michael yeung
Greenhorn

Joined: Oct 20, 2004
Posts: 16
What is the major difference between Java 5 and Java 1.4?

Thanks!!!


MCP (70-210), OCP9i DBA, SCJP 1.4 (SAI)
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
For more information on new features, you might read SUN's article:
http://java.sun.com/developer/technicalArticles/releases/j2se15langfeat/

Nick
Cay Horstmann
author
Ranch Hand

Joined: Nov 14, 2004
Posts: 114
    
  10
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


Author of Java 8 for the Really Impatient
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Cay,

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

Nick
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
New Feature in Java 5.0


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
michael yeung
Greenhorn

Joined: Oct 20, 2004
Posts: 16
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

Joined: Nov 07, 2003
Posts: 4982

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

Joined: Jul 04, 2003
Posts: 1312
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

Joined: Nov 07, 2003
Posts: 4982

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
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

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.




Groovy
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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
C Kutler
Ranch Hand

Joined: Apr 15, 2004
Posts: 62
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?


We learn by doing, there is no other way.
Cay Horstmann
author
Ranch Hand

Joined: Nov 14, 2004
Posts: 114
    
  10
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
Ranch Hand

Joined: Nov 14, 2004
Posts: 114
    
  10
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

    Joined: Nov 07, 2003
    Posts: 4982

    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Difference between Java 5 adn Java 1.4