Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!

David Hernandez

+ Follow
since Jun 06, 2010
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by David Hernandez

I'm such a dork, I was reading the book very closely and noticed that just by typing "java MyFirstApp" without the quotes and without the .class, IT WORKS! It gave me the results. I guess that little thrills make me happy. I will also acknowledge that your explanation -Friedman- is better than mine.!!! Thanks

Ernest Friedman-Hill wrote:Tha "garbage" is the contents of that class file. I don't know precisely what you typed to see that, but the way to run a Java class file is to type "java" followed by the name of the class -- not the path to the class file, or the name of the class file. So cd into the directory "C:\Users\name\Documents\My JAVA SE" and type "java MyFirstClass".

Now go and read this article: HowToSetTheClasspath .

And finally, try running from some other directory using the -cp switch:

java -cp "C:\Users\name\Documents\My JAVA SE" MyFirstApp

Most of the time this last way of doing things is what you'll really use in the scripts that run your programs.

10 years ago
I have a Compaq Presario F700 w/Win7 loaded (No adobe, messenger, music, very clean), my environmental variables worked (because javac work). I saved "C:\Users\name\Documents\My JAVASE\" in notepad, I compiled it "C:\Users\name\Documents\My JAVA SE\javac" in DOS, I ran it "C:\Users\name\Documents\My JAVA SE\MyFirstApp.class " but what I get is the strangest results, basically garbage as follows:

-------Source Code---------
import java.util.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

public class MyFirstApp
public static void main (String[] Args)
System.out.println("I Rule!");
System.out.println("The World");
-------Source Code Ends-------

-------Garbage starts-MyFirstApp.class---------
Êþº¾ 1           <init> ()V Code LineNumberTable main ([Ljava/lang/String;)V
SourceFile      I Rule!  The World MyFirstApp java/lang/Object java/lang/System out Ljava/io/PrintStream; java/io/PrintStream println (Ljava/lang/String;)V !        *· ±    
1   ² ¶ ² ¶ ±         
-------Garbage ends--------------------------

I have not touch anything regarding printing, much less touching anything related to printing to a file. So, does anyone has an idea why this garbage gets triggered how can I see the true output? I will trully appreciate your suggestions.

10 years ago

David Newton wrote:That's because you're executing from within the directory where javac is located, not where the Java source code file is located...

Your are right, I tried as suggested and got "at least" something.

I issued the java and the javac commands, as follows:

c:\Program Files\Java\jdk1.5.0_22\bin>java C:\Users\David Hernandez\Documents\My JAVASE\
it returns: Exception in thread "main" java.lang.noClassDefFoundError: c:Users\David

Is it because my dir <david hernandez> has a space in between???

c:\Program Files\Java\jdk1.5.0_22\bin>javac C:\Users\David Hernandez\Documents\My JAVASE\
it returns: javac: invalid flag: c:\Users\David <---- Same S---!
Usage: javac <options> <source files>
where possible options include
...........all kind of option follow up.!!!
10 years ago

David Newton wrote:You'll need to put spaces around path names with spaces in them.

I don't understand why you haven't just tried it, or just typed in the complete path to the executable to see if it actually works--it'd be much, much faster than waiting for someone to help you here, no? Recall that even Windows has path completion via the TAB key.

And again: read up on the OS you're using; there are hundreds of tutorials, and Microsoft's own documentation, that tell you how to work in the environment you're working in. Why waste time not knowing how things work?

Tried it! c:\program files\java\jdk1.5.0_22\bin>javac then hit enter, then I got: Error: Can not read: ....written en notepad.
10 years ago

David Newton wrote:In the path, towards the front. You might want to get acquainted with how your OS works before going too much further--it will reap great dividends and make your life substantially easier.

Assuming your JDK is in c:\jdk1.6:If it's somewhere else, please use that path instead of the placeholder I used.

My JDK files are here C:\Program Files\Java\jdk1.5.0_22

The |bin file inside the JDK is here C:\Program Files\Java\jdk1.5.0_22\Bin

The sys var PATH is as follows: %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

The original sys var PATH has been backed up. The original does not look like the sample you sent, but Oh well is just a matter of adapting it. The problem is that I have not edited system variables but only one time before, long time ago. Nor sure how to do it. I dont know if it would be as C:\Program Files\Java\jdk1.5.0_22\Bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

If If can edit these variables and get it going one time, i can run the first 6 exercises I have written so far, test them, edit, fix them and LEARN java, meanwhile I am stuck. Thanks for all the input.
10 years ago

David Newton wrote:

I wrote:Is there a JDK "bin" directory on your path? If not, you need to make it so there is (or, I suppose, you could type in the full path, but that's really irritating).

This is my sys var PATH which reads %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\ ....... but I am not sure where the \bin would go.!!
10 years ago

Roger F. Gay wrote:Check java sdk setup instructions for setting the JAVA_HOME environment variable. If you're using Windows, you create the environment variable by clicking on System in the Control Panel -> Advance System Settings -> Environment Variables (button). If JAVA_HOME is set correctly, then javac will be recognized everywhere.

My sys var JAVA_HOME READS C:\Program Files\Java\jdk1.5.0_22 unsure if this is correct.

My sys var PATH reads %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\

I have made backups of these variables already.

Do I need to edit any of these variables so I can run a very simple and my first java source code.?
10 years ago
Based on what I read on this book, (1) I must save the source file written in notepad with an extension .java, then (2) compile the source code by issuing this statement in the CMD session as follows "javac", then (3) run (also in the CMD session) this statement "%java Beersong"

It fails at the second step!!, as follows:

c:\users\David Hernandez\javac
'javac' is not recognized as an internal or external command, operable program or batch file.


c:\users\David Hernandez\%javac
'%javac' is not recognized as an internal or external command, operable program or batch file.

Any ideas?. Thanks. DH
10 years ago

Christophe Verré wrote:

I guess I could edit the variable PATH variable within the "Sys variables" group

Yes. You can also set JAVA_HOME there.

1) JAVA_HOME = C:\Program Files\Java\jdk1.5.0_22

You mean I create a new variable in the "System Variable" group, name it JAVA_Home and the variable value to be C:\Program Files\Java\jdk1.5.0_22?

2)PATH = "%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\"

You mean I edit the Path variable within the "System Variable" group, add "%JAVA_HOME%\bin;" right before %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\"?


10 years ago
I downloaded what I believe is the J2SE 5.0 from SUN, it installed it in "C:\Program Files\Java\jdk1.5.0_22\", within it, there is a folder called “\bin". Now, the book says "Your need to add an entry to your PATH environment variable that points to the "\bin" directory inside the main Java directory. The" \bin" directory is the one you need a path to so when you type "% javac" at the command line, your terminal will know how to find the javac compiler".

Under "System Properties", "Advance" tab, there ar two groups, the "User Variables" and the "Sys Variables", I guess I could edit the variable PATH variable within the "Sys variables" group, which has the following content :
"%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\" but I am not sure what to edit it to and if I am in the right spot.
10 years ago

Joanne Neal wrote:And unless you have some specific reason for using Java 1.5 it's probably best to use the latest version which is 1.6.

Well Joan, I was told to start with this book called "Head First Java" to learn J2SE 5.0 first, and then move to J2EE. I need to install Java in my laptop, 2 things the "J2SE 5.0" [Installed but I did not see the need to unzipp it. I don’t see a zipped file. Did I miss something?] and the "J2Se API documentation" [Which I can not find. Where is it?]. I am behind on the installation I need to continue but can’t get the environment installed appropriately. Any advice from anyone will be great.
10 years ago

David Newton wrote:(I'm not sure what word "carpet" is supposed to be, but I'm pretty sure it's not "carpet" :)

Sorry David N, I meant to write "Folder", I dont know why I typed "Carpet".
10 years ago
While reading the java book, I noticed I need to download J2SE V1.5 from, but it also says that I need to download the API documentation from the same site. What it does not say is WHERE to downloaded it. I dont know if I need to download the J2SE V1.5 in a carpet I named <J2SE V1.5> and dowload the API documentation into another carpet I named <J2SE v1.5 API Doc> or if I should download both things into one single carpet i.e. <J2SE V1.5> . Help.

Also, what are the "BB Codes"

And finally, what are the "Smilies".

I am a newby.

David H
10 years ago