patternjavaMajor
Hello World, Phrancis
Viewed 0 times
helloworldphrancis
Problem
I just yesterday started learning some Java. I wrote this piece and got some help from @Simon André Forsberg to refine it some. I added a few things since. It's super-simple but I just want to make sure I have a few concepts down before I move on to more complex things. Any constructive criticism is appreciated!
Console output:
import java.lang.*;
public class HelloWorld {
private final String output;
public HelloWorld(String name) {
output = "Hello World, " + name + "!";
}
public String getMessage() {
return output;
}
public static void main (String args[]) {
HelloWorld helloObj;
helloObj = new HelloWorld("Phrancis");
System.out.println(helloObj.getMessage());
}
}Console output:
Hello World, Phrancis!Solution
First things first:
This import is superfluous. Java by default imports the
You seem to be using consistent two newlines between last
While this is a perfectly valid declaration for main, I'd prefer to have the array declaration behind the type and not behind the argument name for consistency's sake:
import java.lang.*;This import is superfluous. Java by default imports the
java.lang package, you don't have to specify any further things.You seem to be using consistent two newlines between last
} and the next opening brace. I personally find this to take a lot of space and I'd reserve "large" vertical distance to signify sectioning or similar, it's consistent ;)public static void main (String args[]) {While this is a perfectly valid declaration for main, I'd prefer to have the array declaration behind the type and not behind the argument name for consistency's sake:
public static void main (String[] args) {Code Snippets
import java.lang.*;public static void main (String args[]) {public static void main (String[] args) {Context
StackExchange Code Review Q#71537, answer score: 26
Revisions (0)
No revisions yet.