Results 1 to 30 of 30

Java Programming : Doubts

  1. #1
    newprouser
    Guest

    Default Java Programming : Doubts

    1.

    What is the purpose of using Strings [] args in the following statement, considering that no value is being returned to the main function.

    public static void main (String[] args )

    and then string [] means a string is being returned, so why the statement args, that too without being separated by comma ?


    2. is it possible to have the following for loop like in C/C++


    for ( ; condition ; )
    { ..
    .. };

  2. #2
    Silver Member nandini's Avatar
    Join Date
    Jun 2009
    Posts
    482

    Default

    Quote Originally Posted by newprouser View Post
    1.

    What is the purpose of using Strings [] args in the following statement, considering that no value is being returned to the main function.

    public static void main (String[] args )

    and then string [] means a string is being returned, so why the statement args, that too without being separated by comma ?


    2. is it possible to have the following for loop like in C/C++


    for ( ; condition ; )
    { ..
    .. };


    1. public static void main(String[] args) is the method from where your java application begins.
    We can have multiple main method but the signature exactly matching to the above method, is recognised by jvm and it starts by calling that main method.
    It's like entry point.

    The purpose of using String[] args is that, you can provide inputs to your application before actually running it.

    String[] args means array of String. Hope you know what array is.

    2. Better to check for yourself. In my opinion it should run.
    वन्दे मातरम्

  3. #3
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    String args[] also.
    String... args also. This is called var args.
    What nandini had said is right? rep+ to her for beating me to answer.

  4. #4
    newprouser
    Guest

    Default

    Quote Originally Posted by nandini View Post
    1. public static void main(String[] args) is the method from where your java application begins.
    We can have multiple main method but the signature exactly matching to the above method, is recognised by jvm and it starts by calling that main method.
    It's like entry point.

    The purpose of using String[] args is that, you can provide inputs to your application before actually running it.

    String[] args means array of String. Hope you know what array is.
    well I have used C/C++ and OOPS in it too.

    are you talking about operator overloading in the first para ??


    2. Better to check for yourself. In my opinion it should run.
    not running. thats why i was wondering if there's any other alternative statement for that.

  5. #5
    Platinum Member
    Join Date
    Sep 2008
    Posts
    3,144

    Default

    NPU,

    that's the equivalent of main (argc, argv) in C and C++

    "String [] args" is the same as "char **argv" or "char *argv[]" for
    all practical purposes.

    they are the command line parameters when you run the program.

    -F

    what exactly is not working in your program?

  6. #6
    Silver Member nandini's Avatar
    Join Date
    Jun 2009
    Posts
    482

    Default

    1. It's not operator overloading. in fact java doesn't support operator overloading.

    you can declare an array of String in two ways.

    String[] arr=null; //more readable
    String arr[]=null;

    2.I think in for loop initialization is a must. So you can write like
    for(int i=0;condition; ) //it should work.
    by the way why the hell do you want to write it? Do you want to create infinite loop?

    PS: Farce is right,as usual.
    वन्दे मातरम्

  7. #7
    newprouser
    Guest

    Default

    Sorry can't rep now, will rep ya ASAIC

  8. #8
    Silver Member nandini's Avatar
    Join Date
    Jun 2009
    Posts
    482

    Default

    Quote Originally Posted by newprouser View Post
    Sorry can't rep now, will rep ya ASAIC
    It doesn't matter anything to me. What really important is that whether you got your doubt cleared.
    वन्दे मातरम्

  9. #9
    Platinum Member
    Join Date
    Sep 2008
    Posts
    3,144

    Default

    Quote Originally Posted by nandini View Post
    1by the way why the hell do you want to write it? Do you want to create infinite loop?
    break;
    goto
    return
    exit

    ;-)

    and what's wrong with infinite loops?
    this is the program that NPU is writing

    login to IBF
    for ( ;forever; ) {
    post :lol:
    }


    Quote Originally Posted by nandini View Post
    PS: Farce is right,as usual.
    my online reputation is much better than my domestic one ;-)
    I wish you could tell that to my wife ;-)

  10. #10
    newprouser
    Guest

    Default

    Quote Originally Posted by farce View Post
    NPU,

    that's the equivalent of main (argc, argv) in C and C++

    "String [] args" is the same as "char **argv" or "char *argv[]" for
    all practical purposes.

    they are the command line parameters when you run the program.

    -F
    Quote Originally Posted by nandini View Post
    1. It's not operator overloading. in fact java doesn't support operator overloading.

    you can declare an array of String in two ways.

    String[] arr=null; //more readable
    String arr[]=null;

    2.I think in for loop initialization is a must. So you can write like
    for(int i=0;condition; ) //it should work.
    by the way why the hell do you want to write it? Do you want to create infinite loop?

    PS: Farce is right,as usual.
    thanks both of you , got the first one cleared.


    Quote Originally Posted by farce View Post
    what exactly is not working in your program?
    well i'm not able to create a loop like this in java, atho it will work in C

    for ((blank) ; condition ;(blank) )

    by the way why the hell do you want to write it? Do you want to create infinite loop?
    even god won't know why i'm doing what i'm doing

    Quote Originally Posted by farce View Post
    break;
    goto
    return
    exit

    ;-)

    and what's wrong with infinite loops?
    this is the program that NPU is writing

    login to IBF
    for ( ;forever; ) {
    post :lol:
    }



    my online reputation is much better than my domestic one ;-)
    I wish you could tell that to my wife ;-)
    :lol:

    nice idea farce, maybe i should use Fx and use a macro with it

    ---

    :lol:

    Quote Originally Posted by farce View Post
    my online reputation is much better than my domestic one ;-)
    I wish you could tell that to my wife ;-)
    i'd guess her reply to be "the boss is always right :sneaky2: "
    Last edited by newprouser; 3rd August 2009 at 10:13 PM. Reason: Automerged Doublepost

  11. #11
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    It is working for me:-
    class Main {

    public static void main(String[] args)
    { int i=1 ;
    for ( ;i >0 ; )
    {
    i=1;
    }
    }
    }

  12. #12
    newprouser
    Guest

    Default

    Quote Originally Posted by Luke Skywalker View Post
    It is working for me:-
    class Main {

    public static void main(String[] args)
    { int i=1 ;
    for ( ;i >0 ; )
    {
    i=1;
    }
    }
    }
    My bad, i had initialized ch1 as zero, so that was the problem.

    public class chaz
    {
    public static void main (String[] args )
    {
    char ch1;

    ch1=1;

    for ( ; ch1 < 127 ; )
    {
    System.out.println(ch1);
    ch1++;
    }

    }
    }

  13. #13
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    That is also a valid program but it print character upto 127

  14. #14
    newprouser
    Guest

    Default

    Quote Originally Posted by Luke Skywalker View Post
    That is also a valid program but it print character upto 127
    yes, i was trying to print ASCII values, since its from 0-127, i initialized ch1 as 0., which seems to be the cause of the problem.

  15. #15
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    Post the exception & error you get. They are your best teachers.

  16. #16
    newprouser
    Guest

    Default

    Quote Originally Posted by Luke Skywalker View Post
    Post the exception & error you get. They are your best teachers.
    well well it was for a reason u guys asked me not to use an ide in the beginning, coz the original program (with ch1=0) is working fine in CMD, but in IDE , no output was displayed (except process completed).

  17. #17
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    Yes it will work. Don't use IDE now. Use cmd only.

  18. #18
    Silver Member nandini's Avatar
    Join Date
    Jun 2009
    Posts
    482

    Default

    Quote Originally Posted by newprouser View Post
    well well it was for a reason u guys asked me not to use an ide in the beginning, coz the original program (with ch1=0) is working fine in CMD, but in IDE , no output was displayed (except process completed).
    it can't be.
    post your code.
    वन्दे मातरम्

  19. #19
    newprouser
    Guest

    Default

    Quote Originally Posted by nandini View Post
    it can't be.
    post your code.
    public class chaz
    {
    public static void main (String[] args )
    {
    char ch1;

    ch1=0;

    for (;ch1<127; )
    {
    System.out.println(ch1);
    ch1++;
    }

    }
    }
    I use Jcreator Pro IDE. v4.5

  20. #20
    Silver Member
    Join Date
    Dec 2008
    Posts
    375

    Default

    Simple suggestion. Can't this be written as follows:

    public class chaz
    {
    public static void main (String[] args )
    {
    for (ch1=1;ch1<127; ch1++)
    {
    System.out.println(ch1);
    }

    }
    }

    This will be proper and clear way of coding as per the standard followed by many java developers.

  21. #21
    newprouser
    Guest

    Default

    Quote Originally Posted by matrix View Post
    Simple suggestion. Can't this be written as follows:

    public class chaz
    {
    public static void main (String[] args )
    {
    for (ch1=1;ch1<127; ch1++)
    {
    System.out.println(ch1);
    }

    }
    }

    This will be proper and clear way of coding as per the standard followed by many java developers.
    Sure, I'm a beginner to java.

  22. #22
    Silver Member
    Join Date
    Dec 2008
    Posts
    375

    Default

    Quote Originally Posted by newprouser View Post
    Sure, I'm a beginner to java.
    Well, it is better to follow a standard from the begining. Even I come across many who don't follow any standard. But suggestion is better follow a standard as you are already a C/C++ pro.

  23. #23
    newprouser
    Guest

    Default

    Quote Originally Posted by matrix View Post
    Well, it is better to follow a standard from the begining. Even I come across many who don't follow any standard. But suggestion is better follow a standard as you are already a C/C++ pro.
    oh if i knew i would. thats one disadvantage when one learns from e-books instead of computer courses i guess.

  24. #24
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    Which book are you using?

  25. #25
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    Which book are you using?

  26. #26
    newprouser
    Guest

    Default

    Java 2 - The Complete Reference 5edition, herbert schildt.

    Its outdated, but its the one I found to be easiest.

  27. #27
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    Head first Java is much easier & you will retain it more.

  28. #28
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    Head first Java is much easier & you will retain it more.

  29. #29
    newprouser
    Guest

    Default

    oh, i plan to use them side by side.

  30. #30
    Jedi knight Luke Skywalker's Avatar
    Join Date
    Jul 2009
    Posts
    2,174

    Default

    Here is the link for it. You can read it legally Head first Java - Google Books

Similar Threads

  1. GO | Google programming language
    By itsmemad in forum Computer technology
    Replies: 2
    Last Post: 17th February 2010, 11:17 AM
  2. Vote: would you like to have a programming section in IBF ?
    By newprouser in forum Suggestions and Complaints
    Replies: 38
    Last Post: 29th August 2009, 04:11 PM
  3. programming challenge...
    By nandini in forum Entertainment and Recreation
    Replies: 105
    Last Post: 28th August 2009, 08:58 PM
  4. Any how to videos for Flash Programming?
    By vishnu54 in forum Windows
    Replies: 0
    Last Post: 6th May 2009, 03:58 PM