Jump to content
TacoManStan

[Tutorial] Learning Java with TRiBot #3 - Primitive Basics

Recommended Posts

Leaning Java with TRiBot - Primitive Basics

Click Here for a List of All Tutorials

If anyone would like to provide any advice or feedback on the tutorial, please message me on Skype. I want to keep the comments to questions as much as I possibly can, so people can learn not only by reading the tutorial, but also reading the rest of the thread. Thank you!

Introduction

As always, be sure that you read every line of this tutorial carefully. If you don't, you are going to find yourself very lost. When I tell you to stop and think about something, I'd definitely recommend that you listen!

By now you should have read, and hopefully loosely understand, my 2nd tutorial. If you haven't, I would highly recommend doing so before reading this.

What is a Primitive?

49KkxZ1.jpg

Recall from my previous tutorial that Java is comprised of objects. Objects are created by classes, and controlled by methods. This is useful, of course, but what about much simpler ideas? What if you want to know something that is too simple to be an object, such as the height of a person? That is what primitives are for.

Types of Primitives

There are multiple types of primitives, but I am going to be focusing on only several of them in this tutorial. The rest are much less commonly used, and I will have a tutorial on them in the future. For now, let's just focus on the following.

Int

As you have probably guessed, int is short for "integer".

An integer is a whole number. An integer can be positive, negative, or zero, but because it is a whole number, cannot ever be a fraction or decimal.

Integers are used when a decimal or fraction doesn't make sense. One of the most common ways to use an integer is when you are counting something. If you are counting something, you usually want to count in whole numbers. For example, how many trees are in this picture?

57yhW5C.png

The answer is 3. There are 3 trees.

Now, I know what some of you might be thinking; "what if there is a half of a tree?". The answer to that is as follows: Don't think that way. Take the following picture for example.

HQEXlHJ.jpg

While it's funny to say that there are 2.5 men here (the TV show reference which makes it even funnier), there are in fact 3 people in this picture. If you tell the computer that there are 2.5 people, the computer won't understand your humor, and will get incredibly confused and you will get a lot of nasty errors.

Another Example: If you are still confused as to why you might need a value that can't be a fraction of decimal, look at the top of your browser window. How many tabs are open? 1? 2? 10? I can bet you that the number of tabs open in your browser is an integer!

Aaaand Another Example: Sometimes integers aren't necessary, but they just make life easier. Take a look at your various skill XP values in RuneScape. Imagine how confusing it would be if you could have 32,392.382394 XP in a skill.

Double

Remember when I said that ints can't be decimals or fractions? As I'm sure you guessed, doubles can be!

Doubles represent pretty much any number you can think of. If whatever you are trying to describe should be able to be a fraction or decimal, you should use a double.

Here are some examples of doubles: 3.4, 1.0, 1932.2, 2.2912992, -2.1, -3291, 0.0.

While integers are usually used to count things, doubles are most commonly used to define properties of things. These would be things like weight, height, the pull of gravity, etc.

Boolean

A boolean has one of two values: true or false.

Booleans are sometimes the hardest primitive for people to understand the usefulness of. To help clarify things, I present to you the following educational image.

9R4zHCd.jpg

When you select someone as being "hot" or as being "not", you are selecting a boolean. Is this person hot? True or false? When you select your answer, the program sets a boolean to "true" or "false" depending on what you select.

Another Example: Open up pretty much any script on TRiBot that has a GUI. Chances are that there is at least one check box on that GUI. When you press "Start" on that GUI, the script will look at all of the check boxes and see if they are checked or not. How is this done? As you probably guessed, with a boolean!

Char

You won't be using characters very often (even for advanced programs it isn't very common), but because of their uniqueness, I will mention them briefly.

Char stands for character. Characters are exactly that: characters. Anything on your keyboard is a character.

Here are some examples: 'A', 'B', 'C', 'G', 'a', 'b', ' ', '%', '~', etc.

Conclusion

This is the end of the third installment of my Learning Java with TRiBot tutorial series. This session was all about learning the basics of what primitives are in Java.

In the next tutorial, we will be diving right back into program structure!

As I mentioned in my previous tutorials, if people seem interested in this concept, I'll probably make videos to go along with my written tutorials as well!

Also, if there is anything listed above that you would like a graphical representation of so you can visualize it better, please let me know and I will do my best to include it.

 


If there is anything you don't understand, please let me know! If you didn't understand it, chances are someone else didn't either.

Click Here For Tutorial #4!

Edited by TacoManStan
  • Like 16

Share this post


Link to post
Share on other sites

@TacoManStan

 

Thank you for this! Found this more useful that any guide iv searched for on the web. Will you be basing this whole concept around tribot.. or just learning java in general?

The goal is to learn java through TRiBot (and RuneScape), so the guides will almost always be someone related to one of the two or both. That being said, these beginning tutorials are just going over Java fundamentals, so there won't be any TRiBot scripting, just Runescape references.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Our picks

    • This release will:

      Add support for using custom F key bindings to switch between game tabs (Thanks @erickho123)


      Fix tab opening for "Skills" and "Kourend Tasks" (Thanks @erickho123)



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Like
      • 30 replies
    • This release will:

      Fix an issue where breaks would stop firing


      Fix Combat#getWildernessLevel, use dynamic search for text and cache ID for later calls


      Fix an NPE in the Combat API


      Fix Mouse#leaveGame bug where the mouse wouldn't actually leave the game screen
        • Like
      • 21 replies
    • This release will:

      Add LG support for Runelite


      Fix NPCChat issues


      Fix a bug where the camera angle setter would just hold down a key for 5 seconds (the timeout)


      Slightly adjust the rotation via keys to be more accurate


      Add the ability for asynchronous camera movement via keys


      Make Camera rotation via mouse more fluid, with more antiban, and work much better in resizable mode


      Add a "Camera#setCamera" method, allowing the rotation and angle to be set in parallel


      Increase the likelihood of using the mouse for camera movements


      Add support for adjusting the camera to positionable entities (Positionable#adjustCameraTo)



      Upcoming updates:

      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Thanks
        • Like
      • 59 replies
    • This update will:

      Allow for clicking through the chat box when possible (Thanks @Todd)


      Fix Combat#selectIndex (Thanks @Encoded)


      Ensure worlds stay sorted and added a check to avoid misclicks in the in-game world hopper (Thanks @erickho123)


      Fix out-dated Options API interface indices (Thanks @Todd)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Like
      • 12 replies
    • This release will:

      Fix login bot after today's game update (Thanks @JoeDezzy1)


      Fix latest in-game world hopping issues (Thanks @erickho123)


      Compact Settings UI and set location relative to TRiBot (Thanks @JoeDezzy1)


      Fix an older implementation of GrandExchange#getWindowState (Thanks @JoeDezzy1)


      Improve the preformance of NPCChat by only searching in certain interface parents (Thanks @JoeDezzy1)



      Upcoming updates:

      Break handler bug fix


      Improved CLI support


      LG support for RuneLite


      Much more



      Note: If you are using LG, please restart both the RS client and TRiBot
        • Thanks
        • Like
      • 16 replies
  • Recently Browsing   0 members

    No registered users viewing this page.

×