• 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

Webservice doubts - Sun Tutorial

 
Ranch Hand
Posts: 751
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
     
    It means our mission is in jeapordy! Quick, read this tiny ad!
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic