Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Data Types and Data Structures

Similar presentations


Presentation on theme: "The Data Types and Data Structures"— Presentation transcript:

1 The Data Types and Data Structures
Chapter 3 The Data Types and Data Structures

2 Data Types

3 Scanner userinput = new Scanner(System. in); System. out
Scanner userinput = new Scanner(System.in); System.out.println("Welcome to Java Calculator"); System.out.print("Enter First Number:") num1= userinput.nextInt(); System.out.print("Enter Second Number:"); String num2= userinput.nextInt(); System.out.print("Enter operation to perform (+,-,x,/):"); String operation = userinput.next();

4 for(char loop = a ; loop <= z ; loop++ )
System.out.println(loop);

5 Data Structures Arrays Records

6 Arrays An array stores multiple values of the same data type but say that we want to store values of multiple data types. For example a person on a database will have data about their name, age and gender; all of which could not be stored in an array (as they are data types string, integer and character). This is where records are useful as they can store a number of fields on a particular situation that requires a number of different data types.

7

8 Indexed Sequential Files Direct Access Files/Random Access File
Types of files: Serial Files Sequential Files Indexed Sequential Files Direct Access Files/Random Access File Random Files

9 Serial Files Is a file in which the data is stored in the order in which it arrives. New data is simply added to the end. When data is deleted a gap is made and the only way to remove this gap is to rewrite the file. To find something you need to search the entire file.

10 Sequential Files Stored in a logical sequence such that library books would be stored by their reference number. New data is added to the middle of the file by creating a new file, moving all of the data before the particular point to the new file, adding the new data to the new file and then migrating the rest of the data to the new file. Pascal does this automatically. Searching is the same as serial files.

11 Indexed Sequential Files
Same as sequential files except data can be searched for from any of the fields, not just the logical sequence field.

12 Direct Access Files/Random Access File
If the records of a sequential file are of a fixed length and so data can be read from the file, if you now its position in the file, without having to read through the whole file; for example a file with record of 50 bytes then the records will be stored at 0, 50, 100, 150, 200 etc. bytes into the file. Formula for accessing the nth record.

13 Random Files Data can be stored in memory or on disk in the most efficient way possible by breaking up the records. The records are broken up through the use of a hash algorithm. It is the quickest as to access data you only need its location and you don't have to read through the entire file. It is very useful for large databases.

14 Scanner scan = new Scanner(System. in); System. out
Scanner scan = new Scanner(System.in); System.out.println("Enter strings to change "); int input = scan.nextLine(); int result = input.toUpperCase(); System.out.println(result);

15 Working with files Opening Opening files usually means just declaring the file as a variable and using an open command (or similar) in most languages. Not too much to it really. It is also good practice to have the file open for as little time as possible so that to minimalise memory usage, processor time and also other applications may also need to have access to the same file, especially on a network.

16 Working with files Reading Some languages provide different methods of reading from files (Pascal uses the read command which reads the file line by line). In some files it maybe necessary to check that you have not reached the end of the file before reading the next line otherwise errors may occur, or place the reading the file inside a repeat loop that continues until end of file has been reached.

17 Working with files Writing This may include appending, editing, rewriting files and a variety of other tasks that differ between programming languages and types of files and I can't be bothered to do lots of research: so let me google that for you instead

18 Working with files Estimating File Sizes
Determine the size of each record by adding up the size of each variable (see table at top). Multiple this number by the number of records in the file. Add 10% for overheads. Divide by 1000 (1024 for the perfectionists) to convert to kilobytes. Repeat above step to convert to next levels of data storage if necessary - Megabytes, Gigabytes etc.


Download ppt "The Data Types and Data Structures"

Similar presentations


Ads by Google