Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Embaressing Question >.<

Thread view: 
gwoodhouse@gmail.com - 08 Oct 2007 15:09 GMT
Hullo,

Now, your all going to laugh i know it but:

What is the technical name for the if statements that look like
((argument) ? answer : answer);

Ive always used if-elseif-else symantics - I get confused as to which
side is the "if-true" side.

Ill go hide my head in shame now!

Graeme
Karsten Wutzke - 08 Oct 2007 15:15 GMT
On 8 Okt., 16:09, "gwoodho...@gmail.com" <gwoodho...@gmail.com> wrote:
> Hullo,
>
[quoted text clipped - 9 lines]
>
> Graeme

The technical term for that is a ternary operator. The expression
following the '?' is the one that gets evaluated if the boolean
expression before the '?' is evaluated to true, otherwise the
expression behind the ':' is evaluated.

There are so many basic sources for stuff like that. Even
comp.lang.java.help is better than this group. Google is your friend.

Karsten
Gordon Beaton - 08 Oct 2007 15:16 GMT
> What is the technical name for the if statements that look like
> ((argument) ? answer : answer);
>
> Ive always used if-elseif-else symantics - I get confused as to which
> side is the "if-true" side.

That's a conditional expression, not a statement. It uses the
conditional operator (?:) , often called the ternery operator.

/gordon

--
Lew - 08 Oct 2007 15:26 GMT
> What is the technical name for the if statements that look like
> ((argument) ? answer : answer);

Expressions.

The operator ?: is the "conditional", or "ternary" [1], operator.  The part
before the question mark is the boolean condition, then the true part comes
after the question mark, and the false part after the colon.

Had you considered looking to the tutorials or JLS for this?
<http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.25>
<http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html>
<http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html>

[1] "Ternary" really means "three-part" operator, as opposed to "binary" or
"two-part" operator, but since ?: is the only such operator in Java and C.*
the term has stuck.

Signature

Lew

gwoodhouse@gmail.com - 08 Oct 2007 15:37 GMT
> Had you considered looking to the tutorials or JLS for this?
> <http://java.sun.com/docs/books/jls/third_edition/html/expressions.htm...>
> <http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html>
> <http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html>

> Lew

Yeah, tried google but its surprisingly hard to search for something
when the only fixed bit of coding is ()?:; Now that i know what to
search for its much easier obviously :)

Thanks guys.

Graeme
Lew - 08 Oct 2007 15:40 GMT
Lew wrote:
>> Had you considered looking to the tutorials or JLS for this?
>> <http://java.sun.com/docs/books/jls/third_edition/html/expressions.htm...>
>> <http://java.sun.com/docs/books/tutorial/java/nutsandbolts/index.html>
>> <http://java.sun.com/docs/books/tutorial/java/nutsandbolts/op2.html>

> Yeah, tried google but its surprisingly hard to search for something
> when the only fixed bit of coding is ()?:; Now that i know what to
> search for its much easier obviously :)

<http://search.yahoo.com/search?p=Java+basics+tutorial>
<http://search.yahoo.com/search?p=Java+%22question+mark%22+operator>

Signature

Lew

Roedy Green - 11 Oct 2007 22:20 GMT
On Mon, 08 Oct 2007 07:37:28 -0700, "gwoodhouse@gmail.com"
<gwoodhouse@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>Yeah, tried google but its surprisingly hard to search for something

you could have found it by looking up "?" in the Java glossary or
"operator" without knowing the term "ternary".

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 11 Oct 2007 22:13 GMT
On Mon, 08 Oct 2007 07:09:14 -0700, "gwoodhouse@gmail.com"
<gwoodhouse@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>What is the technical name for the if statements that look like
>((argument) ? answer : answer);
>
>Ive always used if-elseif-else symantics - I get confused as to which
>side is the "if-true" side.

see http://mindprod.com/jgloss/ternaryoperator.html
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.