Results 1 to 14 of 14
Like Tree1Likes
  • 1 Post By jim829

Thread: Basic Questions

  1. #1
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Basic Questions

    1) Should every project have atleast one main method?
    2) Since eclipse comes with a built-in compiler do we need to have a JDK or a JRE alone is enough?

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Basic Questions

    1) depends on the application. Web applications have no main, neither do applets
    2) Modern versions of Eclipse require a runtime only
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic Questions

    2) Modern versions of Eclipse require a runtime only

    That means modern versions of eclipse come with a JDK?

  4. #4
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic Questions

    3) Can we say any application which uses web.xml is a web application?

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Basic Questions

    Quote Originally Posted by jmohandos304 View Post
    2) Modern versions of Eclipse require a runtime only

    That means modern versions of eclipse come with a JDK?
    ... no, not in any way.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Basic Questions

    Quote Originally Posted by jmohandos304 View Post
    3) Can we say any application which uses web.xml is a web application?
    If an application has a web.xml then it is almost certainly a (Java) web application. But not all Java web applications have a web.xml. A cow is an animal, but not all animals are cows so to say. You can also manually create a web.xml file, that does not magically turn whatever application you have into a web application.

    What makes it a web application is if you deploy it to a web container/server which will then service it through the web.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic Questions

    Quote Originally Posted by gimbal2 View Post
    ... no, not in any way.
    That means a Java program does not need a JDK(Java Development Kit)?

  8. #8
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Basic Questions

    No, only a runtime. You need a development kit to *drumroll* - develop Java programs! But since Eclipse has its own built-in compiler, when using Eclipse you can technically do without the JDK and manage with only a runtime installed.

    It can still benefit you to have one anyway, such as being able to use the command line tools part of the JDK, or have access to the src.zip that's in there.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic Questions

    4) Since constructor has no return value, how does a reference variable get initialized?

    e.g.
    Java Code:
    A a=new A();

  10. #10
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,275
    Rep Power
    6

    Default Re: Basic Questions

    A constructor is not a method, its an entirely different mechanism not to be compared.

    Don't ask questions before you took enough time trying to understand the material you are asking questions about.
    Last edited by gimbal2; 04-29-2014 at 01:59 PM. Reason: fix hasty assumption
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic Questions

    Quote Originally Posted by gimbal2 View Post
    What does a return value have to do with variable initialization?

    Don't ask questions before you took enough time trying to understand the material you are asking questions about.
    Lets take an example:
    Java Code:
    package Yes;
    class A
    {
       public static void main(String args[])
       {
            int i=func();
            A a =new A();
       }
       A()
       {
    	   
       }
       static int func()
       {
    	   return 10;
       }
    }
    Try to draw the comparison I am trying to make. A constructor is like a method which has the same name as the class.

  12. #12
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,182
    Rep Power
    20

    Default Re: Basic Questions

    It doesn't require a return value because it's a constructor.
    How it works is all down to the specification of how Java works involving the 'new' keyword and a constructor call.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  13. #13
    jmohandos304 is offline Senior Member
    Join Date
    Apr 2014
    Posts
    122
    Rep Power
    0

    Default Re: Basic Questions

    Quote Originally Posted by Tolls View Post
    It doesn't require a return value because it's a constructor.
    How it works is all down to the specification of how Java works involving the 'new' keyword and a constructor call.
    Where can I get explanation for what happens when new operator is used? And how the reference variable a gets initialized?

    Eg.,
    Java Code:
    A a = new A();

  14. #14
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,923
    Rep Power
    5

    Default Re: Basic Questions

    Check out the Java Language Specification --> Chapter*12.*Execution

    Regards,
    Jim
    Tolls likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Some basic questions - Java
    By Fusion in forum New To Java
    Replies: 4
    Last Post: 04-02-2014, 12:54 AM
  2. Basic GUI questions
    By sunde887 in forum New To Java
    Replies: 6
    Last Post: 02-11-2011, 07:11 PM
  3. VERY basic Java questions
    By hayden06f4i in forum New To Java
    Replies: 6
    Last Post: 11-10-2010, 09:09 PM
  4. Basic Image Questions
    By DaRancor in forum AWT / Swing
    Replies: 6
    Last Post: 11-22-2009, 01:20 AM

Posting Permissions

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