• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why is the () required? and other Java-related questions.  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys! So I'm brand new to both these forums and Java. The thing I love about the programming community is that it is one of the rare communities that is almost unanimously catering to each-other. Yeah, there is a lot of cross-language rivalry, but I've NEVER encountered a time where I was denied help by anyone, regardless of the language. And you here and Code Ranch seem to exemplify that!

Anyways, I'm setting out on a brave new adventure to try and learn Java, which has been a bit of a life goal of mine. I picked up a copy of Head-First Java (Second Edition), and I have nothing but high praise for it. It's the second most user-friendly programming book I've ever read, behind only "Learn To Program" by Chris Pine. (Ruby fanboy bias.)

My only issue is with the style it teaches. It has you programming a lot of things, but doesn't explain them until a later chapter. It's not a criticism at all, I know some people love to learn that way, I just like to know what I'm working with.

So a few questions:

-I noticed a lot of times, you are required to put an empty () after a lot of things, like when you are calling a method and such. What is the reason for it?

-What is the purpose of declaring (String[]args) after your main method? The bookk made it quite clear it's something you have to do, but never quite explained why.

- What is the purpose of while (true)? I know in some languages, it's to create a never-ending loop. Is that true in Java as well?

Thanks a ton in advance, and I'm thrilled to have found this community!
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The () is part of the syntax for a method call. You can have a method foo() and a field foo which are distinguished by the presence or absence of (). The posh name for that is disambiguation.
The main method called by the JVM is expected to take an array of Strings; this goes back to the days of C and you can pass information from the command line. You may not need it at present, but you can read about it in the Java Tutorials.
Yes, while(true)… constitutes an infinite loop. Whether you ever want an infinite loop is a different matter!

And welcome to the Ranch We shall try to live up to your expectations.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!