• Post Reply Bookmark Topic Watch Topic
  • New Topic

Cant get the 'MooseGreeting.java' to compile  RSS feed

 
Daniel Mikkelsen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, first of, im a complete newbie with zero programming experience

I can't get the MooseGreeting.java to compile when I follow this tutorial http://www.coderanch.com/how-to/java/how-to-create-java-program

My command promt tells me the following when I try the 'javac MooseGreetings.java' command:

javac: file not found: MooseGreetings.java
Usage: javac <options> <source files>
use -help for a list of possible options

I've made sure that the path is set correct (the 'javac -version' works. It displays 'javac 1.8.0_11' when I type in 'javac -version')

I've installed the jdk (1.8.0_11)

I've created the file in Rich Text

I use windows 7, 32

I've restarted my PC
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
where are you when you run javac? Where is the "MooseGreetings.java" file?

I'm not sure what you mean by "i've created the file in Rich Text", but that may not be what you want. It needs to be plain text - no formatting, no control characters, no anything but plain, simple text.

From a command line, enter the command "type MooseGreetings.java" - if you get something readable, you are OK. If you get all kinds of weird symbols, you are not. (Note: you must be in the same directory where MooseGreetings.java is for this to work, or you must provide the path to it...)
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there definitely a file called MooseGreetings.java in the directory you're running the command from.
Some editors automatically add an extra extension such as .txt or .rtf.
Run the dir command in that directory to make sure it is correctly named.

Daniel Mikkelsen wrote:I've created the file in Rich Text

Don't do that. RTF files contain formatting information which will confuse the compiler. Always save the files in plain text format.
 
Daniel Mikkelsen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, forgot to say that. It's in program files\java\src, but I've found the problem.

The only text programs I've both add txt or rtf at the end. Discovered that with Joanne's 'dir' function (wasn't aware of that before). I just looked in my map, and in there, it seemed perfectly fine with the .java at the end. But using dir, I can see that is not the case..

Good news: my problem has been found!
Bad news: I don't have any other text editors than those two which both adds txt or rtf, can you recommend any - preferable free (im a poor student ;) )?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use something called ConTEXT (http://www.contexteditor.org/index.php). Lots of people here like Notepad++ (http://notepad-plus-plus.org/).

You can actually use windows notepad (or probably anything else), you just need to be sure when you save it, you make sure you save it as a text file (.txt) in the Save as Type option.

 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We just happen to have an Editor FAQ that you might find useful. Most of them are free.
 
Daniel Mikkelsen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestions. I'll give them a dekko

I don't understand: you want me to save them as .txt? I was of the thought, when I save them as .txt, it makes the .java unable to function? At least, that was my experience with MooseGreetings
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Daniel Mikkelsen wrote:I don't understand: you want me to save them as .txt?

Sorry - trying to do too many things at once...

you need to save it as a .java file. but you need to save is as plain text - not rich text. Most editors, when you go to save a file, have two things - one where you type in the name you want to save it as, and another that lets you say what TYPE of file it is. in Notepad, one option for "save as type" is "Text Documents (*.txt)", but if in the "File name" you type "MooseGreetings.java", it will save it as "MooseGreetings.java". (I think i have that right...)

A lot of the time, if you leave the extension off (i.e the ".java"), the editor will kindly put something on there like ".doc" or some such if you don't hve that type set right. Heck, even if you DO have the .java on there and have it set to save it as some other type, it will put the .doc on the end, giving you "MooseGreetings.java.doc"
 
Daniel Mikkelsen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fred rosenberger wrote:
Daniel Mikkelsen wrote:I don't understand: you want me to save them as .txt?

you need to save it as a .java file. but you need to save is as plain text - not rich text. Most editors, when you go to save a file, have two things - one where you type in the name you want to save it as, and another that lets you say what TYPE of file it is. in Notepad, one option for "save as type" is "Text Documents (*.txt)", but if in the "File name" you type "MooseGreetings.java", it will save it as "MooseGreetings.java". (I think i have that right...)


Oh, alright. But, when you use windows notepad, despite that you put .java in the end, e.g. MooseGreetings.java, it will still save it as MooseGreetings.java.txt

However, now that I've tried notepad++, when I save it as .txt in file type but add .java to the file name, it will not do as windows notepad with the forced .txt at the end. Insted, it will just be MooseGreetings.java. Just as I want (also got the compiler to function now )
 
Daniel Mikkelsen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:We just happen to have an Editor FAQ that you might find useful. Most of them are free.


Sorry, missed that post. Thought it was an ad for some reason That FAQ is very helpful
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows has an absolutely awful 'feature' where it hides the extensions from files if they have well-known extensions. This means SomeFile.java.txt will be displayed as SomeFile.java.

Apart from being a bit of a security vulnerability, it confuses you if you aren't paying close attention.

You can turn it off so it always shows you the correct extension. I can't remember off the top of my head exactly where the option is, but a Google search will find it.
 
Tony Docherty
Bartender
Posts: 3271
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike. J. Thompson wrote:Windows has an absolutely awful 'feature' where it hides the extensions from files if they have well-known extensions.

Agreed, the first thing I do on a new machine is turn this off.

Mike. J. Thompson wrote:
You can turn it off so it always shows you the correct extension. I can't remember off the top of my head exactly where the option is, but a Google search will find it.

In Win 7 (Not sure about Win 8 but it may be similar) goto Control Panel.
Select View by 'Small Icons' and select 'Folder Options'.
Click the 'View' tab and uncheck 'Hide extensions for known file types'
Click 'OK'
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Another suggestion: when you get to the command line issue the following commands (you can give the folder any name you like):-
mkdir java
cd java
Don's put your work in the Java installation folder.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!