Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Newbie question on javac

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.

I recently bought the Headfirst Java and it recommended this forum for questions regarding java.

Question: Is it correct to use the windows command prompt to access javac?

i'm not sure if what im doing with the command line is correct (or if thats the right tool i should be using). the picture of the command prompt in the book doesnt look similar to the command prompt i'm using. the one in the book has "File", "Edit", "Window", "Help" and uses the "%" sign. the command prompt im using is just a simple black screen, no buttons on the top just "C:\Users>" and doesnt recognize "%".

im more familiar with an ide but the book said that i shouldn't use one just yet.

Problem: when i, idk whats the term, run javac using the command prompt to compile a source file, it says it cannot find the file.

this is what i type: javac MyFirstApp.java. then it returns something like "file not found: MyFirstApp.java". Should i put the source file in a certain folder? It's currently on the desktop and not in any particular folder.
 
lowercase baba
Posts: 12768
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the cmd.exe is the correct place. I think the book tends to use the Mac/Apple OS for pictures, so don't let that worry you.

The file can be anywhere...but you have to tell the java compiler where it really is. By default, it looks in the 'current' directory - i.e. wherever your cmd window says it is. Generally, you would make something like a C:\java\projects directory, and put the .java file there.

I have a C:\slop directory I use. Then, I cd into it, and then just type "javac MyClass.java". If i was somewhere else, I could type "javac c:\slop\MyClass.java"
 
Marshal
Posts: 65842
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

This is what I suggest about running the command prompt. I think, apart from the file name, it is the same as Fred suggested earlier.
 
Jose Kampilan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@fred: thanks man. what you said worked. also, i was encountering the "file not found" error because i was only putting the location of the folder. didnt know i was supposed to also include the file.

@campbell: this looks like a place friendly to newbies like me.
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!