Jump to content

Recommended Posts

Posted
 

 

6wItAcC.png

 

 

Java Data and Variables

 

There are 8 primitive data types. he 8 primitive data types are numeric types. The names of the eight primitive data types are:

 

byte short int long float double char boolean

There are both integer and floating point primitive types. Integer types have no fractional part; floating point types have a fractional part. On paper, integers have no decimal point, and floating point types do. But in main memory, there are no decimal points: even floating point values are represented with bit patterns. There is a fundamental difference between the method used to represent integers and the method used to represent floating point numbers. 

 

 

7wxrbU8.png

 

 


Examples

 

int yr = 2006;

double rats = 8912 ;

 

         For each primitive type, there is a corresponding wrapper class. A wrapper class can be used to convert a primitive data value into an object, and some type of objects into primitive data. The table shows primitive types and their wrapper classes:

 

 

qtZkbI7.png

 

 

Variables only exist within the structure in which they are defined. For example, if a variable is created within a method, it cannot be accessed outside the method. In addition, a different method can create a variable of the same name which will not conflict with the other variable. A java variable can be thought of as a little box made up of one or more bytes that can hold a value of a particular data type:

 

Syntax: variabletype variablename = data;

 

Source Code ( demonstrating declaration of a variable )



class example
{
  public static void main ( String[] args )
  {
    long x = 123;    //a declaration of a variable named x with a datatype of long


    System.out.println("The variable x has: " + x );
  }
}



Source Code



public class MaxDemo {
     public static void main(String args[]) {
     //integers
          byte largestByte = Byte.MAX_VALUE;
          short largestShort = Short.MAX_VALUE;
          int largestInteger = Integer.MAX_VALUE;
          long largestLong = Long.MAX_VALUE;




         //real numbers
         float largestFloat = Float.MAX_VALUE;
         double largestDouble = Double.MAX_VALUE;



       //other primitive types
        char aChar = 'S';
        boolean aBoolean = true;



        //Display them all.
        System.out.println("largest byte value is " + largestByte + ".");
        System.out.println("largest short value is " + largestShort + ".");
        System.out.println("largest integer value is " + largestInteger + ".");
        System.out.println("largest long value is " + largestLong + ".");
        System.out.println("largest float value is " + largestFloat + ".");
        System.out.println("largest double value is " + largestDouble + ".");
   }
}



 


Sample Run

 

The largest byte value is 127.

The largest short value is 32767.

The largest integer value is 2147483647.

The largest long value is 9223372036854775807.

The largest float value is 3.4028235E38.

The largest double value is 1.7976931348623157E308.

 

 

Dear Baggos mentioned on my previous post that a guide related to variables would be nice so here it is :)

Thanks.

 

  • Upvote 1
Posted (edited)

vampir only said than

if (condition)
{
  _var = 1;
}
else
{
   _var = 2;
}

could be replaced by

if (condition)
   _var = 1;
else
   _var = 2;

and even more sexier by

_var = (condition) ? 1 : 2;
Edited by Tryskell
Posted

 

vampir only said than

if (condition)
{
  _var = 1;
}
else
{
   _var = 2;
}

could be replaced by

if (condition)
   _var = 1;
else
   _var = 2;

and even more sexier by

_var = (condition) ? 1 : 2;

 

I like the way you think XD

Posted (edited)

I like the way you think XD

 

See a real case scenario of "if/else if" shortcuted here (fighter / mage buffs) : 

 

http://www.maxcheaters.com/topic/211475-newbies-helper-npc-acis/?p=2611476

 

As you can see, that idiom

(check) ? trueStatement : falseStatement

 can reduce redundant code for the same output.

Edited by Tryskell
Posted (edited)

See a real case scenario of "if/else if" shortcuted here (fighter / mage buffs) : 

 

http://www.maxcheaters.com/topic/211475-newbies-helper-npc-acis/?p=2611476

 

As you can see, that idiom

(check) ? trueStatement : falseStatement

 can reduce redundant code for the same output.

 

Yea i have alot to improve thanks for showing me the way :) thats a way to shorten the code also make the code easier to read and understand.

Edited by Sawadee
Posted

http://www.freejavaguide.com/java_variables.htm

 

Im dying laughing over here.

 

Nice u diged internet to find what i shared, but i didnt even know that this guide was posted on somewhere as i mentioned before i just copy and paste this guide from a pdf file that i found in my pc thats simple theres no need to tryhard :) The difference between me and you, you just break balls and do actually nothing for this community and i try to help with anythin/whatever i have/can.

Posted

Nice u diged internet to find what i shared, but i didnt even know that this guide was posted on somewhere as i mentioned before i just copy and paste this guide from a pdf file that i found in my pc thats simple theres no need to tryhard :) The difference between me and you, you just break balls and do actually nothing for this community and i try to help with anythin/whatever i have/can.

Exquse me but you just got pwned. http://www.maxcheaters.com/topic/203773-free-help-small-code-fixes-request-small-codes/

Also continue this "speech". Next time you're reported for share guides without credits and bad language toward members. 

Posted (edited)

Exquse me but you just got pwned. http://www.maxcheaters.com/topic/203773-free-help-small-code-fixes-request-small-codes/

Also continue this "speech". Next time you're reported for share guides without credits and bad language toward members. 

 

Bad language toward members? u should be banned for trolling and spammin on other people guides all the time i already reported you 3 times and im goin to do it again lets see who will be banned. stop acting like a lawyer u are just a simple member here mind your own business if anything is wrong with me ill be punished if anything is wrong with you, you will be punished just for gods sake stop posting on other topics and judge the people like your are their boss.

Edited by Sawadee
Posted

Bad language toward members? u should be banned for trolling and spammin on other people guides all the time i already reported you 3 times and im goin to do it again lets see who will be banned. stop acting like a lawyer u are just a simple member here mind your own business if anything is wrong with me ill be punished if anything is wrong with you, you will be punished just for gods sake stop posting on other topics and judge the people like your are their boss.

You can't report someone who just tell you that you sharing tutorials without adding credits and going against rules. What you gonna report me for? 

"This user flame my topic and force me to put credits on stolen tutorials?" 

 

I don't flame, i just say you go against rules and leech other's tutorials. You dont want understand it? Report me as many times you want but read rules and we see who is wrong and who is right.

Posted

You can't report someone who just tell you that you sharing tutorials without adding credits and going against rules. What you gonna report me for? 

"This user flame my topic and force me to put credits on stolen tutorials?" 

 

I don't flame, i just say you go against rules and leech other's tutorials. You dont want understand it? Report me as many times you want but read rules and we see who is wrong and who is right.

 

I didnt even read anything ill be honest, lets see what will be the action of admin/moderators about us.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...