• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Beginner Code .java, Compilation, and Run

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When compiling this
I get file not found. Can you please do some explaining?
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic