Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Troubleshooting Guide For Some Basic Java Problems Troubleshooting Guide For Some Basic Jav

Recommended Posts

Troubleshooting Guide For Some Basic Java Problems. Step OneThe first and fore most requirement is the installation of the required(or most current j2sdk) 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 formatC:\j2sdkxxxxxwhere xxxxx will be the version number for the current j2sdk you installed. At this point on my machine it looks like thisC:\j2sdk1.4.1_05Step TwoNext step is setting up the path and class paths for your system so that windows knows what to do with commands likejavac 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>Runin the text field type in cmdif you are one of those who are still on win98/95 or win me then you will need to type in commandThis will bring up a dos window. in the dos window at the prompt type in the followingjavacAt this point we are expecting the following or a message like this 'javac' is not recognized as an internal or external commandoperable program or batch file.This is due to the reason that windows machine does not know as yet that what to do with "javac" command which essentiallyis 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.Step ThreeLets go and set the environment variable.On machines with win2k or alter systems go toStart>Settings>Control Panel>Locate and click on the "System" 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.Environment VariablesThis 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 lowersection 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,New, Edit and Delete.we want to create home variable for java.Click on New button.It will bring up a small window with 2 text fieldsVariable name: _______________________in variable name text field type the followingJAVA_HOMEVariable 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 thisC:\j2sdk1.4.1_05If you look in the window you will see the following record added which you have just addedVariable ValueJAVA_HOME C:\j2sdk1.4.1_05of course there may be others too.We are half way thru..:-)Step FourNow 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 Pathif 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,New, Edit and Delete.we want to create home variable for java.Click on New button.It will bring up a small window with 2 text fieldsVariable name: _______________________in variable name text field type the followingPATHVariable 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 isresolved to its actual path on the disk, again on my machine it looks like below.Variable ValuePATH C:\j2sdk1.4.1_05\bin;C:\j2sdk1.4.1_05\lib;Click "Ok" at the bottom of window, and then click on again.Now lets repeat Step Two here again.This time around(provided everything was done exactly as I mentioned above) when you type in javac at the command prompt you should get the following messageC:\Documents and Settings\Khalid.Ali>javacUsage: 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 optionsif we see the above message,we are all set for some serious java coding..:-).Compilation and Running of Java CodeOpen note pad, and copy and paste the following code in itcode:-------------------------------------------------------------------------------- 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); } } --------------------------------------------------------------------------------There are couple of little precautions you will need to take.Make sure that file name is HelloWorld.java, calls 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:\development\java>javac HelloWorld.javaC:\development\java>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 havethis file,now there is another file with the same name but different extension.HelloWorld.classjava 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:\development\java>java HelloWorldHello Java World! Here I come.C:\development\java>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:\development\java>java HellowWorldException in thread "main" java.lang.NoClassDefFoundError: HellowWorldas 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 iscorrected it will run.If you have class name that's different then the file name then you will get the following message.C:\development\java>javac HelloWorld.javaHelloWorld.java:1: class HellowWorld is public, should be declared in a file named HellowWorld.javapublic class HellowWorld{^1 errorC:\development\java>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 nameHelloWorld.java....I hope this helps, I'd probably add more stuff as it comes to mind...

Share this post


Link to post
Share on other sites

Phew.. i think you're not only made a post, but you just made an article about Java Installation Procedure... haha... I just want to add, if you're want to really master Jaa Programming Language, don't read book only, leave it and try my method: find java decompiler, this program should convert *.class to *.java, then, you should learn from advance program, how the advance programmer combine their funtion and use or create an expert header and ariety of instance...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.