A basic start on java.
Questions/Tutorials for any programming language not covered in other sections.
6 posts
Page 1 of 1
Hello everyone. Duggypker here posting a Java programming tutorial... Well let's get started.
First we will start with loops.
While Loop
The first loop base we will discuss is the While loop basically this says While This statement is true do this.
Here's an EX:
BUT i does not have a value. So at the start of the script you must set an int.
int stands for integers intergers are basically any WHOLE number as in 0, 1, 2 etc. OR any negative WHOLE number as in: -1, -2, -3.
EX of a negative Int:
Now as you saw earlier in my while loop code. This code does not have an ending because i will always be less then 0 now to set an ending we can simply do this:
Now that we have a basic knowledge of the increase of int. and the while loop Let's move on. I'm going to stop here to show you a little bit more about Variables.
String Variable
Now a String is basically a letter or word formation in a script. whenever you want to place a sentence in a script it is referred to as a string.
Example of a string would be:
Arrays
Arrays are used to set multiple Variables in one variable. Mainly used to set multiple objects like trees or axes.
An Example:
Arrays can take a heavy load off your back when you have to write a lot of integers.
If and Else
Now a major part to your scripts/programs you will be making is the if and else statements. They declare if it happens, then to do this.
Example:
I'm sure you saw the
The For loop
A for loop makes a while loop alot shorter you will more then likely use these alot in your java programs but you will use your Public int loop() in your scripts. Let's get started
A for loop basic setup is like this:
Adding and About Breaks
Breaks in your script can change the way your script works completely but it can also work to be Very beneficial to you. Let's look at how the break is set u and I will explain to you what it does after we set it up.
Adding and About Continue
Now continue is basically the Same as breaks but the opposite. It continues on with the script.
Cases/Switches
Ah Cases. One of the newer ways to script but it is also the most unused formation. Case and switch are the same thing. First were going to have to set a String OR and int in our variables.
This concludes the basic Java tutorial. I will update this as needed, and later on get a little more advanced for you guys
Thanks for taking the time to read.
Please do post questions or if you spot a fault tell me! Thanks! <3
~Duggypker
First we will start with loops.
While Loop
The first loop base we will discuss is the While loop basically this says While This statement is true do this.
Here's an EX:
Code: Select all
Now this loop says If i is less then 5. then do the following action which is the log. What this does is in the screen it will say: "There are 2 Items" etc.while(i < 5) {
system.out.println("There are" + i + "Items");
}
}
BUT i does not have a value. So at the start of the script you must set an int.
Code: Select all
This sets i to equal 0int i = 0;
int stands for integers intergers are basically any WHOLE number as in 0, 1, 2 etc. OR any negative WHOLE number as in: -1, -2, -3.
EX of a negative Int:
Code: Select all
But for now we are going to go with 0.int i = -1;
Now as you saw earlier in my while loop code. This code does not have an ending because i will always be less then 0 now to set an ending we can simply do this:
Code: Select all
Now a lil advice on the addition code there. i = i + 1 you may think how do you set 0 = 1 ? Well what this means is setting everything that is on the Right of the = sign to the left side so in our int. i = 0 but with this i = i + 1 it will raise everytime by 1 which will make it greater then 5 eventually.while(i < 5) {
system.out.println("There are" + i + "Items");
i++; //or i = i + 1
}
}
}
Now that we have a basic knowledge of the increase of int. and the while loop Let's move on. I'm going to stop here to show you a little bit more about Variables.
String Variable
Now a String is basically a letter or word formation in a script. whenever you want to place a sentence in a script it is referred to as a string.
Example of a string would be:
Code: Select all
Strings can be used mainly for labeling and making titles in your scripts.String Ex = "This is an Example String Variable";
Arrays
Arrays are used to set multiple Variables in one variable. Mainly used to set multiple objects like trees or axes.
An Example:
Code: Select all
NOTE: These are just random Numbers to be used as an example.int [] myArray1 = {1223, 1225, 1227};
int [] myArray2 = {5553, 5554, 5555};
Arrays can take a heavy load off your back when you have to write a lot of integers.
If and Else
Now a major part to your scripts/programs you will be making is the if and else statements. They declare if it happens, then to do this.
Example:
Code: Select all
What this says is if i is equal to 0 then to display "i is equal to 0" but if it is not equal to 0 then it will display "i is Not equal to 0". if (i == 0) {
system.out.println("i is equal to 0");
} else {
system.out.println("i is Not equal to 0");
}
}
I'm sure you saw the
Code: Select all
In there what this does is NOT set the left variable (i) but it says is i equal to 0? or is it not equal to 0? This is also VERY important to know when scripting to know your = from your == remeber
if (i == 0) {
Code: Select all
While
= this sets the right information to mean the left
i = 0
Code: Select all
But now we I am going to get back into loops. Our next loop is called a for Loop.== just asks if it is equal
i == 0
The For loop
A for loop makes a while loop alot shorter you will more then likely use these alot in your java programs but you will use your Public int loop() in your scripts. Let's get started
A for loop basic setup is like this:
Code: Select all
Now this does the same thing but it is all stated in one line. But note that each event is separated by a ; this is VERY important. As the script will run errors if you do not do this.for(int i = 0; i < 5; i++;) {
system.out.println("There are" + i + "Items");
}
}
}
Adding and About Breaks
Breaks in your script can change the way your script works completely but it can also work to be Very beneficial to you. Let's look at how the break is set u and I will explain to you what it does after we set it up.
Code: Select all
Now what this does is when the number reaches 5 the loop will stop. It will not continue it will stop and move on outside of the brackets because the break; in there breaks the loop.for(int i = 0; i < 8; i++;) {
system.out.println("There are" + i + "Items");
if (i == 5) {
system.out.println("i is equal to 5!");
break;
}
}
}
Adding and About Continue
Now continue is basically the Same as breaks but the opposite. It continues on with the script.
Code: Select all
Once the code hits that continue in there it will skip log("Example Text"); and continue on. But once the script loops it will then re add the log("Example Text"); and continue on to its max.for(int i = 0; i < 8; i++;) {
log("There are" + i + "Items");
if (i == 5) {
log("i is equal to 5!");
continue;
}
log("Example Text");
}
}
Cases/Switches
Ah Cases. One of the newer ways to script but it is also the most unused formation. Case and switch are the same thing. First were going to have to set a String OR and int in our variables.
Code: Select all
Now we have our variables set. Now we can move on to the loop part of cases.
int status = 0;
OR
String status;
Code: Select all
the status = #; says what case it is going to set to. Basically what this code does is if i is less then 1 it will go to case 1 which will display a message and then add 1 to i and if i is greater it will display a message and then reset i to 0.switch(status) {
Case 0:
if (i < 1) {
status = 1;
} else if (i > 1) {
status = 2;
}
Case 1:
system.out.println("i is less then 1. Cool!");
i++;
Case 2:
system.out.println("i is greater then 1. Uh oh.");
int i = 0;
}
}
This concludes the basic Java tutorial. I will update this as needed, and later on get a little more advanced for you guys

Please do post questions or if you spot a fault tell me! Thanks! <3
~Duggypker
Hi DuggyPker
I am sure this will help many people out who know nothing about Java ( like me
)
Nice One
Chris
I am sure this will help many people out who know nothing about Java ( like me

Nice One
Chris
I am interested in learning Java and have no clue what software is needed.
On the Java website I get all these different links.
Please PM me with a download link or purchase page(Hope it's little-to-no cost
)
On the Java website I get all these different links.
Please PM me with a download link or purchase page(Hope it's little-to-no cost

The Java IDE is free - it is called NetBeans.
You can get it from netbeans.org.
You can get it from netbeans.org.
Thanks, but I actually looked into it and I'm now using 'Eclipse' to edit my java files.
I've been at it for about an hour now and things couldn't be better, I understand everything thanks to:
http://www.youtube.com/user/thenewboston
All of the tutorials for java are outstandingly thorough.
I've been at it for about an hour now and things couldn't be better, I understand everything thanks to:
http://www.youtube.com/user/thenewboston
All of the tutorials for java are outstandingly thorough.
6 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023