I have trouble understanding code in java because I am a beginner, can anyone help?
sure, what do you need help with specifically?
I can't quite understand classes and the syntax of this piece of code: class Hello { public static void main ( string[] args ) { system.out.println("Hello world!"); } } would you mind going through the syntax with me when you read it?
You have a class, Hello, it has one function, main, that does not return a value and has a single print statement in the body that displays "Hello World" to a console.
And as a beginner, shall I be using the class and all of this stuff to write my small java programs or shall I begin writing simple programs with a syntax much simpler like python syntax?
As you are using Java, you shall be using a class and all that stuff.
Java is a classy language.
Hi! I'm a beginner too, but I've learned some things through courses and online tutorials. I'll sum up that code you posted. The "class" is a collection of variables and methods (or functions, if you prefer to call them that) contained within the `{}`. Variables store data, methods change things (they do the action). Here, that class is addressed as "Hello." And Hello contains only the method ` public static void main ( string[] args )` `{}`. Each word in there (by there, I mean the "method declaration") means something. The `public` means a class besides Hello can use it. The `static`, I forget. The `void` means that this method does not return data as it finishes, which is a useful thing in other situations. The `main`, and notice that it's right before the parentheses, is the name of the method. For a reason I'm unaware of, this method is always called upon first. The `String[]` is an object, meaning it has variables and methods of its own, that stores strings of letters, pretty much. You'll soon learn about them. and `args` is the name for that `String[]`. It's significant that that is within the parentheses, because that means it is required by `main` and can be used in `main`. Within the method called `main` you have ` System.out.println("Hello world!");`. This starts the `println` method, used by `out`, which is in `System`. That sore of code might come later, depending on how you learn your Java. And look, the `println` has stuff INSIDE the parentheses. That is what the method will use. It uses that to print your text onto a console. Notice a few things. It's important how everything is in their `{}`s. Also, capitalization is important, and this code probably wouldn't compile without correcting some letters. And, in case you're new to programming, look at how organized it is - each time you go into a new block between `{}`s, you also indent. And the `{` and its complementary `}` are aligned, with the same indent as what the content belongs to. There are many styles of organization, but it's good to be organized.
Here's a nice tutorial, it'll even help you download a good program for writing and compiling code. http://www.java-made-easy.com/
After you learn to use java a little more, you might want a boost from premade stuff. This site has documentation for that stuff. http://docs.oracle.com/javase/7/docs/api/
And there are many other resources on the internet! Anyone, feel free to correct or debate anything I said! I think I made no mistake, but I accept that I very well might have. :)
thank you theEric, when I have further questions i'll ask for everything you wrote is crystal clear and easy to understand.
My pleasure, and I hope the people on OpenStudy will help the same another time :) Take care!
Join our real-time social learning platform and learn together with your friends!