Introduction to Data Type (JAVA)
Transcript of Introduction to Data Type (JAVA)
-
8/3/2019 Introduction to Data Type (JAVA)
1/16
CHAPTER 1 :INTRODUCTION
1.1 Motivation for studying data structure
1.2.1 Primitive Type
1.2.2 Abstract Data Type
1.3 Data Structure Concept
1.3.1 Static Data Structure
1.3.2 Dynamic Data Structure1.3.3 Operations on data structure
1.4 Application of structure data1
-
8/3/2019 Introduction to Data Type (JAVA)
2/16
A ood a lication can solve roblems o timall
minimize running time and efficiently use memory space.
structure.
2
-
8/3/2019 Introduction to Data Type (JAVA)
3/16
1.2 In r i n D T
In Java ro rammin all variables are re uired to have
aData Type.
a) Fundamental /Primitive /Base Type
b) Abstract Data Type
a) Fundamental Type
Ei ht Java fundamental data t es are int, float,
double, long, short, char, boolean and byte
A variable of the fundamental type simply store a
.
3
-
8/3/2019 Introduction to Data Type (JAVA)
4/16
1.2 Introduction to Data Type (cont)
a) 8 fundamental types
int: 32-bit signed twos complement
integerfloat: 32-bit floating-point number
ou e: - t oat ng-po nt num er
long: 64-bit signed twos complement
short:16-bit signed twos complement
inte er
char: 16-bit unicode character
boolean: boolean value true or false
byte: 8-bit signed twos complement integer
4
-
8/3/2019 Introduction to Data Type (JAVA)
5/16
1.2 Introduction to Data Type (cont)
ADT is also referred to as anobject.
ADT containsmore than one fundamental data types.
ADT also containsthe methods as an inter ace to mani ulate the
data.Each ADT is an encapsulation of data and methods.
In Java, ADT or object is defined using Class. Eg:
class Computer {
private int code;private String brand;
private double price;
pu c ompu erpublic Computer (int c, String b, double p) {}
public int getCode () { return code; }
public double getPr() { return price; };
} 5
-
8/3/2019 Introduction to Data Type (JAVA)
6/16
1.2 Introduction to Data Type (cont)
ADT can be used by any application program,
it eliminates rewriting the code if there arechanges in the implementation of the data /
o ect.
-
interfaces by having the set of methods in the
classes.
ADThides the implementation of the methods
in the encapsulation feature of the object.
6
-
8/3/2019 Introduction to Data Type (JAVA)
7/16
Abstract Data Type
Using class to create ADT
Classes are used to represent objects in Object
Oriented Programming (OOP) approach.
Class contains :
Member data - a set of field (data) -
OOP uses classes to encapsulate data (attributes) and
methods (behaviors).
Enca sulate enables ob ects to hide their
implementation from other objects.
7
-
8/3/2019 Introduction to Data Type (JAVA)
8/16
Abstract Data Type (cont)
Objects can communicate with one and
another across well defined interfaces (
methods).
implemented.
Pro rammer usesclasses to instantiate ob ects
that work together to implement the system
(using OOP approach)
Programmer can create their own ADTdepends on their needs (using OOP approach)
8
-
8/3/2019 Introduction to Data Type (JAVA)
9/16
1.3 Data Structure Concept
Data Structure is a concept on how to
structure represent an man pu ate ata
(store, process, access and etc) in the
program.
Data structure is known asa collection of re a e a a ems.
Two types of Data Structure :
a c a a ruc ure xe -s zeDynamic Data Structure
9
-
8/3/2019 Introduction to Data Type (JAVA)
10/16
Data Structure Conce t cont.1.3.1 Static Data Structure
Data is re resented with a s ecific/fixed memor
allocation.Example :
1.3.2 Dynamic Data StructureData can bea ocated anywhere in the memory and
reference is used to point to the data
D namic Data Structure can row and shrink at
execution time.Uses reference or dynamic memory allocation
10
-
8/3/2019 Introduction to Data Type (JAVA)
11/16
Data Structure Concept (cont.)
Example : Static/Fixed-Size Data Structure
Arrays :
contagiously in memory (adjacent to each other).Arrays arefixed-length entities with the capacity that is
specified during the creation / declaration time and the
length remains until end of program.
Arra s in JAVA are ob ects and its considered asre erence
type.
The elements of a JAVA array can be eitherprimitive types or
.Example : primitive types
int c[ ]; // declare an int array
c = new int[10]; // create an array of int with 10 elements
11
-
8/3/2019 Introduction to Data Type (JAVA)
12/16
Data Structure Concept (cont.)
Example : ADT
public class Student{
private String name;
private double gpa;
..
}
public static void main(String[] arg)
{ ..
Student Stu[ ]; // declares the array of objectStu = new Student[12];// creates the array of student (object)
}
12
-
8/3/2019 Introduction to Data Type (JAVA)
13/16
Data Structure Conce t cont.1.3.3 Operations on Data Structure
Some basic operations are:
. Adding
- Insert data into the structure.ii. Deleting
- .
iii. Updating
- Modify data in the structure
- Find a particular data in the structure base on a criterion
(keyword). It can be the location or the element to be searched.
v. Sortin
- Sort or organize data in the structure base on a criterion(keyword). It can be in ascending or descending order.
vi. Traversal
- Access each data in the structure and process them at least once.
13
-
8/3/2019 Introduction to Data Type (JAVA)
14/16
1.4 Data Structure Application
There are many data structure applications, some of the
major ones are:
st
List is an ordered sequence elements.contains a number of elements that is less than or
equal to its capacity.
Two types of list :
data in a contiguous memory (elements next to
each other)
Linked list a linked structure that store data
where one element refers to another, anywhere
in memory
14
-
8/3/2019 Introduction to Data Type (JAVA)
15/16
Data Structure Application (cont.)
Stacks
insertion and deletions are made from thetop of a stack
Queuerepresent a wa t ng nes an use n any
queue eg. printing queue and request queue
deletions are made from the front of a
ueue.
15
-
8/3/2019 Introduction to Data Type (JAVA)
16/16
Data Structure A lication cont.
Facilitate high speed searching andsorting of data.
Store high volume of data with the links
from one element to another anywheren memory
Eliminate duplicate data efficiently
expressions into machine language.
16