aspose file tools*
The moose likes Beginning Java and the fly likes Compiling and running? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compiling and running?" Watch "Compiling and running?" New topic
Author

Compiling and running?

Faraz Bukhari
Greenhorn

Joined: Jul 27, 2013
Posts: 4
So I am learning Java and and I know basic procedural coding. I am getting to object-oriented. I am using this book called Head First Java. I just made a practice program but the thing is I do not know how to compile and run it. I only have one class and the class' name is Application so I named the file Application.java
I am using this text-editor called Notepad++.
How do I compile and run Java source code files.



[Thumbnail for screenshot.png]

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40


Have you downloaded and installed a JDK?


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Faraz Bukhari
Greenhorn

Joined: Jul 27, 2013
Posts: 4
I really feel like I have because I started doing it with these other online tutorials and now I am using Head First Java so I think I have a JDK. How do I check?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

Faraz Bukhari wrote:I really feel like I have because I started doing it with these other online tutorials and now I am using Head First Java so I think I have a JDK. How do I check?


Don't know what you mean by "feel like" you have. Either you did, or you didn't... software doesn't get accidentally download and installed (well, those that isn't malware that is).

The java compiler (which is used to compile java programs) is named "javac" and the JVM (which is used to run java programs) is named "java". What happens when you type either of these on the command line?

Henry
Faraz Bukhari
Greenhorn

Joined: Jul 27, 2013
Posts: 4
When I type in javac it is not recognized as an internal or external command. When I type in Java it comes up with a list of commands or something.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18990
    
  40

The beginning of this FAQ ...

https://www.coderanch.com/how-to/java/how-to-create-java-program

explains how / where to download, and how to intstall the JDK.

Henry
Faraz Bukhari
Greenhorn

Joined: Jul 27, 2013
Posts: 4
ok I officially have the latest JDK and the latest JRE but when I type in "javac" on cmd it just says that it is not recognized as an internal or external file.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18903
    
    8

Yes. And the link which Henry posted does explain how to deal with that. In the section headed "Setting the JAVA_HOME and PATH environment variables".

This all may seem rather obscure and picky. Which it is, really. But back when Java was first invented it was mainly used by people who were already programmers and who were familiar with folders and paths and other low-level operating system stuff, so they wouldn't have had any trouble with it. Nowadays Java is being installed by people who haven't had that kind of experience, though, and it's a lot more of a headache.
Manu Somasekhar
Ranch Hand

Joined: May 22, 2012
Posts: 44
Hi Faraz,
Once you successfully set JAVA_HOME environment variable [Tutorial] using cmd tool of windows, go to the directory where your java files are located. type "javac Application.java" to compile your java code. It will produce a "class" file within the same directory named as "Application.class". Now you can run your java program using the command "java Application". Hope it helps
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Compiling and running?