Author Topic: Java for noobs #1: Primitive datatypes (Variables)  (Read 165 times)

Offline Arno

  • Java Tutor
  • Newbie
  • *****
  • Posts: 12
  • Reputation: +6/-1
  • Belgian's Finest
  • Location: Belgium #1
    • View Profile
Java for noobs #1: Primitive datatypes (Variables)
« on: April 12, 2013, 05:52:39 pm »
Let's start this little series off with a tutorial on variables. (More to the point the primitives)

Variables are types of data that are as the name suggests "variant". More then frequently this means they can change, can be assigned a certain data type, and can be directed how to be used in our java program.

We can seperate two different sorts of variables. We call those primitives, and OO-variables.

The difference is that a primitive variable is already dished and ready for you to use, they are your basic tools that Java already provides you, in contrast with OO-vars, which are required to be made from scratch by yourself.

The most common and easiest primitive variable which practicly every beginner starts with is the integer.

The easiest way to explain an integer to you, is that an integer is interpreted as a natural number (that means no decimal numbers). And between -2147m and +2147M. (On runescape the cash stacks are made off off integers, hence why that is a max cash pile).

Integers get declared in java as the statement int. For example if we want to declare our age in the integer age, we would do the following:

Code: [Select]
int age = 19;
The integer int now represents the number 19.

In terms of mathematics, it is a possibility to use operators to assign a dynamic state of integer value.
For example:

Code: [Select]
int age = 10;
int age1 = 17;
int age2 = age1 - age

age2 then represents the value of 7. But will change in concurrence by changing any of age or age1's values.

Next, we have the primitive called a boolean. This can be resembled with a switch that can either be turned on or off. When defining no value to a boolean, default syntax will be off, or in this case called false. When the switch is on, we call that true.

We can for example (in the concept of an RSPS), do the following:

Code: [Select]
private static boolean hasStarter = false;
if (hasStarter != true)
givestarter();
else
return;

Note: the != operator means is not equal to.

Next off we have the Strings. A string is a collection of letters and numbers, as can be read upon from the StringBuilder API, appending collections towards a seperate container of data.

We can define Strings the following way:

Code: [Select]
public String welcomeMsg = "Welcome to Sayberscape!");

private static void main(String args[]) {
System.out.println(welcomeMsg);
}

WORKING ON THIS STILL
« Last Edit: April 15, 2013, 04:23:05 pm by Arno »

Share on Facebook Share on Twitter


Offline Hexicone

  • Member
  • *
  • Posts: 27
  • Reputation: +1/-3
  • Hi :3
  • Location: Bariloche,Argentina Bitches
    • View Profile
Me no speaking english XD

hey you got skype i got a problem with my java i need to fix sooon.

Offline regkiller

  • Donator
  • Member
  • *
  • Posts: 46
  • Reputation: +2/-2
  • xxx REGKILLER xxx
  • Location: texas
    • View Profile
this stuff is confusing :\


Offline Godsword

  • Forums Developer
  • Member
  • *
  • Posts: 40
  • Reputation: +8/-0
  • #YoloMcSwagginIt
    • View Profile
Arno's gonna be teaching java and making tuts.

This is as simple as it gets, he'll be making more in the future. :)

Offline Unknown

  • Forums Developer
  • Newbie
  • *
  • Posts: 14
  • Reputation: +101/-4
  • I'ma go getta.
  • Location: raycilla.
    • View Profile
Most people don't understand Java Scripting. It's take time to learn it. I know a lot and i still learn more. There no being perfect. Unless your Arno :P

Offline Arno

  • Java Tutor
  • Newbie
  • *****
  • Posts: 12
  • Reputation: +6/-1
  • Belgian's Finest
  • Location: Belgium #1
    • View Profile
Updated a bit, been busy lately

Offline White King

  • Ex-Staff
  • Member
  • *****
  • Posts: 39
  • Reputation: +2/-4
    • View Profile
By the time we get more members we're probably gonna have a web client if that's what next

Offline Mr Jake

  • Newbie
  • *
  • Posts: 4
  • Reputation: +1/-0
    • View Profile
My boy snapped