• Advertisement
Sign in to follow this  

[java] Can't compile hello world!

This topic is 4717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I just picked up a book on Java recently and have just today tried using it. I downloaded the J2SE SDK and installed it. The compiler is working because if I go to the command prompt and type javac it gives me compiler info. Well I went to notepad and typed the code public class Hello { public static void main (String[] args) { System.out.printIn("Hello World"); } } and saved it as Hello.java. Then I went to the command prompt, went to the folder "c:\myjava\" where I saved the file and tyoed javac Hello.java and it gave me one error saying that it didn't understand the symbol "." after "out". I figured that maybe it was because the file still had the .txt extension (i.e. Hello.java.txt) so in the command prompt I typed "ren Hello.java.txt Hello.java" and got the same error. It's not even showing the java icon for the .java files :( . By the looks of the book this should work fine. Can anyone help me? -Jake [Edited by - jake2431 on March 14, 2005 9:23:50 PM]

Share this post


Link to post
Share on other sites
Advertisement
Rating+ for you! Ahh.... now I feel stupid. Lowercase L's and Uppercase I's always confuse me in some fonts, but I still should have thought of that. For some reason I was thinking that the command was print in and didn't consider print line. Well, thanks alot though. Any idea why when I save as .java it doesn't give a java Icon it just gives the notepad icon. The reason I ask is because in the book his files have a icon. Maybe it's because of the IDE he is using and I'm not, but it seems like it would display after installing all the java stuff. Thansk again for the help.

-Jake

Edit: Now even the compiled file doesn't have an icon, but it did compile! Yes, I'm so excited. I love learning new stuff.

Share this post


Link to post
Share on other sites
You need to go to folder options in the settings tab and click on the file settings (or something like that :-) Tab, find the .java extention and click the change button. Then a dialog should come up, click change icon and locate the icon that you would like .java files to display. then click OK a lot of times, hope that helped ( i use Windows 98).

Share this post


Link to post
Share on other sites
I couldn't figure it out, thanks for the help though. I am running WinXP so it may be different. The closest thing I could find was the folder options > file types, but there isn't even a .java file type named.
-Jake

Share this post


Link to post
Share on other sites
Quote:
Original post by jake2431
I couldn't figure it out, thanks for the help though. I am running WinXP so it may be different. The closest thing I could find was the folder options > file types, but there isn't even a .java file type named.

Files, such as .java or any other, are delegated icons solely on the program used to open them. Since you're working from a command line instead of an IDE, .java files are naturally associated with Notepad. If you want to change this, you need to install an IDE - such as Textpad, Eclipse, MSVC will append .java files with the evil J# icon, *insert other IDE here*. The IDE installation will usually associate these files for you. However, if you already have an IDE, or just want to open .java files with a different program, do the following :
 - Highlight and right-click on any java file
- In the pop-up menu, choose "Open-With"
- Select the .exe (the .exe itself, shortcuts won't work) and click "Ok", or "Open"
- Click the box labeled "Always open with this program"
- Exit

All .java files should now be associated with whatever program you chose, and if there is no "special" .java icon, they will now have the program's default icon.

*Disclaimer : There is probably a generic method for changing icons ... but the above works if that's what you want.
Quote:
Edit: Now even the compiled file doesn't have an icon, but it did compile! Yes, I'm so excited. I love learning new stuff.

Heh, that's good. Java is good stuff. As for the .class file not having an icon, that's normal. You can't edit the contents so there's no point in opening them.

Share this post


Link to post
Share on other sites
Thanks for everyone's help. So I guess my assumption that it may be his IDE was correct. Yeah I love the open with option; I hate when computers don't have that (like some at my school. I hate having to go to the exe and open from there). The reason I didn't know if it should have a icon automatically is because of my experience with HTML and javascript. You know when you save as .js it automatically comes up with the icon for it even though I only open it with notepad. I just never click the always open with this program thing. Thanks again for all the help guys, the gamedev forums are awesome for finding knowledgeable people who are willing to help. Now I have to work on a final project for Life Drawing and then I will resume coding.

-Jake

Share this post


Link to post
Share on other sites
Ummm. I have another question. The book I am using uses JPadPro as its IDE. I know this question will be highly opinion based, but what is the best free Java IDE. By free I mean one that is completly free; as in you can make a program and sell it if you want. Any suggestions?

Share this post


Link to post
Share on other sites
Eclipse, JBuilder and JCreator are my favorites with Eclipse probably being my very favorite. I like Eclipse for its features, JBuilder for its simplicity and JCreator for its speed. All of which are free (or have a free version). I don't think the IDE you use to write code has anything to do with the licensing issues of your finished application - the IDE just simplifies the organization/writing of source files, the compilation and possibly the debugging. Correct me if I'm wrong.

Share this post


Link to post
Share on other sites
I'd start off with JCreator and when you're projects get large enough for you to find it limiting switch to Eclipse. Starting off with Eclipse is also possible (there's a good tutorial I believe) but it might be a bit overwhelming if you are learning Java at the same time.

Cheers

kezz

Share this post


Link to post
Share on other sites
Thanks everyone! I will try these out and see what works for me. Not sure about the licensing issue, but I think you might be right. Thanks to everyone here I am well on my way to learning Java.

-Jake

Share this post


Link to post
Share on other sites
the first time I tried to compile a java version of Hello World I typed up the code and I numbered each line because that's how it was in the book. Needless to say, it didn't work. I was puzzled for about an hour hehe.

Share this post


Link to post
Share on other sites
Once you get past the "hello world" console application, you might want to consider the "hello world" applet. Of course, it will be a bit harder to work with, but this site has such a tutorial in the Articles section. Also, if you didn't already know, there are two ways to print:


//starts new line after printing
System.out.println("Text");

//continues on same line
System.out.print("Text");



As far as IDE's go, I was using NetBeans, but switched to JCreator for greater speed.

Share this post


Link to post
Share on other sites
Hey, thanks for the help. I'm actually on page 80 something in the book now (I've been slacking) so I actually now a bit more now. I haven't go to applets yet, but it's coming soon. I did see that there were two print functions(methods maybe in Java), but I couldn't figure out why they needed two. Does it have something to do with the print line thing, as in it will only print a single line. I guess not because theey still use the \n for new line. Thanks again.

-Jake

Share this post


Link to post
Share on other sites
System.out.println("test");

will have the same result as

System.out.print("test\n");

println() just appends a \n for you.

Share this post


Link to post
Share on other sites
Thanks, thats the only thing I could think of that would be different if there was a difference.

-Jake

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement