Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: New To Java

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default New To Java

    Could you show me where I went wrong with this program? It comes from a book and doesn't explain anything. Thanks.


    class FirstVariable
    {
    public static void main ( String[] args );
    {
    String message = Initial value;
    System.out.println("message");
    message = Modified value;
    System.out.println("message");
    }
    }


  2. #2
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: New To Java

    Hi SecTech,

    It is a simple error, nice and easy to correct. You have your quotation marks in the wrong spots. When you assign a value to a string variable it needs to have the quotation marks. When you use a variable in something like a println method, you only reference the variable name.

    String message = "Initial Value";
    System.out.println(message);
    Also there is no semicolon after the main method declaration.

    Good luck! Learning Java is great fun.

  3. #3
    Junior Member vasanthjayaraman's Avatar
    Join Date
    Jul 2013
    Location
    Chennai
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: New To Java

    In java String is a immutable object,,,So String object Created by enclosed with double Quote(" ") and Don't put Semi colon at the end of main() method
     
    class FirstVariable
    {
    public static void main ( String[] args )
    {
    String message = "Initial value";                        //string object
    System.out.println(message);
    }
    }


    I hope it is useful

  4. #4
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: New To Java

    vasanthjayaraman, you have left the quotation marks in place from the op's code in your example. The variable message in the println statement. I'm sure you meant to remove them.