Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling and running?

 
Faraz Bukhari
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
screenshot.png
A screenshot of my simple java source code.
[Thumbnail for screenshot.png]
 
Henry Wong
author
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Have you downloaded and installed a JDK?

 
Faraz Bukhari
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20889
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20750
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic