Results 1 to 14 of 14
Thread: [SOLVED] very basic java problem
- 08-16-2008, 09:09 PM #1
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
[SOLVED] very basic java problem
i just got my brand new "Learn to program with java" book today and am having fun learning about java but when it came to compiling the first program:
/**
This program displays "I love Java!" to the standard output.
*/
class ILoveJava {
public static void main(String[] args) {
System.out.print1n("I Love Java!");
}
}
i came un-glued i have tried to learn java multiple times before with e-books but i found it impossible to read from my computer screen. Anyways long story short my computer wont allow the command:
Javac Appname.java
So i have taken to the only method that works (sort of) which is to give the directory straight to the javac file:
jdk1.6.0_07\bin\javac Appname.java
But this is irrelvant as the problem is when i come to compile the above code it keeps coming up with the same error:
C:\Java>jdk1.6.0_07\bin\javac ILoveJava.java
ILoveJava.java:6: cannot find symbol
symbol : method print1n(java.lang.String)
location: class java.io.PrintStream
System.out.print1n("I Love Java!");
^
1 error
plz help i have been stuck on the first source code for ages now and im getting tired lol and help is much appreciated
~AlexLast edited by sales1; 08-17-2008 at 09:21 AM. Reason: sorry missed the most important bit xd
- 08-16-2008, 09:56 PM #2
What exactly is the error message? When you post error messages, please copy and paste them as is,don't edit them.my computer wont allow the command:
I guess that the OS can't find the javac command. You need to add the path to the javac.exe file to the PATH environment variable. How to do This has been described on the forum and you can find it with a search.
Is that a number 1 or the letter l ? between the t and n?System.out.print1n("I Love Java!");
- 08-17-2008, 09:24 AM #3
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
oh for god sake well i cant copy and paste because command prompt wont let me the forum wont let me post the link to the image of the error the only thing now is to describe it and that won't go well. Basically the error is exactly the same as i posted it above but underneath the line:
System.out.print1n("I love Java!")
There is a (^) underneath the second (.)
if that makes it any clearer you must be a genius. I'll try changing the PATH again see if that works because the java files are in a different area to the last time i changed the PATH. Thanks for the help so far.
~AlexLast edited by sales1; 08-17-2008 at 09:42 AM.
- 08-17-2008, 01:45 PM #4
To copy from a Command prompt, click on the icon in the upper left of the window, select the Menu, select "Select All" - part of the window wil have a white back ground. Click thru again and this time select Copy. Now paste it here. Here's what I get:
If you'll read to the last line of my last post you might see what the problem is.Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\Owner>
- 08-17-2008, 02:10 PM #5
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
norm i think i can quite safely say i love u. It finally works after wasting a lot of time thanks so very much :)
- 08-18-2008, 03:39 PM #6
Member
- Join Date
- Aug 2008
- Posts
- 1
- Rep Power
- 0
Hi Alex
That's my book you're reading, and I feel bad that you're having problems.
You have a typo--for one thing, you typed println with the number 1, not the letter L.
Java, like any programming language, is very picky about syntax--it gets confused easily.
As I point out in my book, you could have emailed me directly about this (my email address is in the book).
You can also check my support page for the book---there you can download all of the completed exercises and programs in the book, and you could have compared it to yours. Here's the link...oops, sorry, the forum won't let me post it but it's included in my book.
Just scroll down to my Java book and look for the link to the exercises.
Once you get a few programs under your belt, you'll be well on your way to mastering this wonderful language.
John Smiley
- 08-18-2008, 05:55 PM #7
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
if you really are john smiley i really want to thank for such a wonderful book it's very interesting and makes everything very understandable. I would recommend this book to any one wanting to learn java. Thnks :)
~Alex
P.S. I pretty get the syntax right every time i just need to work on my spelling now
- 08-18-2008, 08:26 PM #8
Member
- Join Date
- Aug 2008
- Posts
- 8
- Rep Power
- 0
yeah its typo thing...
You type :
It should be like this :Java Code:System.out.print[B][COLOR="Red"]1[/COLOR][/B]n("I Love Java!");
Java Code:System.out.print[COLOR="Red"][B]l[/B][/COLOR]n("I Love Java!");
- 08-18-2008, 08:28 PM #9
Member
- Join Date
- Aug 2008
- Posts
- 8
- Rep Power
- 0
Could you help me too..
I've done some little coding to test how Java works using System.out.println() too
But the result are rather unecpected weird, it always print same false result.
Could anyone please help me, what am I doing wrong in the code. Thx in advance.
I've tested it in Eclipse & intelliJ IDEA
with jdk1.6.0_07
intelliJ IDEA Result :
Eclipse Result :Java Code:circleToy@9304b1
Code :Java Code:circleToy.circleToy@3e25a5
The correct result for this code should be "40" ...Java Code:public class circleToy { private double radius; public circleToy() { radius = 0.0; } public circleToy(double radius) { this.radius = radius; } public void setRadius(double radius) { this.radius = radius; } public double getRadius() { return radius; } public double getDiameter() { return calcDiameter(); } private double calcDiameter() { return radius * 2; } static void test() { circleToy a = new circleToy(20); System.out.println(a); } public static void main(String[] args) { test(); } }
Am I wrong ?
calcDiameter = (radius * 2)
calcDiameter (20 * 2) = 40
- 08-18-2008, 09:55 PM #10
Member
- Join Date
- Feb 2008
- Posts
- 60
- Rep Power
- 0
looking at your code, you are trying to print circleToy class, which you should not, and not the diameter
you should do something like this, in your test() method:
Java Code:System.out.println("Diameter is: " + a.getDiameter());
- 08-18-2008, 11:48 PM #11
The above is the default output from the Object.toString() method for object a: System.out.println(a);circleToy@9304b1
It takes the class name and appends to it the object's memory location.
If you want to see something different in the output when you println() an object reference, override the class's toString() method and have it return what you want to see.
- 08-19-2008, 10:58 AM #12
Member
- Join Date
- Aug 2008
- Posts
- 8
- Rep Power
- 0
Thanks for your help guys...
Those informations really help me understanding Java...
Happy coding. :D
- 08-19-2008, 11:32 AM #13
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
If you have solve the problem, please mark it as solved. It's really helpful to all members who's looking on.
- 08-20-2008, 08:33 PM #14
Member
- Join Date
- Aug 2008
- Posts
- 11
- Rep Power
- 0
Similar Threads
-
Basic Java help, AIM?
By jkswebsite in forum New To JavaReplies: 4Last Post: 07-11-2012, 06:17 PM -
basic java help
By adred in forum New To JavaReplies: 0Last Post: 03-08-2008, 12:36 PM -
help with basic java code
By elizabeth in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:47 PM -
Help with basic shapes in java
By carl in forum Java 2DReplies: 1Last Post: 07-31-2007, 11:40 PM -
Help, basic shapes using java
By coco in forum AWT / SwingReplies: 1Last Post: 07-31-2007, 08:52 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks