Results 1 to 8 of 8

Thread: Java basic

  1. #1
    chinthanabt is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default Java basic

    String st="hello";
    st+="world";

    strings are imutable so what willl happen here;

    please help me

    thax.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,532
    Rep Power
    24

    Default Re: Java basic

    Moving thread to New To Java, as that's a better home than the JDK sub forum.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,421
    Blog Entries
    7
    Rep Power
    26

    Default Re: Java basic

    At the end of that code snippet, st refers to a new String "helloworld" and the two other Strings "hello" and "world" are to be destroyed by the garbage collector (if possible).

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  4. #4
    chinthanabt is offline Member
    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Default Re: Java basic

    i saw video on you tube it says;

    st=new StringBuffer("hello").append("world");

    please expalin me, is this correct

    thax.

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    10

    Default Re: Java basic

    Does it work?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    Nihar is offline Member
    Join Date
    May 2017
    Posts
    3
    Rep Power
    0

    Default Re: Java basic

    Below is the syntax highlighted version of HelloWorld.java from 1.1 Hello World.


    /************************************************** ****************************
    * Compilation: javac HelloWorld.java
    * Execution: java HelloWorld
    *
    * Prints "Hello, World". By tradition, this is everyone's first program.
    *
    * % java HelloWorld
    * Hello, World
    *
    * These 17 lines of text are comments. They are not part of the program;
    * they serve to remind us about its properties. The first two lines tell
    * us what to type to compile and test the program. The next line describes
    * the purpose of the program. The next few lines give a sample execution
    * of the program and the resulting output. We will always include such
    * lines in our programs and encourage you to do the same.
    *
    *For learning Java visit here: https://hackr.io/tutorials/learn-java
    ************************************************** ****************************/

    public class HelloWorld {

    public static void main(String[] args) {
    // Prints "Hello, World" to the terminal window.
    System.out.println("Hello, World");
    }

    }

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,144
    Rep Power
    12

    Default Re: Java basic

    First, this has nothing to do with the question. Second, please do not spoon feed solutions (even incorrect ones).
    Third, this thread is over 3 years old. Please don't resurrect old threads.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,421
    Blog Entries
    7
    Rep Power
    26

    Default Re: Java basic

    Closing this poor old thread ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. basic java + ms sql
    By selomojemalo in forum New To Java
    Replies: 4
    Last Post: 08-06-2013, 09:47 AM
  2. basic java
    By sukeerthi in forum New To Java
    Replies: 3
    Last Post: 06-30-2012, 12:33 PM
  3. Java Basic
    By Anveshan in forum New To Java
    Replies: 6
    Last Post: 05-06-2011, 10:45 AM
  4. Basic java
    By santa in forum New To Java
    Replies: 5
    Last Post: 11-16-2009, 11:16 AM
  5. basic java help
    By adred in forum New To Java
    Replies: 0
    Last Post: 03-08-2008, 01:36 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
  •