Results 1 to 4 of 4
  1. #1
    ravian is offline Senior Member
    Join Date
    Nov 2007
    Posts
    115
    Rep Power
    0

    Default boolean variables

    I am confused about boolean variables. What is the use of boolean variables? We can use short variable (as a flag) for the required purpose then what edge does boolean variables gives us?

    Java Code:
    			if(var == 1)
    				System.out.println("true");
    			else
    				System.out.println("false");

  2. #2
    staykovmarin is offline Senior Member
    Join Date
    Nov 2007
    Location
    Newport, WA
    Posts
    141
    Rep Power
    0

    Default

    Java Code:
    var == 1
    Right now you are using a boolean operator (the double = sign). The result of the following equation is true of false. '
    The use is this (in pseudocode):
    Java Code:
    boolean isAuthenticated = false;
    
    if (passWordIsCorrect) isAuthenticated = true;
    else isAuthenticated = false;
    
    if (isAuthenticated) allowToSeeSecretData;
    note: Pseudo code is English, written in a more code like form, just to make sense. That of course will not compile.

  3. #3
    ravian is offline Senior Member
    Join Date
    Nov 2007
    Posts
    115
    Rep Power
    0

    Default

    So its slower in that case. If I use boolean variable, it will be faster... Is this what you mean?

  4. #4
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    Quote Originally Posted by ravian View Post
    So its slower in that case. If I use boolean variable, it will be faster... Is this what you mean?
    It's more of a convenience to further abstraction, fundamental to OOP.

Similar Threads

  1. Replies: 6
    Last Post: 10-08-2008, 08:09 AM
  2. Replies: 4
    Last Post: 04-15-2008, 01:04 PM
  3. boolean to string
    By otoro_java in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 05:31 AM
  4. Variables
    By mew in forum New To Java
    Replies: 3
    Last Post: 12-11-2007, 12:44 PM
  5. Boolean Expression
    By ritwik07 in forum New To Java
    Replies: 3
    Last Post: 07-11-2007, 04:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •