Results 1 to 6 of 6
  1. #1
    DrAgonmoray is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Question New to Java, need some help

    Hio. I'm new to Java, and OOP. I am using NetBeans IDE.

    I've been googling around, but I can't seem to find a specific answer to what I am looking for. What exactly IS a package, and a library?

    Also, I've been looking at some tutorials and things, and I want to know what is mandatory and what is just popular trend. Do all .java files need a main class, and do all projects need a Main.java file?

    Any help would be appreciated. :)

  2. #2
    Navatha is offline Member
    Join Date
    Sep 2010
    Posts
    11
    Rep Power
    0

    Default

    Go through this link it will be helpful to you get some knowledge.
    Learn Java online with Java Beginner Tutorial

  3. #3
    DrAgonmoray is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default

    So everything needs a class, and inside that class a function called main? I was testing some things.

    Java Code:
    public class Main {
        public static void main(String[] args) {
            System.out.println("Hello, world!");
        }
    }
    That worked, but it didn't work when I removed the public class main (and it's curly brace) and it did not work when I changed the name of the main function. Is this correct?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,902
    Rep Power
    25

    Default

    The main() method your talking about is a requirement from the Java program as THE method it will call when starting the execution of your program. Any class you start execution of with the java command must have that method.

    There does NOT have to be a class named Main. The java program doesn't look for or require a class with that name. That name is a convention used by IDEs

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by DrAgonmoray View Post
    That worked, but it didn't work when I removed the public class main (and it's curly brace) and it did not work when I changed the name of the main function. Is this correct?
    Did you test the code without that line? If so what happen, any error message?

  6. #6
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Quote Originally Posted by DrAgonmoray View Post
    So everything needs a class, and inside that class a function called main? I was testing some things.

    Java Code:
    public class Main {
        public static void main(String[] args) {
            System.out.println("Hello, world!");
        }
    }
    That worked, but it didn't work when I removed the public class main (and it's curly brace) and it did not work when I changed the name of the main function. Is this correct?
    Every "library" needs an access point that is a main(). It needs to be static because static requires no instance declaration of the class, it needs to be public so it is accessible to all programs it needs curly braces because everything inside them defines a function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •