Results 1 to 14 of 14
  1. #1
    sales1 is offline Member
    Join Date
    Aug 2008
    Posts
    11
    Rep Power
    0

    Unhappy [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

    ~Alex
    Last edited by sales1; 08-17-2008 at 09:21 AM. Reason: sorry missed the most important bit xd

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    my computer wont allow the command:
    What exactly is the error message? When you post error messages, please copy and paste them as is,don't edit them.
    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.
    System.out.print1n("I Love Java!");
    Is that a number 1 or the letter l ? between the t and n?

  3. #3
    sales1 is offline Member
    Join Date
    Aug 2008
    Posts
    11
    Rep Power
    0

    Default

    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.

    ~Alex
    Last edited by sales1; 08-17-2008 at 09:42 AM.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    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:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.

    C:\Documents and Settings\Owner>
    If you'll read to the last line of my last post you might see what the problem is.

  5. #5
    sales1 is offline Member
    Join Date
    Aug 2008
    Posts
    11
    Rep Power
    0

    Default

    norm i think i can quite safely say i love u. It finally works after wasting a lot of time thanks so very much :)

  6. #6
    jsmiley is offline Member
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    Default

    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

  7. #7
    sales1 is offline Member
    Join Date
    Aug 2008
    Posts
    11
    Rep Power
    0

    Default

    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

  8. #8
    Join Date
    Aug 2008
    Posts
    8
    Rep Power
    0

    Default

    yeah its typo thing...

    You type :

    Java Code:
     System.out.print[B][COLOR="Red"]1[/COLOR][/B]n("I Love Java!");
    It should be like this :

    Java Code:
     System.out.print[COLOR="Red"][B]l[/B][/COLOR]n("I Love Java!");

  9. #9
    Join Date
    Aug 2008
    Posts
    8
    Rep Power
    0

    Default

    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 :
    Java Code:
    circleToy@9304b1
    Eclipse Result :
    Java Code:
    circleToy.circleToy@3e25a5
    Code :
    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();
        }
    }
    The correct result for this code should be "40" ...
    Am I wrong ?
    calcDiameter = (radius * 2)
    calcDiameter (20 * 2) = 40

  10. #10
    new_2_java is offline Member
    Join Date
    Feb 2008
    Posts
    60
    Rep Power
    0

    Default

    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());

  11. #11
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default

    circleToy@9304b1
    The above is the default output from the Object.toString() method for object a: System.out.println(a);
    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.

  12. #12
    Join Date
    Aug 2008
    Posts
    8
    Rep Power
    0

    Default

    Thanks for your help guys...

    Those informations really help me understanding Java...

    Happy coding. :D

  13. #13
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    If you have solve the problem, please mark it as solved. It's really helpful to all members who's looking on.

  14. #14
    sales1 is offline Member
    Join Date
    Aug 2008
    Posts
    11
    Rep Power
    0

    Default

    there we go marked as solved for any one with the same problem :)

    ~Alex

Similar Threads

  1. Basic Java help, AIM?
    By jkswebsite in forum New To Java
    Replies: 4
    Last Post: 07-11-2012, 06:17 PM
  2. basic java help
    By adred in forum New To Java
    Replies: 0
    Last Post: 03-08-2008, 12:36 PM
  3. help with basic java code
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 06:47 PM
  4. Help with basic shapes in java
    By carl in forum Java 2D
    Replies: 1
    Last Post: 07-31-2007, 11:40 PM
  5. Help, basic shapes using java
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 07-31-2007, 08:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •