• Post Reply Bookmark Topic Watch Topic
  • New Topic

help java head first java 2nd edition  RSS feed

 
m meee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I always wanted to learn java language, I have some background of html, c+ and computers in general. It has been frustrated this couple days because I cannot pass page 3 from the book. I have download jdk 8, I download api, I even download beans but then uninstalled.
I try to get a simple code such as helloworld.java but I cannot get it to run it. I do not have any idea where is the compiler is, I do not know where the java virtual machine is stored in my mac. how can I run my code? how can I test it!!!

I believe I have done everything, I have been searching for help and tips but I am stuck, I think I did everything I had to do and this is my last source, asking for help.
here is my version of java

java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

(somehow I end up with two version of java)

I have created a folder called java under my library and I stored the api in that folder.

what else I have to do??? help please

I even go to my terminal and did the example from coderach but still not working!!! help please!!!


-MacBook-Pro:~ m$ ls Desktop
MooseGreetings.java
MooseGreetings.class uncc
-MacBook-Pro:~ m$ javac MooseGreetings.java
javac: file not found: MooseGreetings.java
Usage: javac <options> <source files>
use -help for a list of possible options
-MacBook-Pro:~ m$ javac MooseGreetings.class
javac: invalid flag: MooseGreetings.class
Usage: javac <options> <source files>
use -help for a list of possible options


 
Mohammed Sardar.
Ranch Hand
Posts: 193
1
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good. You first MooseGreetings.class has been successfully created by the javac compiler. Now you are able to run Java files from your commands I'm saying. I don't know Mac. But the commands you have used are good.

Finally did you try java Moose greetings
This you have to run to see the final output. Try that command.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
m meee wrote:
-MacBook-Pro:~ m$ javac MooseGreetings.java
javac: file not found: MooseGreetings.java
Usage: javac <options> <source files>
use -help for a list of possible options


You are trying to compile the MooseGreetings.java program that is in the current directory... but the compile can't seem to find that java file.

m meee wrote:
-MacBook-Pro:~ m$ javac MooseGreetings.class
javac: invalid flag: MooseGreetings.class
Usage: javac <options> <source files>
use -help for a list of possible options


You are trying to compile the MooseGreetings.class file... but the compiler is *not* for compiling class files. It generates class files. And it also loads, and uses class files as part of the compilation.

Henry
 
m meee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you guys!
your advices have help me and now i got it
m-MacBook-Pro:Desktop m$ java MooseGreetings
mooooooooooo

now back to the Head First Java book,  my question is, where is the java virtual machine at???
i download the sdk file and api folder but I do not see the java virtual machine to run my code, what am I doing wrong??
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

You may have two versions of Java® installed on your computer (or even more) but that is not usually a problem. The OS goes through your PATH variable and uses the first program it finds whose name matches what the instruction is, in this case the first program called “java”. found. Then it stops looking. You shou‍ld therefore put the PATH to your most recent installation first in the PATH variable. That is more of a problem with Unix/Linux boxes than Windows® because they usually have Java® preinstalled, which Windows® doesn't. You can get problems if your javac tool is a more recent version than the java tool. Macs may have the whole JDK installed, but I am not sure.
Windows® users probably shou‍ld uninstall Java® before installing the next upgrade.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!