Thread: Java Concepts

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    913

    Java Concepts

    Im looking at Java book for CS AP, but i dont get all stuff.

    Code:
    public class Test {
    	public static void main(String[] args) {
    		System.out.println("test");
    	}
    }
    How can main be inside of something?

    Do all class have to have a main?

    This is alittle funky...

    Thanks

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    385
    Not every class has a main but every main has to be in a class. Object oriented programming is a bit different from procedural languages.
    Wandering aimlessly through C.....

    http://dbrink.phpwebhosting.com

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Java is a little different than C++. Everything must be a class (or interface), so there's a controlling class that contains the main function as an entry point. Annoyingly, the name of that controlling class is also the name of the source file.
    My best code is written with the delete key.

  4. #4
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Just so you know, it's supposed to be String args[] now.
    Do not make direct eye contact with me.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Just so you know, it's supposed to be String args[] now.
    You can do it both ways. Your way may be 'preferred' now (if you're correct that is), but to require it would break far too much code. I don't think Sun is willing to risk doing that.
    My best code is written with the delete key.

  6. #6
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Yes, preferred as int main is preferred to void main .
    Do not make direct eye contact with me.

  7. #7
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Originally posted by Lurker
    Yes, preferred as int main is preferred to void main .
    That's in C/C++, not Java.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  8. #8
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    . Annoyingly, the name of that controlling class is also the name of the source file.
    This is true only if the class is declared public.

    Just so you know, it's supposed to be String args[] now.
    Can you verify your claim? I'm pretty sure Sun has always encouraged String[] args. This style better reflects the fact that args is an array of references to String objects.

  9. #9
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    Back to my original question, how could i keep tract of all those objects?

    If every student gets a object from the class how i can i make a object for every student without knowing their name or how many there are?

    In C it would be a linked list, could some on show me a mock up of a java one please?

  10. #10
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Originally posted by mart_man00
    Back to my original question, how could i keep tract of all those objects?

    If every student gets a object from the class how i can i make a object for every student without knowing their name or how many there are?

    In C it would be a linked list, could some on show me a mock up of a java one please?
    i assume you are referring to your other java thread?

    Code:
    import java.util.LinkedList;
    .....
    LinkedList list = new LinkedList();
    .....

  11. #11
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    Java also has linked lists. The principles are the same. Alternatively you can use the vector class.

  12. #12
    Registered User
    Join Date
    Jul 2002
    Posts
    913
    Alternatively you can use the vector class.
    Should i be looking at that instead? Whats move Java-y?

    i assume you are referring to your other java thread?
    Doh!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Java for real-time applications
    By zacs7 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 08-26-2008, 06:34 AM
  2. C#, Java, C++
    By incognito in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 10-05-2004, 02:06 PM
  3. The Java language is being expanded
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 06-11-2004, 09:07 PM
  4. Java woes
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 07-06-2003, 12:37 AM
  5. C or Java as a first language
    By CorJava in forum A Brief History of Cprogramming.com
    Replies: 34
    Last Post: 10-23-2002, 05:12 PM