Results 1 to 9 of 9

Thread: Query. . .??

  1. #1
    JSMundada is offline Member
    Join Date
    Apr 2014
    Posts
    2
    Rep Power
    0

    Unhappy Query. . .??

    What happend if main() function is written as private in java. . .????

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

    Default Re: Query. . .??

    compile error probably. Try it and see!
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    988
    Rep Power
    2

    Default Re: Query. . .??

    No compile error. Still you have to try and see to understand. Make a class with a public static void main(String args[]) and run it. Then try it again after making it private. It takes more keystrokes to register on a forum and ask this question than to try it yourself.

    Do you remember when you were young and wanted to know if there was power on the electric fence around a meadow? Instead of writing a letter to the farmer who owns the meadow and ask, just try it! Touch it! Or pee on it! Just... do it!
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

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

    Default Re: Query. . .??

    Hm yeah I guess that this would not be a case where the compiler holds your hand even though it would be 99.99999% certain its a mistake. I don't think I ever tried it myself to be honest, I just followed the rules as written like a good boy.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

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

    Default Re: Query. . .??

    Quote Originally Posted by SurfMan View Post
    Or pee on it! Just... do it!
    <Public Service Announcement> It is not recommended that you pee on your computer. </Public Service Announcement>
    Please do not ask for code as refusal often offends.

    ** This space for rent **

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

    Default Re: Query. . .??

    Quote Originally Posted by Tolls View Post
    <Public Service Announcement> It is not recommended that you pee on your computer. </Public Service Announcement>
    The sad part is that I know you're not posting this as a joke.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    Join Date
    Apr 2014
    Posts
    3
    Rep Power
    0

    Default Re: Query. . .??

    i think by convention main block should be public since its the method needed to access other method.Why will you declare a main private in high level java reprogramming where main do not (should not) have method blocks within it.You declare a particular block(method,interface,class) private when you want to represent data hiding.In main as no methods blocks are present there is no use of data hiding by declaring it privateok :)

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

    Default Re: Query. . .??

    Quote Originally Posted by sachin@kolkata View Post
    i think by convention main block should be public since its the method needed to access other method.Why will you declare a main private in high level java reprogramming where main do not (should not) have method blocks within it.You declare a particular block(method,interface,class) private when you want to represent data hiding.In main as no methods blocks are present there is no use of data hiding by declaring it privateok :)
    Not entirely, but you're thinking in the right direction.

    Think from a different perspective: the main() is the entry point of the application, that is where it all begins. It is the one method that the Java runtime will look for to go ahead and run your application.

    Making the main() private is like putting a door in your house to allow entrance into it and then building a brick wall in front of it. Sure your house is secure then, but you can't get in or out yourself either so both the door and the house are useless.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    988
    Rep Power
    2

    Default Re: Query. . .??

    Quote Originally Posted by sachin@kolkata View Post
    i think by convention main block should be public since its the method needed to access other method.Why will you declare a main private in high level java reprogramming where main do not (should not) have method blocks within it.You declare a particular block(method,interface,class) private when you want to represent data hiding.In main as no methods blocks are present there is no use of data hiding by declaring it privateok :)
    There is no error when creating a private static void main(String[] args) method. The only downside is that you can't use it as a starting point for your application. That's all. If you want to use it as a starting point, then you must adhere to the spec, which (logically) says main() must be public.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Replies: 3
    Last Post: 10-19-2012, 10:16 PM
  2. Sql Query
    By Nomad in forum JDBC
    Replies: 16
    Last Post: 02-20-2009, 01:58 PM
  3. I need help with a query.
    By Daredemo in forum JDBC
    Replies: 1
    Last Post: 08-13-2008, 05:16 AM
  4. Help in Query
    By geeta_ravikanti in forum JDBC
    Replies: 0
    Last Post: 03-31-2008, 01:16 PM
  5. Using sql:query tag
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-15-2008, 03:13 PM

Posting Permissions

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