/    Sign up×
Community /Pin to ProfileBookmark

Troubleshooting Guide For Some Basic Java Problems.

[b]
Troubleshooting Guide For Some Basic Java Problems.
[/b]

[b]
Step One
[/b]

The first and fore most requirement is the installation of the required(or most current j2sdk, the newer versions of jdk are known as J2SE) from java.sun.com.
if you have done that then you will have a new folder created in the C: drive.
Typically it will be something along the following format
C:j2sdkxxxxx (I think jdk 5 is installed in C:Program Files folders?)
where xxxxx will be the version number for the current j2sdk you installed. At this point on my machine it looks like this
C:j2sdk1.4.1_05

[b]
Step Two
[/b]

Next step is setting up the path and class paths for your system so that windows knows what to do with commands like
javac or java.
Lets see what happens if we want to test our setup as it is right now.
on your windows machine go to
bottom left corner and click on
Start>Run
in the text field type in
cmd
if you are one of those who are still on win98/95 or win me then you will need to type in
command

This will bring up a dos window. in the dos window at the prompt type in the following
javac

At this point we are expecting the following or a message like this
[i]
‘javac’ is not recognized as an internal or external command
operable program or batch file.
[/i]

This is due to the reason that windows machine does not know as yet that what to do with “javac” command which essentially
is required to compile java src code.Close the does window,because windows will not apply new variable changes in this session,
you will have to open up a new window once you are all set with variable settings.

[b]
Step Three
[/b]

Lets go and set the environment variable.On machines with win2k or newer systems go to
Start>Settings>Control Panel>
Locate and click on the [b]“System”[/b] icon.
This will bring up “System Properties” window.
by default “General” is selected, locate and click on “Advanced” tab.
Locate and click on the button that has the following caption on it.
[b]
Environment Variables
[/b]

This will bring up the a window with 2 sections in it, top one is for the user as whom you have logged in,and the lower
section is for system.
We will work in the user variables section.

You will see 3 buttons right below the display window in the “user variables” section,
[b]
New, Edit and Delete.
[/b]

we want to create home variable for java.Click on [b]New[/b] button.
It will bring up a small window with 2 text fields
Variable name: _______________________
in variable name text field type the following
JAVA_HOME

Variable value:______________________
in the variable value field type the folder name + path where on C drive you have j2sdk installed.
in my machine this value looks like this
C:j2sdk1.4.1_05
If you look in the window you will see the following record added which you have just added
[b]
Variable Value
[/b]

JAVA_HOME C:j2sdk1.4.1_05

of course there may be others too.We are half way thru..:-)

[b]
Step Four
[/b]

Now lets set the path to required java bin files to run several java commands.
Look in the window for the user variables and try to locate a Variable name [b]Path[/b]
if you see one then we need to edit and add new values,if you don’t see one then we need to create one.
And then add values.
First lets create one.

You will see 3 buttons right below the display window in the “user variables” section,
[b]
New, Edit and Delete.
[/b]

we want to create home variable for java.Click on [b]New[/b] button.
It will bring up a small window with 2 text fields
Variable name: _______________________
in variable name text field type the following
PATH

Variable value:______________________
in the variable value field type the folder name + path where on C drive you have j2sdk installed.
in my machine this value looks like this
%PATH%;%JAVA_HOME%bin;%JAVA_HOME%lib;
If you look in the window you will see the following record added which you have just added.You will see that JAVA_HOME is
resolved to its actual path on the disk, again on my machine it looks like below.
[b]
Variable Value
[/b]

PATH C:j2sdk1.4.1_05bin;C:j2sdk1.4.1_05lib;

Click [b]“Ok”[/b] at the bottom of window, and then click on again.
Now lets repeat [b]Step Two[/b] here again.
This time around(provided everything was done exactly as I mentioned above) when you type in [b]javac[/b] at the command
prompt you should get the following message

C:Documents and SettingsKhalid.Ali>javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is doing
-deprecation Output source locations where deprecated APIs are used
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class files
-encoding <encoding> Specify character encoding used by source files
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
-help Print a synopsis of standard options

if we see the above message,we are all set for some serious java coding..:-).

[b]
Compilation and Running of Java Code
[/b]

Open note pad, and copy and paste the following code in it

[code]
public class HelloWorld{
public static void main(String[] args){
//declare and define a variable of type String
String helloWorld = “Hello Java World! Here I come.”;

//Now print it out on screen
System.out.println(helloWorld);
}
}
[/code]

There are couple of little precautions you will need to take.Make sure that file name is HelloWorld.java, class name must always
match the file name.If everything is fine and dandy, nothing will happen and you will be brought back to the dos prompt.

C:developmentjava>javac HelloWorld.java

C:developmentjava>

In this case now is the time to run the newly written java application.if you want to make sure,just look in the directory where you have
this file,now there is another file with the same name but different extension.
HelloWorld.class

java src files always have *.java extension and compiled classes have *.class extension.
Anyways, let run this app, type in the following at the dos prompt.

C:developmentjava>java HelloWorld
Hello Java World! Here I come.

C:developmentjava>

The java runtime engine will print the value of the variable then come to dos prompt for a new command.
At this point typically a beginner may see the following error.

C:developmentjava>java HellowWorld
Exception in thread “main” java.lang.NoClassDefFoundError: HellowWorld

as you can see it makes total sense that its not finding the class name, because HelloWorld has a “w” in it,once the class name is
corrected it will run.
If you have class name that’s different then the file name then you will get the following message.

C:developmentjava>javac HelloWorld.java
HelloWorld.java:1: class HellowWorld is public, should be declared in a file named HellowWorld.java
public class HellowWorld{
^
1 error

C:developmentjava>
Obvious enough…I’ll just go take a look at my class name and remove the w from so that its the same as the file name
HelloWorld.java….

I hope this helps, I’d probably add more stuff as it comes to mind…
[b]Edit:[/b]Sep 06, 2005
[b] MySQL’ centric jdk settings[/b]

[code]
Following are the settings for MySQL to work on my windows 2000
work station. Make sure you have same settings on your machines
for MySQL to work.

JDK installed at the following address
C:j2sdk1.4.2

Environment variable for java home set as follows
JAVA_HOME=C:j2sdk1.4.2

Paths set to point to java home as follows
Path=C:j2sdk1.4.2bin;C:j2sdk1.4.2lib;

Mysql driver is placed at the following location
C:Program FilesJavaj2re1.4.2libmysql-connector-java-3.1.0-alpha-bin.jar

I have attached a zip file that contains a DbTest.java class to test the
connection.
[/code]

[b][url=http://www.webdeveloper.com/forum/showpost.php?p=529986&postcount=4]Deploying a Servlet on Tomcat[/url][/b]

The tutorial above is mostly the works for any servlet on any server, only difference there will be that the root folders names could be different in different server environments.
Sometimes people face problems in their JSP pages that their user created objects/classes throw an error that [b]cannot resolve symbol[/b]. This error is almost always caused by the fact that there is a problem in the setup and the classes are not at right place for the jsp page to find them. [url=http://www.webdeveloper.com/forum/showpost.php?p=529986&postcount=4]Deploying a Servlet on Tomcat[/url]–> this tutorial will actually guide you through the process of setting up a correct context for any new webapplication as well as where required files should be at.

[upl-file uuid=58f02e82-c47d-4bb6-a065-8a7fc5319893 size=2kB]dbtest.zip[/upl-file]

to post a comment
Java

30 Comments(s)

Copy linkTweet thisAlerts:
@JonaSep 13.2004 — [font=trebuchet ms]Thanks Khalid, this is great. One question, though, if I installed the complete kit downloadable at <http://java.sun.com/j2ee/1.4/download.html#sdk>, and installed it in C:java, what would I use for my JAVA_HOME and PATH global variables? I tried using C:java instead of C:jdkxxxx, but it didn't work...

Thanks! ? [/font]
Copy linkTweet thisAlerts:
@JonaSep 14.2004 — [font=trebuchet ms]Never mind, I found it in: C:javajdkbin. Thanks.[/font]
Copy linkTweet thisAlerts:
@Khalid_AliauthorSep 14.2004 — [i]Originally posted by Jona [/i]

[B][font=trebuchet ms]Never mind, I found it in: C:javajdkbin. Thanks.[/font] [/B][/QUOTE]


Glad that it helps, I remember quite a few years ago when I started learning java, the biggest darn problem I had was to set up the env variables on my windows 95 box....anyways...looking forward to answer some questions....
Copy linkTweet thisAlerts:
@ladynredd4uFeb 13.2005 — Ohhh my...had I only had this a week ago.

I hope other newbies read this first...it will save them many hours of frustration.
Copy linkTweet thisAlerts:
@EntertainerFeb 24.2005 — There's a handy program that i use now, it does all that stuff in here automatically. It does take quite much memory but that's not too bad.

For windows only:

[URL=http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.0.1-200409161125/eclipse-SDK-3.0.1-win32.zip]Eclipse[/URL]

Hope it helps ?

Grtz,

Entertainer
Copy linkTweet thisAlerts:
@drythirstMar 15.2005 —  There are couple of little precautions you will need to take.Make sure that file name is HelloWorld.java, [b][u][i]calls[/i][/u][/b] name must always

match the file name.[/QUOTE]

[COLOR=red]Oops! Typo![/COLOR]

Fix:
There are couple of little precautions you will need to take.Make sure that file name is HelloWorld.java, [b][u][i]class[/i][/u][/b] name must always

match the file name.[/QUOTE]
Copy linkTweet thisAlerts:
@slarkinApr 26.2005 — FWIW: I just solved one little problem that prevented me from running a java app that compiled without error and contained no logic errors as it displayed simple text.

On a Windows XP computer, I have Oracle tools installed for managing a couple of remote instances. Its installation had added JRE version 1.3.1 that comes with Oracle Admin tools. The JDK I downloaded and installed is a more recent version, C:Program FilesJavaj2re1.4.2_08. The compiled class could not be run with the older JRE.

When I checked [CODE]c:appsjava -version[/CODE] against [CODE]c:appsjavac -version[/CODE] , I got two different versions -- of course!

Simple solution: changed the PATH env variable from c:Program FilesOraclejre...bin to c:[[I]folder of new JRE[/I]]bin

General Rule: if you're getting version errors after an app compiles correctly, check your PATH for other JREs.

HTH someone else.

Cheers.

S.Larkin
Copy linkTweet thisAlerts:
@theuedimasterSep 03.2005 — Wow this helped so much! Thanks Khalid Ali! Seriously, this is like the only place on the web to fix the class path problem!
Copy linkTweet thisAlerts:
@RbronsonSep 11.2005 — I typed the following for Name and Value

Java_Home Java_Home C:J2sdk-1_3_1_16

PATH C:J2sdk-1_3_1_16bin;C:J2sdk-1_3_1_16lib;

This is not working.

And I have windows xp
Copy linkTweet thisAlerts:
@BadArtistDec 12.2005 — Yah i typed the following: C:jdk1.5.0_06/bin;C:jdk1.5.0_06lib;

and it's not working for me as well it still comes up with the: 'javac' is not recognized as an internal or external command

operable program or batch file.

It's not workin for me too and i also have xp. Did i type somethin wrong or what?
Copy linkTweet thisAlerts:
@BadArtistDec 23.2005 — Ok I have been working on getting it running for a while now and it still won't work. What is up with my damn computer?
Copy linkTweet thisAlerts:
@mukarramJan 24.2006 — "What is up with my damn computer?"

Calm down dude, the path u r entering doesnt seem fine to me. is this a typo or u r actually entering a wrong path?

replace the line C:jdk1.5.0_06/bin;C:jdk1.5.0_06lib; with

C:jdk1.5.0_06bin;C:jdk1.5.0_06lib;

hopefully it would help. chao.
Copy linkTweet thisAlerts:
@kusumJan 31.2006 — hey khalid

thanks for you guide on how to install java and get it to work...but unfortunately, i still cant get mine to run.

i have got installed jdk1.3.1_16 in my c drive and also sun/Appserver which is J2EE

i am not sure which one to work with or why have many versions.

please advice!!

thanks
Copy linkTweet thisAlerts:
@slevenFeb 17.2006 — yes, I have do this and it works.

thanks your advice.
Copy linkTweet thisAlerts:
@jaqy_francoFeb 17.2006 — Thanks for this. My hard drive recently crashed, and I'm getting ready to reload everything on it. My problem was that I had obtained the laptop from a technical school after learning java programming, so it was already set up for me. I go to java.sun.com, and sometimes the instructions seem too daunting. It's nice to have something like this from someone who's just done it.

Thanks again.
Copy linkTweet thisAlerts:
@Bchy_FairyMar 20.2006 — [COLOR=Purple][SIZE=3][FONT=Arial][B]Hi ! I'm new here ! ? Well, I have a JAVA project for next week. I have to make a Hangman game and there is an aspect called ORIGINALITY, in that part I would like to make an applet in which the hangman is drawn but I would like the hang man to be an image, not a simple circle with lines. How can I do that ????[/B][/FONT][/SIZE][/COLOR]
Copy linkTweet thisAlerts:
@UltimaterMar 21.2006 — Hi all.

In a nutshell, I haven't installed Java on my Windows PC and searching for a full-installation download from-over the web.

I am new to Java (although I have skimmed my Java book many times over the years and I haven't ever compiled a single "java" file before [I was planning on programming Java years ago and bought a book yet never really got around to it.] ) and I am looking to install Java for the first time on my computer so I can compile "java" files into "class" files. I could care less for graphical interfaces, all I am looking for is the simplest compiler available to install on my PC.

My old Java 1.2 book that I bought years ago tells me to download a program called the

[u]Java Development Kit[/u]. It then links me to http://java.sun.com/products/JDK/1.2/

where I am expected to find some sort of installation download.

As I go there, I notice the URL of the page changes in the address bar to:

http://java.sun.com/products/archive/j2se-eol.html

Which I believe is telling me that Java1.2 has reached it's "End of Life".

So where do I go to install the "new" [u]Java Development Kit[/u]?

Why is it so hard to install such a simple thing which I only intend to use for compiling and nothing else!?
Copy linkTweet thisAlerts:
@Khalid_AliauthorMar 21.2006 — you should have posted a new thread in the forums instead of using the sticky..:-)

anyways..download the latest Java SDK from java site, its called J2SE5..[url=http://java.sun.com/j2se/1.5.0/index.jsp]here is the link[/url].

By the way on the right side of the page there still is jdk 1.4 available in case u wante that...anyhow if you are starting afresh then 5 is the way to go (which is essentially jdk 1.5)
Copy linkTweet thisAlerts:
@UltimaterMar 21.2006 — Thanks Khalid Ali, the link helped-out a lot as-well-as did the information [color=blue]jdk 1.5[/color] by itself! I had to fiddle with the downloads for a while and after downloading three files bindedly I finally, on the third try, located the file I had to download. It seems all I had to do was download

[color=blue]JDK 5.0 Update 6[/color] from the page http://java.sun.com/j2se/1.5.0/download.jsp

(which I got to from your link and clicking the link labeled "Downloads" on the very top-right corner of the page -- which took me about an hour to locate on the page)

After installation I finally located the javac.exe file in the location [color=blue]C:Program FilesJavajdk1.5.0_06binjavac.exe[/color]

I then was able to compile my first "java" file into a "class" file and it executed beautifully as expected when I tested it.


Khalid Ali, sorry for not making a different thread, I thought it would fit-into the sticky because we are already dealing with installation. Someone should really make a sticky that sums-up how to install Java step-by-step and walks you through, it's a pain in the you-know-what.
Copy linkTweet thisAlerts:
@Khalid_AliauthorMar 21.2006 — lol.. I guess u did not read the thread from the start.It actually walks u through the complete installation process....anyways..weclome to Java
Copy linkTweet thisAlerts:
@Bchy_FairyMar 23.2006 — Can somebody help me in graphics and applets ??? I know how to make simple circles and lines on an applet, but I would like to do something like this hangman game : (to put the face and the body from a picture, not a simple circle and lines)

http://www.kidscom.com/games/hangman/hangman.html
Copy linkTweet thisAlerts:
@jaqy_francoMar 27.2006 — Hello again,

I will also need to reinstall Tomcat onto my new hard drive. Again, what I find on http://tomcat.apache.org/index.html confuses me. When I click on the link to download Tomcat 5.x, do I need to save all of the files listed: Core, Deployer, Embedded, Administration Web Application, JDK 1.4 Compatability Package?
Copy linkTweet thisAlerts:
@Khalid_AliauthorMar 27.2006 — First of all guys, please read. This thread is not to post ur questions, rather help to understand some basic problems. Now onto the question [b]jagy_franco[/b] asked, you will need 1 of the 2 files

Core:

* zip (pgp, md5)
* tar.gz (pgp, md5)
* Windows Executable (pgp, md5)


Where zip and windows executeable are for windows machines.

The difference between zip version and windows executeable is that

1. you will need to unzip the zip file using some zip/unzip tool(WinRar?)

2. Windows executable is easier in the sense that you just click on it to install and it will take care of every task for you(if I remember coorrectly, it only asks you for admin password, that u can set at install time)

3. [b]JDK 1.4 Compatability Package[/b] is needed only if you are running jdk 1.4.x on your system. if you have any of the jdk1.5 versions then you do not need that.

Hope this helps
Copy linkTweet thisAlerts:
@jaqy_francoMar 27.2006 — First of all guys, please read. This thread is not to post ur questions, rather help to understand some basic problems. [/QUOTE]

Hi again Khalid ? ,

Where shall I post questions then? I downloaded what I thought was the SDK, but I don't have a C:j2sdk.... folder. I have C:SunAppServer. I'll give more details in the proper thread if you let me know where that is (or shall I start a new one?)

Thanks for your help,

jaqy_franco.
Copy linkTweet thisAlerts:
@Khalid_AliauthorMar 28.2006 — just start a new thread please....
Copy linkTweet thisAlerts:
@drbeardedAug 11.2006 — i think im in the right thread ? ok im using a notepad++ as the editor and compiling through command line so when i try to compile helloworld


javac helloworld.java no errors

java helloworld.class

exception in thread "main" mess

i can compile but i cant run applications :mad:
Copy linkTweet thisAlerts:
@Khalid_AliauthorAug 12.2006 — this is wrong thread, please post it in a new thread. and post complete text of the exception(in the new thread that is)
Copy linkTweet thisAlerts:
@sirishaprasannaDec 27.2006 — Hello Khalid Ali,

I have installed java(jdk1.6.0) into C:ProgramFilesJava and set the environment vrbles as

JAVA_HOME C:ProgramFilesJavajdk1.6.0

PATH C:ProgramFilesJavajdk1.6.0bin;C:ProgramFilesJavajdk1.6.0lib;

at the dos promt when i type javac it says 'javac' is not recognized as an internal or external command.....

what's the problem,where did i go wrong

please help me........

thanks in advance
Copy linkTweet thisAlerts:
@sirishaprasannaDec 27.2006 — Hey Khalid Ali

I found it,it was a typo mistake

THANK YOU

I followed the steps given by you,thanks for starting this thread any way.
Copy linkTweet thisAlerts:
@chazzyDec 28.2006 — Khalid, why not just lock this thread?

(K) Good idea..:-)
×

Success!

Help @Khalid_Ali spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...