Thread: Help understanding something simple

Results 1 to 6 of 6
  1. #1 Help understanding something simple 
    Owner Of SeenScape

    Join Date
    Nov 2012
    Posts
    132
    Thanks given
    4
    Thanks received
    3
    Rep Power
    10
    What does the following in red mean and do?

    Code:
    public boolean Test123() {
            if (absX > 1337 && absX < 1337 && absY > 1337 && absY < 1337){
                return true;
            }
            return false;
        }
    Edit: Ive started coding again in a long time sorry.
    Being really good at C++ is like being really good at using rocks to sharpen sticks.
    Reply With Quote  
     

  2. #2  
    Banned Help understanding something simple Market Banned


    Join Date
    Jan 2011
    Age
    26
    Posts
    3,112
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    a boolean is a datatype which can only return two values. True and false. Be sure that all your methods start with a lowercase letter, so It would be "test123()". Then you can do:


    Code:
    if(test123() == true) {
         doSomething();
    }
    or (same thing)

    Code:
    if(test123()) {
         doSomething();
    }

    and

    Code:
    if(test123() == false) {
         doSomething();
    }
    or (same thing)

    Code:
    if(!test123()) {
         doSomething();
    }
    For more on datatypes look here: Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Reply With Quote  
     

  3. #3  
    Registered Member
    TheChosenOne's Avatar
    Join Date
    Jan 2013
    Posts
    967
    Thanks given
    47
    Thanks received
    161
    Rep Power
    366
    As lare96 already explained, true and false are booleans. The "boolean" before "Test123()" tells that the method will return a boolean value (to the method calling that one). It is in fact compulsory (except when you throw an Exception or stop the program) to return a boolean value, which is what "return true;" and "return false;" do.
    Reply With Quote  
     

  4. #4  
    Owner Of SeenScape

    Join Date
    Nov 2012
    Posts
    132
    Thanks given
    4
    Thanks received
    3
    Rep Power
    10
    if(!test123()) {
    doSomething();
    }
    One last thing what does the highlighted mean?
    Being really good at C++ is like being really good at using rocks to sharpen sticks.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Feb 2012
    Posts
    7
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by -Java- View Post
    One last thing what does the highlighted mean?
    an if-statement will by default test whether or not something is true.
    That's why if you just do

    Code:
    if(test123()) {
        doSomething();
    }
    it will test if test123() returns true.

    To answer your question, the "!" infront of a boolean value will say it's NOT what it is. So !true == false and !false == true
    You can read it as; NOT true == false and NOT false = true

    Hope my answer was clear for you.
    Reply With Quote  
     

  6. #6  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Since your condition is one line and there is no need for ternary operation, a long with what Lare96 said, this is another option.
    Code:
    public boolean isInSpecificArea() {
           return absX > 1337 && absX < 1337 && absY > 1337 && absY < 1337;
    }
    What this essentially means is that when the boolean isInSpecificArea() is checked then it will check the condition, if it's true that you're within those boundaries it will get executed as true, otherwise it remains false.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Okay Am I Understanding Right?
    By Cosmic X in forum Application Development
    Replies: 4
    Last Post: 07-11-2011, 04:53 AM
  2. understanding the eventmanager
    By silabgarza in forum Help
    Replies: 0
    Last Post: 03-02-2009, 02:05 AM
  3. Understanding GFX
    By Infinityyy in forum Tutorials
    Replies: 4
    Last Post: 01-26-2009, 08:41 PM
  4. Understanding XML
    By Vastiko in forum Tutorials
    Replies: 26
    Last Post: 01-17-2009, 09:51 PM
  5. Understanding mapdata.
    By defyboy in forum Informative Threads
    Replies: 17
    Last Post: 08-30-2008, 12:57 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
  •