-
Unit I: Introduction to OOP and JavaFundamentals
Object Oriented Programming - Abstraction – objects andclasses -
Encapsulation- Inheritance - Polymorphism- OOP inJava –
Characteristics of Java – The Java Environment - JavaSource File
-Structure – Compilation. FundamentalProgramming Structures in Java
– Defining classes in Java –constructors, methods -access
specifiers - static members -Comments, Data Types, Variables,
Operators, Control Flow,Arrays , Packages - JavaDoc comments.
Data types, Variables, Operators
1P.Poovizhi/CS8392/Data types, Variables,Operators
7/25/2019
-
Variable Declaration
To declare a variable, you must specify the data type & give
the variable a unique name.
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
2
int a,b,c;
float pi;
double d;
char a;
-
Variable Initialization
To initialize a variable, you must assign it a valid value.
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
3
pi =3.14f;
do =20.22d;
a=’v’;
combine variable declaration and initialization
-
Types of variables
Local Variables
Instance Variables
Static Variables
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
4
-
Types of variables
1) Local Variables
Local Variables are a variable that are declared inside the body
of amethod.
2) Instance Variables
Instance variables are defined without the STATIC keyword
.Theyare defined Outside a method declaration. They are Object
specificand are known as instance variables.
3) Static Variables
Static variables are initialized only once, at the start of the
programexecution. These variables should be initialized first,
before theinitialization of any instance variables.
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
5
-
Example
class Guru99 {int data = 99; //instance variable static int a =
1; //static variable void method() {
int b = 90; //local variable }
}
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
6
-
Data Types in Java
Primitive Data Types Non-primitive Data Types
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
7
-
Primitive Data Types
Primitive Data Types are predefined and available within the
Javalanguage. Primitive values do not share state with other
primitivevalues.
There are 8 primitive types: byte, short, int, long, char,
float, double,and boolean
Integer data types
byte (1 byte) short (2 bytes) int (4 bytes) long (8 bytes)
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
8
-
Floating Data Type float (4 bytes) double (8 bytes)
Textual Data Type char (2 bytes)
Logicalboolean (1 byte) (true/false)
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
9
-
Java Default Values
Data Type Default Value Default size
byte 0 1 byte
short 0 2 bytes
int 0 4 bytes
long 0L 8 bytes
float 0.0f 4 bytes
double 0.0d 8 bytes
boolean false 1 bit
char '\u0000' 2 bytes
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
10
-
Data Types
Java is a strongly typed language. Every variable must have a
declared type. There are eight primitive types in Java.
Four - integer types Two - floating-point number types One -
character type char One - boolean type for truth values.
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
11
-
Java Variable Type Conversion & Type Casting
A variable of one type can receive the value of anothertype.
Case 1: Variable of smaller capacity is be assigned to
another
variable of bigger capacity.
This process is Automatic, and non-explicit is known as
Conversion
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
12
-
Java Variable Type Conversion & Type Casting
Case 2) Variable of larger capacity is be assigned toanother
variable of smaller capacity.
In such cases, you have to explicitly specify the type
castoperator. This process is known as Type Casting.
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
13
-
Data Types
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
14
-
Variables
Initializing the variableint
vacationDays;System.out.println(vacationDays);
// ERROR--variable not initializedint vacationDays;vacationDays
= 12;
Orint vacationDays = 12;
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
15
-
Operators
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
16
-
Operators
Arithmetic Operators
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
17
-
Operators
Bitwise Operators
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
18
-
Operators
Relational Operators
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
19
-
Operators
Boolean Logical Operators
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
20
-
Assignment Operatorint x,y,z;x=y=z=100;
? Operatorexpression1 ? expression2 : expression3
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
21
-
Type Conversion between Numeric
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
22
-
Enumerated Types
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
23
-
Reference
https://www.javatpoint.com/java-tutorial
http://nptel.ac.in/courses/106106147/
http://www.nptelvideos.com/java/java_video_lect
ures_tutorials.php
24
P.Poovizhi/CS8392/Data types, Variables,Operators 7/25/2019
-
PPT Created by – Credits To
Sandra.K.S
Dhinesh Kumar S
Gokulkrishnan.R
Santhoshkumar A
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
25
Sindhu.C
Sadhakrishnan.M
Abarna Jone J
Jithendran.R
-
7/25/2019P.Poovizhi/CS8392/Data types, Variables,Operators
26