Java for Teachers Intermediate

Slides:



Advertisements
Similar presentations
File Management in C. What is a File? A file is a collection of related data that a computers treats as a single unit. Computers store files to secondary.
Advertisements

File Management in C. A file is a collection of related data that a computers treats as a single unit. File is a collection of data stored permanently.
1 Various Methods of Populating Arrays Randomly generated integers.
Chapter 10 Introduction to Arrays
1 File Output. 2 So far… So far, all of our output has been to System.out  using print(), println(), or printf() All input has been from System.in 
Flowcharts Remember that a solution to a problem is called an algorithm. Algorithms are often a series of steps required to solve the problem. A flowchart.
An Introduction to Textual Programming
A Level Computing#BristolMet Session Objectives U2#S6 MUST identify different data types used in programming aka variable types SHOULD describe each data.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Summary and Exam COMP 102.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 62 – Manipulating Data Using Methods – Day 1.
Java for Beginners University Greenwich Computing At School DASCO
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
Program 6 Any questions?. System.in Does the opposite of System.out.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
Chapter 12 Using data files. The concept of file Logically cohesive data stored on a permanent storage, such as hard disk (most cases), CD, USB. Types.
Graphical User Interface You will be used to using programs that have a graphical user interface (GUI). So far you have been writing programs that have.
A Level Computing#BristolMet Session ObjectivesU2#S12 MUST describe the terms modal and pretty printing in term of input and output facilities. SHOULD.
End of unit assessment Challenge 1 & 2. Course summary So far in this course you have learnt about and used: Syntax Output to screen (PRINT) Variables.
CIS Intro to JAVA Lecture Notes Set 6 2-June-05.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Files Tutor: You will need ….
2016 N5 Prelim Revision. HTML Absolute/Relative addressing in HTML.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
What is Binary Code? Computers use a special code of their own to express the digital information they process. It's called the binary code because it.
Programs and Data Files Data information processed by word processing, spreadsheet and similar application programs are stored as data files. Java programs,
Java for Beginners University Greenwich Computing At School DASCO
G043: Lecture 12 Basics of Software Development Mr C Johnston ICT Teacher
Microsoft Visual Basic 2005: Reloaded Second Edition
Lecture 5 of Computer Science II
Introduction to programming in java
Java for Beginners University Greenwich Computing At School DASCO
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Java for Beginners Level 6 University Greenwich Computing At School
Java for Beginners University Greenwich Computing At School DASCO
Reading from a file A file is typically stored on your computers hard drive. In the simplest case, lets just assume it is text. For a program to use.
David Meredith Aalborg University
Building Java Programs
Testing and Debugging.
Java for Beginners University Greenwich Computing At School DASCO
Java for Beginners.
Computer Programming Methodology File Input
Part I General Principles
Building Java Programs
Java for Beginners University Greenwich Computing At School DASCO
Python I/O.
Java for Beginners University Greenwich Computing At School DASCO
Building Java Programs
Unit 6 Working with files. Unit 6 Working with files.
Fundamentals of Data Structures
Building Java Programs
Coding Concepts (Data- Types)
int [] scores = new int [10];
Random Access Files / Direct Access Files
Review for Test1.
Java for Beginners University Greenwich Computing At School DASCO
Functions continued.
Python Basics with Jupyter Notebook
User Input Keyboard input.
CS 240 – Advanced Programming Concepts
Java: Variables, Input and Arrays
Why are arrays useful? We can use arrays to store a large amount of data without declaring many variables. Example: Read in a file of 1000 numbers, then.
Question 1a) What is printed by the following Java program? int s;
LCC 6310 Computation as an Expressive Medium
Dry Run Fix it Write a program
Java Coding 6 David Davenport Computer Eng. Dept.,
Challenge Guide Grade Code Type Slides
Presentation transcript:

Java for Teachers Intermediate Session 4 of 6 Java for Teachers Intermediate University Greenwich Computing At School DASCO Chris Coetzee

Levels of Java coding 1: Syntax, laws, variables, output 2: Input, calculations, String manipulation 3: Selection (IF-ELSE) 4: Iteration/Loops (FOR/WHILE) 5: Complex algorithms 6: Arrays 7: File management 8: Methods 9: Objects and classes 10: Graphical user interface elements

Files There are two types of files in computing: Text files (that contain ASCII/Unicode characters) – e.g. TXT, CSV Random Access Files (that contain binary objects) – e.g. JPG, MP3

Setting up the file connection Steps to remember: Import: java.io.* Throw away any IOExceptions (throws IOException) that could potentially occur in the main method

Connecting to the file Steps to remember: First add a File Reader Then add that File Reader to a Buffered Reader

Where do I store the text file? Store the file in the MAIN project folder (not in BIN or in SRC)

How do I read from the file? ALL INPUT IS ALWAYS STRING!

Useful strategy to know Sometimes you might want to read in data like this: 23, 45, 56, 93, 23, 35 Suggested strategy: Read in the line in to a String Split the String into an array Convert the values into ints

In Java that would be: Which reads as… Read the first line from the file in to a String variable called line. Split the line variable into an String array called tempstringarray Create an integer array called intarr of the same size as tempstringarray Loop through for all the values in tempstringarray Convert each value from a String to an int and store it in the new integer array at the same index point.

No buffer is used this time. You write directly to the file. Writing to a file No buffer is used this time. You write directly to the file.

In the end, always .close()

Example of adding numbers in a file