• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Not compiling but Running

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hello Please Help Me out in this
I am having .java file while compiling it Iam getting an Error
but Inspite of that .class Files are created.Now I can Run that
File and get the Desired output.
Why is it so...
Following is the code
private class ex{

private static void main(String args[]){
System.out.println("hello");
}
}
javac ex.java
The type type ex can't be Private.Package members are always accessible within the current package.
1error

output
java ex
hello

Thanks in Advance...
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't tell you why this compiles. I didn't think it would but I tried it and I got exactly the same results as you. I can tell you what the problem is - the class should be public or have no access modified (i.e. be friendly) because it's a top-level class. The main method should be public too - I believe that's a known bug. Does anyone else know why this compiles?
Kathy
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Intresting one ... Could anyone please explain why it is like this ....
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not exactly sure why it complies, but I have had the same thing happen with some of my programs, that even though the compliler generated an error, the program still compiles. I would guess it would have do to with the severity of the error. Some errors will make code that is still able to run, although maybe not exactly as intended, while other's would generate unrunnable code.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
private static void main
is a known bug it's been documented on sun page i remember reading it there about it.
******************************************
Marine
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please choose a new name which meets the requirements.
[This message has been edited by Cindy Glass (edited January 27, 2001).]
[This message has been edited by Cindy Glass (edited January 27, 2001).]
 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sathish,
The main method must be public, since the JRE has to be able to call it to begin execution of your program. Just like the init method of an applet, except in that case it is the browser calling it instead of the JRE.
~Ryan
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
marine,
Your name does not comply with the Javaranch naming guidelines which can be found at http://www.javaranch.com/name.jsp please register again with a valid name.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using JDK 1.3 and when I tried to compile it, javac showed the error and DID NOT create the .class file. Perhaps this was a bug in earlier releases of JDK (as another member noted), and isn't present in JDK 1.3.

------------------
Manish.
reply
    Bookmark Topic Watch Topic
  • New Topic