Win a copy of Spring Boot in Practice this week in the Spring forum!

Greg Mark

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

Recent posts by Greg Mark

So I just concluded the 'Introduction to Java Applications' chapter in 'Java How to Program'. I'd probally be punching my computer cause of those damned environmental variables if not for the kind people here.

Anyways, one of the exercises in the end of the chapter is to put together an app that collects two numbers, then give the; sum, difference, product and quotient.

I put this together and it worked thankfully:


After it ran, I was wondering how I could shorten the length of the code, so I tried this:


I tried it out, and it worked. YAY ME, but I was wondering, which is more efficient.

I concluded the second one because there is no need to store the four solutions. As a result the first one ties up memory that could otherwise be used one something else. Am I right in this assumption? I know this is a meaningless app, and memory use means nothing for it. Just curiosity.

Thanks for your time =)
11 years ago

Alex Hurtt wrote:Leaving it there probably won't hurt or mess anything up. Just didn't want you getting the wrong impression that the use of Java required that it be set.



Alright, cool. Thank you =) It's good to have everything I need for the command prompt in working right.
11 years ago

Alex Hurtt wrote: There shouldn't be any need to create a JAVA_HOME environment variable unless you are using some tool or library (like ANT maybe for example) which specifically calls for it. The documentation for any such product should mention if it needs this. Otherwise you don't need to set JAVA_HOME as an Environment variable other than for your own convenience or use. I think it is a common misconception that the JAVA_HOME env. variable is somehow required by the java runtime.



I had eclipse setup when I was using Head First before I realized the need for something with better explanations of the whats and whys. I think that had ANT, I switched over to NetBeans b/c that's what the Java site was making use of. Could this possibly mess me up in future endeavors or can I just leave it as is, currently everything seems to be in working order. Then again I am only doing simple programs as per java how to program.
11 years ago
Thank you everyone for the quick replies. I deleted the CLASSPATH from my environment variables and it's working now. =)

Will quick time create this variable again if I run it? I don't use the program, just wondering.

Edit: Also created the JAVA_HOME variable.
11 years ago
Hello all. I've been reading on Javas site and working out of 'Java How to Program' the past couple of days when I get the chance.

This isn't a syntax error, at least I don't think it is, so much as I don't think my class path is setting properly.

C:\Users\Sparrow\Desktop\My Stuff\Java\Projects\Tuts\Java HTP\2.1 Welcome\Welcom
e1\src>java Welcome1
Exception in thread "main" java.lang.NoClassDefFoundError: Welcome1
Caused by: java.lang.ClassNotFoundException: Welcome1
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Welcome1. Program will exit.

I get this for anything I try to run using the 'java' command. 'javac' works fine.

I have this 'C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip' set for it. I also tried it with the ' .; ' ahead of it. I'm kind of at a loss here. I'm running vista if that makes a difference.

This is the code:


Netbeans displays the results. Could Netbeans be a part of the issue?


Thank you for your time =)

Edit: I'm looking around on google and from what I'm reading, I have to set this each time I work in a different folder? I thought I simply set in the environment variables and that was that.
11 years ago
Alright. I'll take a look and read up. Thank you for your time.
11 years ago
I'll do that, thank you. I wasn't sure about what it meant by file.

Now, GuessGame, Player, and GameLaunch are my classes, right?

Then this here would be my instance variable?:


Then this would be my method?:


I'm still unclear on how it translates to the actual code, I understand what the terms mean, just not what it is in practice.
11 years ago
First off, let me say:

HELLO EVERYONE!

Back in the day I tried to learn C++, but I was younger and patience wasn't my virtue. After that I tried out scripting for NWN and found that to be fun, but my computer died and I lost interest.

After playing Minecraft and Dwarf Fort recently, my interest in learning a programing language has been rekindled and it seems like Java is a good place to start. I'm 23 btw.

So heres the breakdown:

After deciding to try this out I went to the net to find a book, got myself a copy of Head First and I'm on the Guess Game Tut.

Here's what I have:


After getting 23 errors in the code I was able to widdle it down to 2 on my own. I'm using Eclipse for this. Was gonna use notpad and the JDK compiler but I couldn't figure that out on my own. This what I'm having trouble with in the code now.



Its telling me the 'The public type Player has to be defined in its own file."

Same for this (only with GameLauncher):



Now the tut doesn't specify this. I have it all in one Java doc. How do I solve this?

Now the book is done 1.5 I'm using 1.6 Is this my problem? What am I missing? Are my classes defined right? I'm also not to sure what the method and classes are here. Same for the instance variable.

Thank you to anyone who has taken the time to read this, and great thanks to anyone who takes the time to help a clueless self teaching student.

I'm looking forward to a long stay here.

11 years ago