Home Answers Viewqa Java-Beginners java declare two string values in single program

 
 


Anitha
java declare two string values in single program
1 Answer(s)      a year and 2 months ago
Posted in : Java Beginners

dear friends, If you declare two string values in single program like

class StringDemo { public static void main(String args[])

{ String s=new String("hello"); s=new String("world"); System.out.println(s); }}

I am getting output: "world".what is the reason why am not getting the string value "happy".please help me am new to java

View Answers

March 14, 2012 at 4:13 PM


String s=new String("hello"); when the above statement is executed a String object is created and s is pointing to that object.

s=new String("world"); Now a new String object is created whose value is "world" and s is now pointing to the new object whose value is "world" .

So,now no reference is pointing to "hello" object but the object is not removed. And when u say System.out.println(s), it indirectly mean as System.out.println(s.toString());









Related Pages:
Declare string array in Java (one and two dimensional)
Declare string array in Java (one and two dimensional... will learn how to declare string array in java. Java provides many ways to declare... dimensional array and two dimensional as well. 1. String arr[] = new String
How to declare String array in Java?
Following example will show you how to declare string array in java... elements of one dimensional array and two dimensional array. 1. String arr... ArrayDimensions { public static void main(String[] args) { //declare
Multiple values for a single parameter
Multiple values for a single parameter   ... multiples values for a single parameter like in checkboxes. We are going to make one... from where the values will be passed to the controller. In this program we have
Two Dimensional Array Program
Two Dimensional Array Program Using Nested for loop       This is a simple Java array  program . In this session we will teach how to use of a two dimensional array
Swapping of two numbers
program to calculate swap of two numbers. Swapping is used where  you want to interchange the values. This program will help you to increase your programming ability. In this program we will see how we can swap two numbers. We can do
Declare components
Java NotesWhere to declare components Components are typically declared...). This is the appropriate place to declare components which must be referenced after... boxes, etc. Those components whose values must be gotten or set. Local
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence of consecutive letters. If two letters are consecutive in any position the function
Uploading a single file by using JSp
Uploading a single file by using JSp  u have said about submit button..but in program u have not used submit button..and where file will be stored...;%@ page language="java" %> <HTML> <FORM ENCTYPE="multipart/form-data
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem...","root","K13nn0r"); ResultSet rs=null; String SQL="select...=st.executeQuery(SQL); rs.last(); int k=rs.getInt(1)+1; String k2=rs.getString
Java radio buttons and button groups two values
Java radio buttons and button groups two values  hi i have a problem...","root","K13nn0r"); ResultSet rs=null; String SQL="select...=st.executeQuery(SQL); rs.last(); int k=rs.getInt(1)+1; String k2=rs.getString
Concatenate two pdf files
; In this program we are going to concatenate two pdf files into a  pdf file through java program. The all data of files ... seeing the code.  The steps to execute this program: Makes minimum two
javascript where to declare variables
javascript where to declare variables  javascript where to declare...); </script> For more information, visit the following link: Declare variables in Javascript   JavaScript where to declare variables To declare
Java Compare String (== operator)
Java Compare String (== operator)       This section describes how two string references are compared. If two String variables point to the same object then these two
Ajax Multiply Two Values
to multiply two values and display the result on the page. This program calls the method 'callmultiply()' for the multiplying  the values entered by user... Ajax Multiplication Program      
using insert and delete in a single page in jsp
using insert and delete in a single page in jsp  I am using the following code in jsp to declare two javascript functions to insert and delete in a single jsp page but insert function doesn't works only delete function works even
Java String
Java String       In this section, you will learn about the java string. Java String is a set.... All String literals are instances of this class and two string literals
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
Multiplication of two Matrix
to declare two multidimensional array of type integer. Here in this program use two.... The Java two dimensional array  program is operate to the two matrix number...;    This is a simple Java multidimensional array program
Multiplication of two Matrix
the matrix.  Now, make this program, you have to declare two multidimensional array...;    This is a simple java program that teaches you for multiplying two matrix to each other. Here providing you Java source code
Merge two list into a single list
Description: This example demonstrate how to merge two lists into a single... and the mergelist funtion merge the two lists into a single list. Code: # include... ( struct node *p ) { printf("The data values in the list are\n"
Uploading Single File by Using JSP
the logic of the program or Java code is mainly written inside the scriptlet... will be passed as a parameter to the constructor of the byte array. Now declare two... Uploading Single File by Using JSP  
Two Dimensional Array Program
;    This is very simple program of Java. In this lesson we will learn how to display arrange form of two dimensional array program... a integer for array declaration Two dimensional array program. We are going
Uploading Single File by Using JSP
the logic of the program or Java code is mainly written inside the scriptlet... will be passed as a parameter to the constructor of the byte array. Now declare two... Uploading Single File by Using JSP  
Two Element Dividing Number
Dividing Two Numbers in Java       This is very simple java program. In this section we will learn how to divide any two number. In java program use the class package
Add Two Numbers in Java
Add Two Numbers in Java     ... is an array of String objects that takes values provided in command prompt. These passed arguments are of String types so these can't be added as numbers
Compare string example
;  In this section, you will learn how to compare two strings in java. The java lang package provides a method to compare two... of comparing the two strings. The following program uses the equals() method and helps
How to declare a Combobox without using a string in its declaration?
How to declare a Combobox without using a string in its declaration?  What i mean to ask is how can i declare a combobox first and initialise the values later? For example JComboBox x= new JComboBox(); ... String s={"Alpha
write a program which asks the user for two int values and calculates their sum.
write a program which asks the user for two int values and calculates their sum.  The title says it all, an example is (1,2) > 3
JSP Simple Examples
in a java. In jsp we can declare it inside the declaration directive or a scriptlet directive. String Length In java... Declaring string array in java An array is the collection
String Arrays Java
String Arrays Java      ... of values of a single type. Array is a collection of similar data types. It means if you have declared an array as string then it can only store the string values
Find String Values of Cell Using POI
Find String Values of Cell Using POI       In this program we are going to find the String... FindStringCellsValues.java C:\POI3.0\exmples\execl>java FindStringCellsValues example.xls String
Multiplication of Two Number in Class
; java program also provide complete illustration with source code.  Description this program  In this program we are going to use two any number... variable. We have to create one object for values passes. This program also
To get the String between two strings
To get the String between two strings  How to get string between two strings repeatedly using java?   Hi, Please tell me more about what do you want to achive. Thanks
Two dimensional array in java
Two dimensional array in java. In this section you will learn about two...: To declare an array just two square bracket with empty list required as follows... : A simple program of two dimension array. public class Twodarray
java multiple users with single connection - JSP-Servlet
java multiple users with single connection  hi, my problem is as follows : - Hide quoted text - i am developing a web project in java. i have... id.now these values will be retrieved from the database with the help
string
string  a java program to replace all matching substrings
Two Dimensional array program
Two Dimensional array program  consider a two dimensional array... and the first become the last.let the program output elements of the first array... static void main(String[] args) throws Exception { int rows, cols
JSP Simple Examples
; Comparing Two String with <c:if> In this program we... hold a fixed number of values of a single type. Array... as string then it can only store the string values.   
string
string  a java program using string function that computes your... links: http://www.roseindia.net/tutorial/java/core/printInitials.html http://www.roseindia.net/answers/viewqa/Java-Beginners/13383-print-initials.html
string
string  a java program using string function to input any string... ArrangeStringAlphabetically { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("Enter string
two dimensional - Java Beginners
two dimensional  write a program to create a 3*3 array and print the sum of all the numbers stored in it.  Hi Friend, Try the following... { public static void main(String[] args) throws IOException { int rows, cols
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
Square Elements of Two Dimensional Array
;     This is a simple java program for implementing the two dimensional array program and its square. This session provide you... that contains integer type values. After this, we use two 'for' loop that denotes rows
Java String Occurrence in a String
Java String Occurrence in a String   .... Description of the code: In the program code given below, we will find another String from a String which already exists. Here we have taken two variables- result
string
string  a java program to input a string and display the string...*; import java.io.*; public class FirstLetter{ public static String capitalizeFirstLetter( String str ) { final StringTokenizer st = new StringTokenizer( str
combine two pdf files
combine two pdf files       In this program we are going to tell you how you can read a pdf file and combine more than one pdf into one.  To make a program over this, firstly
string
string  program for String reverse and replace in c,c++,java e.g.Input:10,20,hello output:hello;20;10   Hi Friend, Try the following java...(String[] args) { String array[]=new String[5]; Scanner input
string
string  a java program using string function and access modifiers to automate the insurance company which will have to manage the information about policy holders Data Members: 1)Policy No 2)Name of policy holder 3)Address 4

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.