Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
I am learning GoF Java Design Patterns and I want to see some real life examples of them. Can you guys point to some good usage of these Design Patterns.(preferably in Java's core libraries). Thank you
I was recently trying to convert a string literal into a boolean, when the method boolean Boolean.getBoolean(String name) popped out of the auto-complete window. There was also another method (boolean Boolean.parseBoolean(String s)) appearing right after, which led me to search to find out what were the differences between these two, as they both seemed to do the same. It turns out that what B...
I have a class with a private static final field, that unfortunately i need to change at run time. using reflection i get this error: java.lang.IllegalAccessException: Can not set static final boolean field is there any possibility to change it anyway? Field hack = WarpTransform2D.class.getDeclaredField("USE_HACK"); hack.setAccessible(true); hack.set(null, true);
I have a quick and straighforward question: I have this simple class: public class A { public void m(Object o) { System.out.println("m with Object called"); } public void m(Number n) { System.out.println("m with Number called"); } public static void main(String[] args) { A a = new A(); // why will m(Number) be called? a.m(null...
the following code throws NPE for me: int num = Integer.getInteger("123"); is my compiler invoking getInteger on null since it's static? that doesn't make any sense! can someone explain what's happening? thanks.
While I know that by definition a boolean consists of only two states, true or false. I was wondering what value does a boolean have before it is initialized with one of these states.
I would like to understand the difference between the Boolean and boolean types in Java, specifically as they relate to GWT. I know that methods are not supported but I want more info if it is available.
Title basically says it all. I've tried Googling but return a load of false positives. I guess I'm just wondering if there was a certain rationale behind these two specific numbers or could they have easily been many other sets of numbers? Edit: And, since the source of the numbers has been answered, any reason why writers of the Boolean hashCode method used those numbers (besides that they're...
I have this code public static Boolean freq[] = new Boolean[Global.iParameter[2]]; freq[Global.iParameter[2]] = false; could someone tell me what exactly i'm doing wrong here and how would i correct it? I just need to initialize all the array elements to Boolean false. thank you
I have this behaviour I do not really understand ${requestScope.rs_redirectFacade} ${requestScope.rs_redirectFacade.class.name} ${requestScope.rs_redirectFacade == 'error'} outputs false java.lang.Boolean true How can it be exlpained? What it the correct way to write the test in order to first test if the two 'things' have the same type and then if their value is the same?
I have a custom button class called ImageButton that extends JButton. In it i have a setEnabled method that I want to be called rather than the JButton's setEnabled method. My code is below. In my other class I create a new instance of ImageButton, but when I try to use the setEnabled method, it goes straight to the JButton's setEnabled method. Even before I run the code, my IDE is telling me ...
I need a mutable boolean field in Java (I will return this field via get* method later and it should be possible to modify this field). Boolean doesn't work because there are no set* methods in the Boolean class (I would say that Boolean is immutable, you can only change the reference, but you can't change the object itself). I guess I can use Boolean array of size 1. But probably there are m...
Possible Duplicate: Java Boolean Question Good afternoon What is the default value of Boolean (primitive wrapper) in Java
I am curious. Why do I have to type String myStr with a capital letter whereas I type int aNumba with a lower-case letter?
I have a question about the meaning (evaluation) of Boolean variables in return statements in Java. I know that: if (var) { ... } is the same as: if (var==true) { ... } In the second case we explicitly say var==true, but we don't need to do this, because Java evaluates var as true anyway. I hope I have understood this right. My question is: is it the same when Boolean variables are retu...
I am surprised to know that getBoolean() and valueOF() method returns diff output for the same string input. I have tried to pass the String str = "true" to both the methods. But getBoolean() gives me false output whereas valueOF() gives me right output that is true. why?? Guys need your comments? Regards, Mahendra
There are discussion around Integer vs int in Java. The default value of the former is null while in the later it's 0. How about Boolean vs boolean? A variable in my application can have 0/1 values. I would like to use boolean/Boolean and prefer not to use int. Can I use Boolean/boolean instead? Thanks.
I've been learning Java in my spare time and have a quick question I can't seem to figure out. This code returns true: Boolean testBool = true; Boolean test = testBool instanceof Object; System.out.println(test); However, I thought Boolean was a primitive type and when I try this same logic with any other primitive type I get a compiler error that says: unexpected type required: reference ...
is there any reason why java booleans take only true or false why not 1 or 0 also?
I did a little search on this but couldn't find anything useful. The point being that if String value is either "true" or "false" the return value should be true. In every other value it should be false. I tried these: String value = "false"; System.out.println("test1: " + Boolean.parseBoolean(value)); System.out.println("test2: " + Boolean.valueOf(value)); System.out.println("test3: " + Boo...
PS: I understand the difference between "true" and true. Edit: I also understand that Boolean.TRUE is a wrapper for the primitive true, my question then is - why does the primitive boolean accept Boolean.TRUE as a value? For instance, boolean boolVar = Boolean.TRUE; seems to be a valid statement.
  /*
   * Copyright 1994-2006 Sun Microsystems, Inc.  All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.  Sun designates this
   * particular file as subject to the "Classpath" exception as provided
   * by Sun in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * version 2 for more details (a copy is included in the LICENSE file that
  * accompanied this code).
  *
  * You should have received a copy of the GNU General Public License version
  * 2 along with this work; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  * CA 95054 USA or visit www.sun.com if you need additional information or
  * have any questions.
  */
 
 package java.lang;

The Boolean class wraps a value of the primitive type boolean in an object. An object of type Boolean contains a single field whose type is boolean.

In addition, this class provides many methods for converting a boolean to a String and a String to a boolean, as well as other constants and methods useful when dealing with a boolean.

Author(s):
Arthur van Hoff
Since:
JDK1.0
 
 public final class Boolean implements java.io.Serializable,
                                       Comparable<Boolean>
 {
    
The Boolean object corresponding to the primitive value true.
 
     public static final Boolean TRUE = new Boolean(true);

    
The Boolean object corresponding to the primitive value false.
 
     public static final Boolean FALSE = new Boolean(false);

    
The Class object representing the primitive type boolean.

Since:
JDK1.1
 
     public static final Class<BooleanTYPE = Class.getPrimitiveClass("boolean");

    
The value of the Boolean.

Serial:
 
     private final boolean value;

    
use serialVersionUID from JDK 1.0.2 for interoperability
 
     private static final long serialVersionUID = -3665804199014368530L;

    
Allocates a Boolean object representing the value argument.

Note: It is rarely appropriate to use this constructor. Unless a new instance is required, the static factory valueOf(boolean) is generally a better choice. It is likely to yield significantly better space and time performance.

Parameters:
value the value of the Boolean.
 
     public Boolean(boolean value) {
         this. = value;
     }

    
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. Examples:

new Boolean("True") produces a Boolean object that represents true.
new Boolean("yes") produces a Boolean object that represents false.

Parameters:
s the string to be converted to a Boolean.
    public Boolean(String s) {
        this(toBoolean(s));
    }

    
Parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string "true".

Example: Boolean.parseBoolean("True") returns true.
Example: Boolean.parseBoolean("yes") returns false.

Parameters:
s the String containing the boolean representation to be parsed
Returns:
the boolean represented by the string argument
Since:
1.5
    public static boolean parseBoolean(String s) {
        return toBoolean(s);
    }

    
Returns the value of this Boolean object as a boolean primitive.

Returns:
the primitive boolean value of this object.
    public boolean booleanValue() {
        return ;
    }

    
Returns a Boolean instance representing the specified boolean value. If the specified boolean value is true, this method returns Boolean.TRUE; if it is false, this method returns Boolean.FALSE. If a new Boolean instance is not required, this method should generally be used in preference to the constructor Boolean(boolean), as this method is likely to yield significantly better space and time performance.

Parameters:
b a boolean value.
Returns:
a Boolean instance representing b.
Since:
1.4
    public static Boolean valueOf(boolean b) {
        return (b ?  : );
    }

    
Returns a Boolean with a value represented by the specified string. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true".

Parameters:
s a string.
Returns:
the Boolean value represented by the string.
    public static Boolean valueOf(String s) {
        return toBoolean(s) ?  : ;
    }

    
Returns a String object representing the specified boolean. If the specified boolean is true, then the string "true" will be returned, otherwise the string "false" will be returned.

Parameters:
b the boolean to be converted
Returns:
the string representation of the specified boolean
Since:
1.4
    public static String toString(boolean b) {
        return b ? "true" : "false";
    }

    
Returns a String object representing this Boolean's value. If this object represents the value true, a string equal to "true" is returned. Otherwise, a string equal to "false" is returned.

Returns:
a string representation of this object.
    public String toString() {
        return  ? "true" : "false";
    }

    
Returns a hash code for this Boolean object.

Returns:
the integer 1231 if this object represents true; returns the integer 1237 if this object represents false.
    public int hashCode() {
        return  ? 1231 : 1237;
    }

    
Returns true if and only if the argument is not null and is a Boolean object that represents the same boolean value as this object.

Parameters:
obj the object to compare with.
Returns:
true if the Boolean objects represent the same value; false otherwise.
    public boolean equals(Object obj) {
        if (obj instanceof Boolean) {
            return  == ((Boolean)obj).booleanValue();
        }
        return false;
    }

    
Returns true if and only if the system property named by the argument exists and is equal to the string "true". (Beginning with version 1.0.2 of the JavaTM platform, the test of this string is case insensitive.) A system property is accessible through getProperty, a method defined by the System class.

If there is no property with the specified name, or if the specified name is empty or null, then false is returned.

Parameters:
name the system property name.
Returns:
the boolean value of the system property.
See also:
System.getProperty(java.lang.String)
System.getProperty(java.lang.String,java.lang.String)
    public static boolean getBoolean(String name) {
        boolean result = false;
        try {
            result = toBoolean(System.getProperty(name));
        } catch (IllegalArgumentException e) {
        } catch (NullPointerException e) {
        }
        return result;
    }

    
Compares this Boolean instance with another.

Parameters:
b the Boolean instance to be compared
Returns:
zero if this object represents the same boolean value as the argument; a positive value if this object represents true and the argument represents false; and a negative value if this object represents false and the argument represents true
Throws:
NullPointerException if the argument is null
Since:
1.5
See also:
Comparable
    public int compareTo(Boolean b) {
        return (b.value ==  ? 0 : ( ? 1 : -1));
    }
    private static boolean toBoolean(String name) {
        return ((name != null) && name.equalsIgnoreCase("true"));
    }
New to GrepCode? Check out our FAQ X