File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What am I doing worng??????

 
alfredo navarro
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I been trying to learn JAVA on my own or at least the basics so later can attend classes and not be to slow in class ( my way of thinking).
Here is my problem.
1st
I have typed the following in a note pad
public class app
{
public static void main(String[] args)
{
System.out.println("Hello from Java!");
}
}
2nd
I saved it as Hello.app
3rd
changed the PATH
3rd
Open a Dos Promt and went to E:\Program Files\j2sdk_nb\j2sdk1.4.2\bin
4th
Javac Hello.app
But the only thing that I get is a browser with the same code
public class app
{
public static void main(String[] args)
{
System.out.println("Hello from Java!");
}
}

I have change the name of the the file, removed the J2sdk, Reinstall it and many other things. But in the best of the cases this is all I get a browser that will show the code
PLEASE HELP
 
Gabriel White
Ranch Hand
Posts: 233
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alfredo, after you run Javac Hello.app it should produce a file called Hello.class that contains the Java byte codes. If you got an error at this stage, go back to the editor(notepad) and make sure your file is exactly the same as the code given here. Javac, the byte code generator, is case sensitive. For example, if you entered string instead of String, javac would report an error. When you get no compile errors and have your Hello.class file, get the Java interpreter to run the bytecodes by entering: java Hello
The message "Hello from Java!" should be displayed in the DOS prompt window.
HTH
 
Billybob Marshall
Ranch Hand
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) if the class is named 'app', then the source file must be named 'app'.something (the convention would be app.java)
2) don't change directory to java's bin directory (that isn't where you put the source file, is it?)
etc etc etc
[ further edited along the lines explained by Ernest below -ds ]
[ February 28, 2004: Message edited by: Dirk Schreckmann ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I deleted several posts from this thread that were less than pleasant. Remember the "be nice" rule, folks. Thanks.
BillyBob, as I don't have any other way to contact you -- consider this your last warning.
[ February 27, 2004: Message edited by: Ernest Friedman-Hill ]
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alfredo,
It is proper practice to name java source files with a .java extension, such as MyClass.java
It is also common practice to name java classes so they start with an upper case letter.
And, it is mandatory that the Class name and file name match exactly. You have named your class app, but named the file Hello.app Rename your file app.java and then try to compile it. It should work fine for you at that point. (And if you want to follow normal conventions, rename you class App and then the file App.java - noticing the capital A on both).
Hope that helps you out...
And Welcome to JavaRanch
 
Joel McNary
Bartender
Posts: 1824
Eclipse IDE Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This intrigues me. How are you getting a browser? I tried the same thing, and got what I expected -- the following output:

How does a browser get invoked when calling javac?
 
Davy Kelly
Ranch Hand
Posts: 384
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alfredo, welcome to the ranch.
whatever clas you have

you save the file as Hello.java save as type: all files
then you can compile the file in the command line with javac Hello.java, once it has compiled without any problems, you can then run it by using the command line prompt with java Hello.
hope this helps break things down for you.
Davy
[ February 29, 2004: Message edited by: Davy Kelly ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, alfredo!
I been trying to learn JAVA on my own or at least the basics so later can attend classes and not be to slow in class ( my way of thinking).
Excellent way of thinking. I did something very similar and it worked out very well for me. The class was a cake walk and I learned a lot more than I otherwise would have learned, were I simply trying to follow along in the class and get an A.
 
Mark Vedder
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alfredo,
If it helps you any, there are several good (and free) resources available to you as you go about learning Java. Take a look at this recent thread for some suggestions. You can also search the Beginning Java forum for other tutorials.
Good luck in your self-studies, and be sure to post any questions you have.
 
Davy Kelly
Ranch Hand
Posts: 384
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
alfredo,
if you email me at davyk@ntlworld.com
i might be able to help you out!!!
Davy
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic