This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes What am I doing worng?????? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What am I doing worng??????" Watch "What am I doing worng??????" New topic
Author

What am I doing worng??????

alfredo navarro
Greenhorn

Joined: Sep 20, 2003
Posts: 2
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

Joined: Mar 02, 2003
Posts: 233
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

Joined: Jan 27, 2004
Posts: 202
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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 ]

[Jess in Action][AskingGoodQuestions]
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

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

Joined: Aug 20, 2001
Posts: 1821

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?


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Davy Kelly
Ranch Hand

Joined: Jan 12, 2004
Posts: 384
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 ]

How simple does it have to be???
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

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

Joined: Jan 12, 2004
Posts: 384
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
 
subject: What am I doing worng??????