• Post Reply Bookmark Topic Watch Topic
  • New Topic

Best way to structure a Java program  RSS feed

 
Ray mann
Ranch Hand
Posts: 48
Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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!




 
Peter Muster
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • 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:”.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!