Author Topic: Helpfull Java Tutorials  (Read 229 times)

Keyani

  • Respect
  • Administrator
  • Newbie
  • ***
  • Posts: 48
  • Thanked +2/-0
  • Location: Belgium
    • View Profile
Re: Helpfull Java Tutorials
« on: July 07, 2011, 06:23:18 pm »
Things to know.

Final - can't be changed from the vaue it has been set with

Public - This can be used in any class

Private - Can only be used in the class declared

Static - Start will only be made once if that class has been made more than once

Packaging - Location of the class within the JVM[Java Virtual Machine]

Char[] - An array of character Objects

Modules - If you divide with a int and the int answer has a remander the modules[%] will give you the remainder

Pre-Increment - used by [++varible] or [--Variable] this will take the variable before used and add +1 to the it or -1

Post-Increment - used by [variable++] or [Variable--] this will take it and print the variable number then anything after will be +1 or -1

assignment operator - this is used to add to a int for example [monkey += 5;] this will add 4 to monkey [assignment operator] you can also do [-, *, /]

if statment - this is basicly a test for a variable [int/boolean] you can use if(youvariable ==[your check if its exactly the same] 2)] you can also use [!=(if not equals), <(less then varibale), >(greater then variable), <=(is it less then or equal to variable), >=(is it greater or equal to variable)] if it is it does one thing if it isnt it does another thing as specified by the body, if the variable isnt == to wat u want it to use } else { and it will tell java to do something different it can only do one at a time.

double amperstan[&&] - this is used for an if statment so if you want to do two ifs in one if you would use this for example [if(varibale == 10 && varibale == 10) {] then make it do something you can still use an else if

or[||] - used in a "if" statment [if(varible == 40 ||[or] varible == 50) {] only one has to be true and it does something if there both false you cant do what you want by using an } else { but one of them always has to be true or they both can be true

switch statment - used by [switch(varible) {] so what you would do is call a "case" like [case (case number) then a colan: ] so now basicly the case is an "if" so case = if so [case 4:] then make it do some code but you want to terminate what you are doing if it is that case so you would use a break [break;(semi colan)] this is used instead of so many if statments so basiclly [case 4: sendMessage("hi"); break;] so what that does is if the thing your switching is equal to 4 you would send the message "hi" so if your variable is equal to any case's you call use a default like [default:] then after that you want it to print the case not declared [System.out.println("didnt handle case "+variable);] then after you make the message after the default add a [break;]

While loop - this helps save time used by [while(varibale) {] this will execute this code after it in the brackets [ } { ] as long as you set it to so example [while(variable <[less then] 10) {] tell it to print "hi" but you want it to stop because it will go on so you would do [variable++;](post intcretment) wat it does is it tells it do 10 - 1 then stop
« Last Edit: July 07, 2011, 06:28:21 pm by Keyani »