Someone please help me with java!

This topic is locked from further discussion.

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#1 xfactor19990
Member since 2004 • 10917 Posts

Ok, so im supposed to type the infamous Hello World

here is my code

class myfirstjavaprog
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}

so i installed Java jdk 1.0.6_16, after installing i went to my variable settings and added jdk1.0.6_16bin to paths well now i wrote the code saved as all files format on desktop, went to javac on cmd typed javac Helloworld.java

and it says its not recognized? Any ideas?

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#2 xfactor19990
Member since 2004 • 10917 Posts
bump
Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#3 Spirolli
Member since 2005 • 100 Posts

Ok, so im supposed to type the infamous Hello World

here is my code

class myfirstjavaprog
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}

so i installed Java jdk 1.0.6_16, after installing i went to my variable settings and added jdk1.0.6_16bin to paths well now i wrote the code saved as all files format on desktop, went to javac on cmd typed javac Helloworld.java

and it says its not recognized? Any ideas?

xfactor19990

It is convention to write the filename after the public cla$$ (sorry for some reason I can't write the word becuase it messes with Gamespot javascript codes but you know what I mean) the same name you are giving the file. So change it to HelloWorld or you could change the original filename to myfirstjavaprog.

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#4 xfactor19990
Member since 2004 • 10917 Posts
just says javac is not recongnized as a command
Avatar image for Saturos3091
Saturos3091

14937

Forum Posts

0

Wiki Points

0

Followers

Reviews: 1

User Lists: 0

#5 Saturos3091
Member since 2005 • 14937 Posts

I learned Java last year. What compiler are you using? I used Blue J (terrible compiler btw), and in that all I had to do was run the main method and it would work fine. I don't see any errors with your syntax, so it's probably due to the compiler or your class names.

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#6 xfactor19990
Member since 2004 • 10917 Posts
my teacher is making me go through the cmd, so im putting cd desktop Javac Helloworld.java and its unrecognized
Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#7 Spirolli
Member since 2005 • 100 Posts

This is most likely a probably a problem with the compiler pathname. You need to set the path for the compiler to compile the program. Number 4 of this webpage should help you out. http://java.sun.com/javase/6/webnotes/install/jdk/install-windows.html#Environment

Avatar image for Saturos3091
Saturos3091

14937

Forum Posts

0

Wiki Points

0

Followers

Reviews: 1

User Lists: 0

#8 Saturos3091
Member since 2005 • 14937 Posts
[QUOTE="xfactor19990"]my teacher is making me go through the cmd, so im putting cd desktop Javac Helloworld.java and its unrecognized

And you changed the filename to HelloWorld then? In that case I am not sure what the problem is. I've never done anything (coding-related) with command prompt to be honest. Well, you said "Javac" isn't recognized, so I suggest you search (with that problem in mind) on the internet for a more knowledgeable person.
Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#9 xfactor19990
Member since 2004 • 10917 Posts
ya i have been messing with that for hours lol its making me mad :) haha i have it to jdk1.6.0_16\bin
Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#10 xfactor19990
Member since 2004 • 10917 Posts
wow ummm ya this is so dumb i have spent 10 hours writing friggin program -_-
Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#11 Spirolli
Member since 2005 • 100 Posts

my teacher is making me go through the cmd, so im putting cd desktop Javac Helloworld.java and its unrecognizedxfactor19990

I can possibly still help you but first just want to ask a few questions.

1. Why are you changing to the desktop and then compiling.

2. By 'go through the cmd', what do you exactly mean?

Also provide what your command line prompt looks like and show each command line (the entire thing)you do.

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#12 xfactor19990
Member since 2004 • 10917 Posts
sent you a PM :)
Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#13 xfactor19990
Member since 2004 • 10917 Posts
anyways here i go Helloworld.java is on my desktop so my teacher told me i had to switch to desktop, secondly here we go i mean i go to start run CMD then once im in there i go cd desktop dir (shows my stupid java file) then javac Helloworld.java (errors)
Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#14 Spirolli
Member since 2005 • 100 Posts

anyways here i go Helloworld.java is on my desktop so my teacher told me i had to switch to desktop, secondly here we go i mean i go to start run CMD then once im in there i go cd desktop dir (shows my stupid java file) then javac Helloworld.java (errors)xfactor19990
Where is your java stuff located (Jdk stuff)? Check if the filepaths match.

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#15 xfactor19990
Member since 2004 • 10917 Posts
C:\Program Files\Java\jdk1.6.0_16\bin
Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#16 Spirolli
Member since 2005 • 100 Posts

C:\Program Files\Java\jdk1.6.0_16\binxfactor19990
I believe all javafiles must be located inside the java folder. Place it within your bin folder in any kind of folder. Then try to compile from the command line again. Make sure to input entire pathname correctly(C:>\Program Files\Java\jdk1.6.0_\bin\javac MyClass.java) just to be safe.

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#17 xfactor19990
Member since 2004 • 10917 Posts
nope same thing
Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#18 xfactor19990
Member since 2004 • 10917 Posts
ok i got an idea-im screwed
Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#19 Spirolli
Member since 2005 • 100 Posts

Just to clarify You put your helloWorld.java program into your bin folder and ran C:> \Program Files\Java\jdk1.6.0_16\bin\javac HelloWorld.java and gave you back the response: 'javac' is not recognized as an internal or external command. Also make sure your in the right directory. It starts out in Documents and Settings and you need to be in Program Files.

Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#20 Spirolli
Member since 2005 • 100 Posts

Well, if you have already left the forum then I'll leave with some helpful tips (plus where I live its really late and I'm tired).

There is a tutorial provided by Sun (the makers of Java) for writing the Hello World which uses the command prompt your using:

http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html Go through it and follow it closely.

For other tips I can give.

1. Make sure that the java file is inside the bin folder of the Program_FilesJavajdk.... bin. If the file is not inside the java folders then the compiler can't read it.

2. Make sure when typing pathnames to make that the filepath is typed correctly.

3. Also I don't know if you changed your filename to match the public cla$$ name. Make sure to do that eventually.

Ask your teacher about the problem if none of these suggestions help you out.

Sorry I wasn't much help.

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#21 xfactor19990
Member since 2004 • 10917 Posts

ok update, so i just tried same steps as to what i was doing on XP and it worked, is there something wrong on vista? imean it flat out denies any codes like if you go to cmd and type javac it just says unrecognized

Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#22 Spirolli
Member since 2005 • 100 Posts

ok update, so i just tried same steps as to what i was doing on XP and it worked, is there something wrong on vista? imean it flat out denies any codes like if you go to cmd and type javac it just says unrecognized

xfactor19990
One reason it might have had a problem was the way Vista sets up conventions between directories and their subdirectories (it's a common problem on the Vista according to http://java.sun.com/javase/6/webnotes/) but this is just a guess.
Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#23 xfactor19990
Member since 2004 • 10917 Posts
hmmm ya i was thinking maybe the compiler was corrupt lol not sure, either way got it running on XP
Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#24 xfactor19990
Member since 2004 • 10917 Posts
hahaha i text my teacher and she keeps saying its javac
Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#25 xfactor19990
Member since 2004 • 10917 Posts
how do i add ""?
Avatar image for MOSSBERG_E-Rock
MOSSBERG_E-Rock

3049

Forum Posts

0

Wiki Points

0

Followers

Reviews: 1

User Lists: 0

#26 MOSSBERG_E-Rock
Member since 2004 • 3049 Posts

wow man this much trouble with this?

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#27 xfactor19990
Member since 2004 • 10917 Posts
ya, dude no matter what vista will not run it, and i have tried everythig on the guides, no its just going crazy
Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#28 Spirolli
Member since 2005 • 100 Posts

ya, dude no matter what vista will not run it, and i have tried everythig on the guides, no its just going crazyxfactor19990
It appears that I had it wrong in my previous posts. In Windows and Vista, there are two different environment variables: PATH and CLASSPATH. Also you need to set the PATH environment variable. The PATH environment variable is meant to find batch files and .exe files, like the javac.exe (which is the compiler executable). The CLASSPATH is the path that the compiler takes to find the .class files to run them. I personally don't use xp or vista with java so I didn't realize what might have been the problem.

There is a guide here for Vista OS users: http://ryan.ifupdown.com/2008/12/04/environment-variables-in-windows-xpvista/. Use it for the time being for your Vista OS. It's probably fine to just do leave at this for now but for larger projects in Java, that include a lot of files, make sure to ask your teacher how to setup the environment variables correctly.

Avatar image for xfactor19990
xfactor19990

10917

Forum Posts

0

Wiki Points

0

Followers

Reviews: 3

User Lists: 0

#29 xfactor19990
Member since 2004 • 10917 Posts
well ya but my computer is not showing class path
Avatar image for Spirolli
Spirolli

100

Forum Posts

0

Wiki Points

0

Followers

Reviews: 19

User Lists: 0

#30 Spirolli
Member since 2005 • 100 Posts

well ya but my computer is not showing class pathxfactor19990
You only need to change the PATH environment variable to include your java command files. You don't need to change the Classpath variable.

Try to run it again with Vista and type the classpath as well as the javac command: C:\Program Files\Java\..(Make sure to put the correct classpath I'm just guessing what it might be)...\bin\javac HelloWorld.java. If it doesn't work then you could try copying how your XP OS (don't change any of environment variables) has its environment variables set up and modify them likewise in Vista (taking into account differences in where you place your Java stuff).

If those methods don't work then I would suggest doing all of your programming through XP for the time being. You could ask your teacher if he/she can help you out with setting it up in Vista or you could post on sun's forums and I'm sure one of the people there could help you. I'm unsure of how to help you any more since I mostly use a Solaris Unix shell for my java stuff. Sorry.