Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Webservice doubts - Sun Tutorial  RSS feed

 
Timothy Sam
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys! I was reading through the Sun tutorial and this portion really makes me wonder if the problems I see are intended or not

http://java.sun.com/webservices/docs/2.0/tutorial/doc/JAXWS3.html#wp144960


First, it instantiates a String like

mesage=new String("Hello, ");

which should have just been

message = "Hello, ";


Second, the article says "The implementation class also must define a default, public, no-argument constructor."

But there's no public constructor there but a method

public void Hello() {}

and I'm sure that is not a constructor! The annotations also has open-close parenthesis which makes me wonder... Is there something wrong here?
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Timothy Sam:
First, it instantiates a String like

mesage=new String("Hello, ");

which should have just been

message = "Hello, ";


Both will work - given the circumstances I would have preferred the second one. The "Hello, " string literal goes into the string pool were it can be reused (remember Strings are immutable). The second version references that string literal directly. The first version creates another, separate string object (copying the string literal) which is entirely unnecessary

Second, the article says "The implementation class also must define a default, public, no-argument constructor."

But there's no public constructor there but a method

public void Hello() {}


  • You are correct that is not a constructor. The "void" its the dead giveaway.
  • However there is a "default, public, no-argument constructor". You may remember from your SCJP preparation: the Java compiler will add a "public, no-argument constructor" if there is no other constructor present.


  • The annotations also has open-close parenthesis which makes me wonder... Is there something wrong here?


    The annotation looks ok. The parenthesis actually have a use under different circumstances. See:
    The Java Tutorials: Annotations
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!