MC Modding
Please register and join the community!


Join the forum, it's quick and easy

MC Modding
Please register and join the community!
MC Modding
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Java basic knowledge to get you started

5 posters

Go down

Java basic knowledge to get you started Empty Java basic knowledge to get you started

Post by TheOnly1ne Tue Oct 25, 2011 3:43 am

Integers:

in code they are called int
notice they turn purple because they are a keyword. Ca store a value of a method, object, or a number with no decimal.
EX:
Code:
int i = 1;


Boolean:
called boolean in code. can store a value of true or false.
useful for certain things.
EX:
Code:
boolean flag = false;

String:
called String in code. Don't turn purple because they are a different kind of a value. They store letters. Used for outputting messages.
EX:
Code:
String s = "I am so sexy!";

Float:
used as a decimal number. after their value put an F
EX:
Code:
float f = 10F;

Now on to coding.
To start your first class do this
Code:
class sexy {
        public static void main(String args[]) {
}         
}
That says that whatever you put in there is what Java will do first.
Code:
class sexy {public static void main(String args[]) {
          String s = "I am sexy!";
          System.out.printf("%s \n", s);
      }
}
what this says is the String s which is "I am so sexy" will print out. %s means a string and then \n means new line. the s after the "" is the string you want to print out(in order).
That's all for now.


Last edited by TheOnly1ne on Tue Oct 25, 2011 3:12 pm; edited 3 times in total

TheOnly1ne
Member

Posts : 10
Join date : 2011-10-20
Location : I'm in your window.

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by breakyorself Tue Oct 25, 2011 5:19 am

Might want to tell them how to start a class Neutral
Code:
class apples{
public static void main(String[] args){
System.out.println("Hello World!");
}
}
breakyorself
breakyorself
Member

Posts : 60
Join date : 2011-10-19

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by Static_boy123 Tue Oct 25, 2011 5:23 am

Good job so far. I just recommend going a bit more in depth; For Example explain the limits of an integer. Here is something you might use:
An integer is only 0-255 this is because it is a one byte binary number. If you know binary then you know a one byte(8 bit) number is at most 256, I won't go into detail about that, but that is an 1 byte number. In the span 0-255 we include 256 numbers, so it makes sense.


For those of you that don't know binary I will put up a tutorial later, but in simplest form it is the only language computers can read. All cade is broken down into it when executed.
Static_boy123
Static_boy123
Helper

Posts : 32
Join date : 2011-10-19
Age : 24
Location : Eclipse Indigo

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by the undecided t Tue Oct 25, 2011 6:09 am

ok say im using a while loop... and at the end of said loop i want it to change the value of a boolean from false to true or the other way around... how would i go about doing that
the undecided t
the undecided t
Helper

Posts : 45
Join date : 2011-10-20
Age : 27

http://www.blacklistgaming.org/forums

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by groxmapper Tue Oct 25, 2011 1:45 pm

Static_boy123 wrote:Good job so far. I just recommend going a bit more in depth; For Example explain the limits of an integer. Here is something you might use:
An integer is only 0-255 this is because it is a one byte binary number. If you know binary then you know a one byte(8 bit) number is at most 256, I won't go into detail about that, but that is an 1 byte number. In the span 0-255 we include 256 numbers, so it makes sense.


For those of you that don't know binary I will put up a tutorial later, but in simplest form it is the only language computers can read. All cade is broken down into it when executed.

Yet i've set integers to numbers well into the thousands with no repurcussions...?
groxmapper
groxmapper
Member

Posts : 27
Join date : 2011-10-24

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by Static_boy123 Tue Oct 25, 2011 2:31 pm

groxmapper wrote:
Static_boy123 wrote:Good job so far. I just recommend going a bit more in depth; For Example explain the limits of an integer. Here is something you might use:
An integer is only 0-255 this is because it is a one byte binary number. If you know binary then you know a one byte(8 bit) number is at most 256, I won't go into detail about that, but that is an 1 byte number. In the span 0-255 we include 256 numbers, so it makes sense.


For those of you that don't know binary I will put up a tutorial later, but in simplest form it is the only language computers can read. All cade is broken down into it when executed.

Yet i've set integers to numbers well into the thousands with no repurcussions...?
Nevermind me I am just thinking in two languages at once.
Static_boy123
Static_boy123
Helper

Posts : 32
Join date : 2011-10-19
Age : 24
Location : Eclipse Indigo

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by TheOnly1ne Tue Oct 25, 2011 3:06 pm

the undecided t wrote:ok say im using a while loop... and at the end of said loop i want it to change the value of a boolean from false to true or the other way around... how would i go about doing that
You would put the boolean into the while loop like this
Code:

int i = 0;
while(i < 10) {
        boolean flag = true;
        i++;
}

TheOnly1ne
Member

Posts : 10
Join date : 2011-10-20
Location : I'm in your window.

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by groxmapper Tue Oct 25, 2011 9:52 pm

the undecided t wrote:ok say im using a while loop... and at the end of said loop i want it to change the value of a boolean from false to true or the other way around... how would i go about doing that

Code:
private int checkWhenFinished = 10;
private boolean isFinished = false;

for(int a = 0; a < 10; a++)
{
//do w/e is needed in the loop
checkWhenFinished--;
}

if(checkWhenFinished == 0)
{
    isFinished = true;
}

It's important to keep changing the boolean changing OUT of the loop because then it would return true the first time the loop goes through. I think he wants it to return when the loop has finished, which is what this would do.
groxmapper
groxmapper
Member

Posts : 27
Join date : 2011-10-24

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by TheOnly1ne Tue Oct 25, 2011 10:07 pm

groxmapper wrote:
the undecided t wrote:ok say im using a while loop... and at the end of said loop i want it to change the value of a boolean from false to true or the other way around... how would i go about doing that

Code:
private int checkWhenFinished = 10;
private boolean isFinished = false;

for(int a = 0; a < 10; a++)
{
//do w/e is needed in the loop
checkWhenFinished--;
}

if(checkWhenFinished == 0)
{
    isFinished = true;
}

It's important to keep changing the boolean changing OUT of the loop because then it would return true the first time the loop goes through. I think he wants it to return when the loop has finished, which is what this would do.
Yeah but what he means is to make it only while it is true so maybe more like this:
Code:
boolean isFinished = false;
int i = 0;
while(i < 10) {
        i++;
}
if(i == 10) {
        isFinished = true;
}else{
        ifFinished = false;
}

TheOnly1ne
Member

Posts : 10
Join date : 2011-10-20
Location : I'm in your window.

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by the undecided t Wed Oct 26, 2011 3:33 am

i mean... look at my code on the on/off light block and you will see what i mean
the undecided t
the undecided t
Helper

Posts : 45
Join date : 2011-10-20
Age : 27

http://www.blacklistgaming.org/forums

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by TheOnly1ne Wed Oct 26, 2011 3:39 am

the undecided t wrote:i mean... look at my code on the on/off light block and you will see what i mean
where?

TheOnly1ne
Member

Posts : 10
Join date : 2011-10-20
Location : I'm in your window.

Back to top Go down

Java basic knowledge to get you started Empty Re: Java basic knowledge to get you started

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum