• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic