• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

operator

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any one explain this program


clas BoolTest {
public static void main(String[] args) {

Boolean b = new Boolean("TRue");
Boolean c = new Boolean("Null");
boolean d = true;
Boolean e = (b||c)&&d;
System.out.println(e);
}
}

o/p true
 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what have you not understood in above program? i have inserted to SOP's to make it clear for you.
b is true and c is false, so when you use or shortcut or operator then it will see only true for you and in next condition it will find && shortcut operator of variable d which is also true. so e is assigned value true.

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

Boolean b = new Boolean("TRue");
Boolean c = new Boolean("Null");
boolean d = true;
System.out.println(b); //here
System.out.println(c);//here

Boolean e = (b||c)&&d; //result
System.out.println(e);
}

}
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi aneea,

for an explanation why b is true and c is false, have a look at the API documentation.
 
anita dhar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Boolean b = new Boolean("TRue");
2. Boolean c = new Boolean("Null");
3. boolean d = true

This first line is Boolean constructor that means condtion we are giving in it it is that only

as boolean condtion checks only true or false condition so how in the line 2 it is Null and what it means
 
Ranch Hand
Posts: 99
Mac Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
javadoc says -
public Boolean(String s)
Allocates a Boolean object representing the value true if the string argument is not null and is equal, ignoring case, to the string "true". Otherwise, allocate a Boolean object representing the value false.


According to the constructor definition line 1 gives "true" and line 2 gives "false".
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic