0% found this document useful (0 votes)
13 views

Introduction To Data Types

Data Types
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Introduction To Data Types

Data Types
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Data Types

-defines the proper use of an identifier or an expression.


-what type of data can be stored in an identifier or written in an expression.
-which types of operations can be performed on an identifier or expression.
Example:
Legal vs. Illegal Expression
12 + 2 //legal numeric expression
12 + Mike //illegal numeric expression
hello, + world //legal string expression
Salary * taxRate // legal arithmetic expression
//can be multiplied together which are defined as numeric value
Data Types

Numeric - 1000, 3.14159


Strings Hello, World, Mike
Characters a, t
Booleans true/false

Numeric Data Types


Integral types
-

int stores numbers in range of -2,147,483,648 to 2,147,483,648


Long stores numbers in range of -9,223,372,036,854,775,808 to
9,223,372,036,854,775,808

Float, double floating point types


Float 127 digits after decimal point
Double 1023 digits after decimal

Byte - -128 to 127


Short - -32768 to 32767
Char alphabetic characters stored as numeric value (ASCII)

Variables Defined and Naming Rules


A name for a memory location
Always has a type
Data stored in a variable is called value.
Variable name must start with a letter.
May contain letters, numbers and the underscore character

Example:

Good vs. Bad Variable Names


//Good
salary;
name3;
first_name;
lastName; //camel notation or camel casing
//Bad
3name;
first name;
-

No real limit to length


Variables should have short, meaningful names
Variables should begin with lowercase letters

String and Boolean Data Types


- String 0 or more characters surrounded by double quotes hello, world
- String is a class, not a built-in type
- Large collection of methods for manipulating strings
- Strings can be combined with + which is called concatenation
- Empty string , is legal String object
Boolean true/false values
-Built-in data type
Comparisons salary >10000
Repetition white balance <100
Declaring and Initializing Variables
To declare a variable is as follows,
<data type> <name> [=initial value]
Example:
int grade;
int grade = 97; //with initialized value
double cost;
double cost = 0.0;
boolean result;
String first_name;
String firstName;

Outputting Variable
Heres a sample program
public class OutputVariable {

public static void main (String [] args) {


int value = 10;
char x;
x=A;
System.out.println( value);
System.out.println(The value of x = + x);
}
}

You might also like