[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

JSP Question - URGENT

Posted on 2001-08-04
4
Medium Priority
?
190 Views
Last Modified: 2010-03-31
Ok, the following is my question.  Say I have a class implementing a tag.  This tag has two attributes, both correctly defined in the tld and correctly used in the JSP.  If the class implementing the class has a method like this:

public String getFirstAttr() {
 return firstAttr + getSecondAttr();
}

If we assume everything is correctly implemented, is it possible for getFirstAttr to return the value of firstAttr concatenated with null instead of the value provided for secondAttr?

Please respond quickly.

John Rayburn
0
Comment
Question by:Laminamia063099
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
black earned 1200 total points
ID: 6352552
yes if getSecondAttr() returns null and firstAttr is equal to "hello" you'll get the following string:
hellonull
basically the + operator when used with strings will convert any null reference to the string "null" and that string literal will be used.
It might be best if you did
public String getFirstAttr() {
  if(getSecondAttr == null) {
    return firstAttr;
  }
  return firstAttr + getSecondAttr();
}

that way the string "hello" will be returned instead of "hellonull"
0
 
LVL 3

Author Comment

by:Laminamia063099
ID: 6356505
Notice, I mention that getSecondAttr returns null "instead of the value provided for secondAttr". If secondAttr is not null, null would not be returned, correct?

John
0
 
LVL 3

Expert Comment

by:black
ID: 6357772
yes, if the getSecondAttr method returns a non null value then you will not get null concatenated.
0
 
LVL 3

Author Comment

by:Laminamia063099
ID: 6357818
Thanks.  I was reading a book passage that was incorrect and I wanted a second opinion!

John
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question