• 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

Best way to structure a Java program

 
Ranch Hand
Posts: 55
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,
I built a small java program that opens a browser window with a specified URL. I'm looking for advice as to how to structure it correctly. Bellow is the code any my attempt at structuring any advice and guidance will be a great help. Thanks in advanced!




 
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A few things I've noticed:

1.) you don't set myUrl, you should most likely assign it to the return value of method urlOut
2.) I would not keep more than one line of code in the public static void main
3.) I would name your methods differently and don't see a reason why urlOut is a static method in the launch class while desktopsupport is an instance method in a separate class, besides desktopsupport is not camel-cased
4.) I see one flaw in urlOut immediately, it doesn't detect for https://; it also wouldn't add a protocoll if http:// was in the middle of the String (use startsWith() instead)
5.) urlOut should not evaluate args[], instead args[0] should be passed to it and the size of args should be evaluated before
6.) why do you set bing.com temporarily and google.com as default location?

Considering the size and purpose of your code I would say it's not really important to stick to OOP design, it's more important the code functions correctly and that you consider refactoring if you decide to add a whole lot of new code.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ray mann wrote:. . .

You also have problems with your comments. Comments are supposed to explain what you are doing; most of your comments simply repeat what is obvious from the code and should be removed. They also make the lines too long. // Comments should be very short; anything longer should be written in /* comments */.
Also you have the documentation comment in the wrong place; is should go after the import declarations. It should start with a simple one‑sentence description of the class, because the javadoc tool separates out the first sentence, and should therefore not begin with “Description:”.
reply
    Bookmark Topic Watch Topic
  • New Topic