aspose file tools*
The moose likes Beginning Java and the fly likes string variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string variable" Watch "string variable" New topic
Author

string variable

kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
can someone tell me what is the deference between

str a = "abc"


str a ="+i+";

what is the double + means?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61768
    
  67

Nothing. It's just a string.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jj Hill
Ranch Hand

Joined: Jul 25, 2011
Posts: 41

The "+" won't do anything while inside the quotation marks - it's just text, a string literal. The only character that has any effect in the string literal is "\".
kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
erm.....so what is the purpose of adding + for the sql statment?

is "SELECT * FROM Student WHERE StudentID = '" + stuID + "';"; equivalent to "SELECT * FROM Student WHERE StudentID = '" stuID "';";
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8427
    
  23

kahkean chor wrote:erm.....so what is the purpose of adding + for the sql statment?

Completely different question.

Answer: usually to include the value of a variable; although it's not the best way to do it. Have a look at PreparedStatement.

And BTW: How do you imagine we're supposed to know that your strings are part of an SQL statement?

is "SELECT * FROM Student WHERE StudentID = '" + stuID + "';"; equivalent to "SELECT * FROM Student WHERE StudentID = '" stuID "';";

No; because that 2nd statement won't compile.

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
so sad i dont get it....btw thanks for your reply
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string variable