This is a discussion on Java Programming : Doubts within the Windows forums, part of the Operating Systems category; 1. What is the purpose of using Strings [] args in the following statement, considering that no value is being ...
| |||||||
| | #1 |
| Guest
Posts: n/a
| 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 | |
| Gold Member Join Date: Jun 2009 Location: Pune
Posts: 487
Rep Power: 3 | Quote:
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 |
| Jedi knight Join Date: Jul 2009 Location: IBF Age: 21
Posts: 1,816
Rep Power: 5 | 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 | ||
| Guest
Posts: n/a
| Quote:
are you talking about operator overloading in the first para ?? Quote:
| ||
| |
| | #5 |
| Platinum Member Join Date: Sep 2008
Posts: 3,140
Rep Power: 10 | 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 |
| Gold Member Join Date: Jun 2009 Location: Pune
Posts: 487
Rep Power: 3 | 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 |
| Guest
Posts: n/a
| Sorry can't rep now, will rep ya ASAIC |
| |
| | #8 |
| Gold Member Join Date: Jun 2009 Location: Pune
Posts: 487
Rep Power: 3 | |
| | |
| | #9 | |
| Platinum Member Join Date: Sep 2008
Posts: 3,140
Rep Power: 10 | Quote:
goto return exit ;-) and what's wrong with infinite loops? this is the program that NPU is writing login to IBF for ( ;forever; ) { post } my online reputation is much better than my domestic one ;-) I wish you could tell that to my wife ;-) | |
| | |
| | #10 | |||||
| Guest
Posts: n/a
| Quote:
Quote:
well i'm not able to create a loop like this in java, atho it will work in C for ((blank) ; condition ;(blank) ) Quote:
Quote:
![]() nice idea farce, maybe i should use Fx and use a macro with it --- ![]() Quote:
" Last edited by newprouser; 08-03-09 at 11:43 PM. Reason: Automerged Doublepost | |||||
| |
| | #11 |
| Jedi knight Join Date: Jul 2009 Location: IBF Age: 21
Posts: 1,816
Rep Power: 5 | It is working for me:- class Main { public static void main(String[] args) { int i=1 ; for ( ;i >0 ; ) { i=1; } } } |
| | |
| | #12 | ||
| Guest
Posts: n/a
| Quote:
Quote:
| ||
| |
| | #13 |
| Jedi knight Join Date: Jul 2009 Location: IBF Age: 21
Posts: 1,816
Rep Power: 5 | That is also a valid program but it print character upto 127 |
| | |
| | #14 |
| Guest
Posts: n/a
| |
| |
| | #15 |
| Jedi knight Join Date: Jul 2009 Location: IBF Age: 21
Posts: 1,816
Rep Power: 5 | Post the exception & error you get. They are your best teachers. |
| | |
| | #16 |
| Guest
Posts: n/a
| 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 |
| Jedi knight Join Date: Jul 2009 Location: IBF Age: 21
Posts: 1,816
Rep Power: 5 | Yes it will work. Don't use IDE now. Use cmd only. |
| | |
| | #18 |
| Gold Member Join Date: Jun 2009 Location: Pune
Posts: 487
Rep Power: 3 | |
| | |
| | #19 |
| Guest
Posts: n/a
| |
| |
| | #20 |
| Bronze Member Join Date: Dec 2008 Location: Kalyan West
Posts: 254
Rep Power: 1 | 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. |
| | |
| Tags |
| doubts, java, programming |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Vote: would you like to have a programming section in IBF ? | newprouser | Suggestions and Complaints | 30 | 08-30-09 12:56 AM |
| Learning Java ~ What are the best choices of tools ? | newprouser | Windows | 42 | 08-01-09 08:05 PM |
| Installling java | saurabh2446 | Nokia | 1 | 06-23-09 12:44 PM |
| Any how to videos for Flash Programming? | vishnu54 | Windows | 0 | 05-06-09 05:28 PM |