• Post Reply Bookmark Topic Watch Topic
  • New Topic

Beginner Code .java, Compilation, and Run  RSS feed

 
George Steven
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys, I'm new here and new to coding.
I just started reading "Head First Java" book, and I wanted to tryout the first piece of code -Party.java

I use notepad and I have JDK and JRE installed. I saved the code written in Notepad with .java and encoding is ANSI.
So, I don't know how to compile it with javac and also run it. I tried open with javac.exe and there was a cmd prompt window in a flash and disappeared again.
I don't know what i'm doing. I need help here. The book didn't show instructions for compiling and running.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George,
Welcome to CodeRanch.

Open DOS on your computer. (Type cmd at the "run" prompt in windows if you don't know how). Then cd to the directory containing your java file. Then type

javac NameOfFile.java

Then to run it type

java NameOfFile
 
ab singh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you have set java environment variable in system else follow this link >>Environment Set
open up command prompt, move to directory which contain .java file using cd in windows.
you need to compile first so, write following instruction to compile

javac filename.java

after successful completion of compilation run program, use instruction written below to run program.

java filename

for more information follow these links below
Environment set UP
Environment set up

Compiling and running file
Compile and run


Hope it will help you. if there is any problem let me know
 
George Steven
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ab singh wrote:Removed as there is no need to read the whole post twice.


It was helpful, but I got an error message while trying to compile.
2015-09-05-03_19_43-Reply-to-Beginner-Code-.java-Compilation-and-Run-UC-Browser.png
[Thumbnail for 2015-09-05-03_19_43-Reply-to-Beginner-Code-.java-Compilation-and-Run-UC-Browser.png]
 
George Steven
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When compiling this
I get file not found. Can you please do some explaining?
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
George Steven wrote:When compiling this
I get file not found. Can you please do some explaining?

First off it should be public class Party. And this should be in a file named Party.java (case sensitive). Then if the compiler can't find it I would guess that you're not in the same directory as the file when you start up the compiler.
 
ab singh
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was helpful, but I got an error message while trying to compile.
there is semicolon missin at the last of your programe in the statement

just add semicolon (;) at the end of the print statement
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Beware of the Party class. Because it has no main method you cannot run that piece of code.

I am afraid the instructions given in the tutorial link are incorrect. you should add the new PATH to the beginning of your system PATH, not at the end. Don't use any of the programs they suggest. Use a text editor as suggested in our FAQ. Notepad is a text editor but it lacks features you need and has some bad habits which make it unsuitable for programming. I prefer Notepad++ is I ever use Windows.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!