Presentation is loading. Please wait.

Presentation is loading. Please wait.

A variable is a storage location for some type of value. days 102 taxrate 7.75 int days = 102; double taxrate = 7.75; char grade = ‘A’; boolean done.

Similar presentations


Presentation on theme: "A variable is a storage location for some type of value. days 102 taxrate 7.75 int days = 102; double taxrate = 7.75; char grade = ‘A’; boolean done."— Presentation transcript:

1

2

3 A variable is a storage location for some type of value. days 102 taxrate 7.75 int days = 102; double taxrate = 7.75; char grade = ‘A’; boolean done = true;

4 What is a data type?

5 A data type describes what type of data the variable will hold. There are 8 basic primitive data types What is a data type?

6 byte short int long float double char boolean int num = 9; double total = 3.4;

7 TYPEHoldsRANGE intintegers (32 bit) -2 billion to 2 billion int num = 3; doubledecimals/ floating number (64 bits) -1.7E+308 to 1.7E+308 double num1 = 7.4; boolean {true, false}Holds two values: {true, false} boolean done = false; char One character ‘A’

8 Declarations A declaration is the introduction of a new name in a program. All variables must declared in advance General forms to declare variable. Data type and variable name  int num;  double digit;  boolean done;

9 How do you name variables when defining them?

10 When naming a variable follow these rules and conventions: 1.The variable name must contain NO spaces. 2.The variable name must begin with a lower case letter. 3.If you run two words together, then the first letter of the second word should begin with a capital letter. 4.The remainder of the variable name contains only letters and digits. Can use _ $ as symbols and can start with _ but not recommended. IDENTIFIER variables are identifers

11 Below are some examples of valid variable names: number sum32 testAverage areaOfTrapezoid and below are some examples of invalid variable names: 2ndValue test Average question#2

12 Java is case sensitive. Brandon does not equal brandon. Brandon != brandon Java is case sensitive. (Yes, it’s so important that I said it twice!)

13 Keywords are reserved words that the language uses for a specific purpose. You cannot use keywordsas identifier names. abstractcontinuefornewswitch assert *** default goto * packagesynchronized booleandoifprivatethis breakdoubleimplementsprotectedthrow byteelseimportpublicthrows case enum **** instanceofreturntransient catchextendsintshorttry charfinalinterfacestaticvoid classfinallylong strictfp ** volatile const * floatnativesuperwhile

14

15 assignment operator (=). Called initializing the variable. int num = 1000; // This line declares num as an int variable which holds value "1000". boolean bol = true; // This line declares bol as boolean variable which is set to the value "true". boolean result = true; char capitalC = 'C'; byte b = 100; short s = 10000; int i = 100000; Statements: Statements in Java end with a semicolon ;

16 OOP: Basic Parts of Java Primitive Data Types, Example // create some integers int x, int y; // declared but not initialized x = 1234; y = 3; //initialized and ready to use double v = 3.14, w = 5.5; //declare and Initialize at same time


Download ppt "A variable is a storage location for some type of value. days 102 taxrate 7.75 int days = 102; double taxrate = 7.75; char grade = ‘A’; boolean done."

Similar presentations


Ads by Google