Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A simple program ???

 
Vaskar Dasgupta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class test{
public static void main(String args[]){
for (int i = 0;i < args.length; i++) {
System.out.println("File " + i + ":" + args[i]);
}
if (args.length<=0) {
System.out.println("No files!");
}
}
}
Compile it and
Run this program using - java test * (its a star)
The out put of this program is the name of the files and folders in the directory from where it is run. No other special character used in the command prompt works like this except *......Any explanations ???
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the '?' also works

[ February 06, 2002: Message edited by: Marilyn deQueiroz ]
 
Vaskar Dasgupta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java ?.java ...................... i didn't get it, does not work for me. ? is not the name of the file so ?.java will throw a exception " Exception in thread "main" java.lang.NoClassDefFoundError: ?/java "
 
Erik Dark
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't work for me neither. Suppose Marilyn meant
But that also doesn't work...Marilyn can you explain what you mean? (learned you can browse your current directory this way..did'nt know!)
TIA Erik Dark
[ February 06, 2002: Message edited by: Erik Dark ]
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vaskar,
In java you always need to include the name of the program. How else would the JVM know which class to execute?
Marilyn just made a small typo:
input:
java TestListFiles ?.java
Regards,
Manfred.
 
Vaskar Dasgupta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry to say even that doesnt work for me... i mean the ?......... "java fileName ?.java" does not work for me at all....this is my output, my file name is test.java
D:\>java test ?.java
?.java
 
Vaskar Dasgupta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you give an explanation for my first query java test * (the star) ???
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All they are showing is that using the * as an input parameter points back to the contents of the directory that you are sitting in at execution time.
So when you say
>java Test *
you are saying "execute Test with this directories content list as input".
Try
>java Test *.java
and you will get a list of just those files that end with .java.
 
Vaskar Dasgupta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does the JVM understand that, when it is DOS command. Is it something to do with the way the program 'java.exe' works ? Awaiting a reply..............
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Of course it was a typo - I've edited my previous post)

Since the JVM is written in native code, it would seem logical that it could use a wild card in DOS. It would also seem logical that the same would hold true in a JVM in a unix/linux environment. I wonder if this would also happen in a MacIntosh JVM.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM never sees the '*' - it is interpreted by the operating system before it is passed to the JVM.
 
Vaskar Dasgupta
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as i understand java.exe by default will look for the class files in the current directory where it is being run from, using a * buffers the directory contents, and the small simple program parsers the * to get the output on the screen..............Somebody please give adetailed explanation, if possible how the code actually works if by using a verbose output (java -verbose test * .........Could not get anything after trying for myself). Any figures or aatachments are welocome to
d_vaskar.cgmaersk@maerskdata.dk
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic