Download presentation
Presentation is loading. Please wait.
1
OOP&M - theory lectures1 OOP&M – presentation Team presentation Lab Tove/Lenny Theory (basics) Thomas Theory (continuation) David Personal presentation 26 – Spanish – driver license – no swedish yet, but learning MSc. Telecommunication Engineering, University of Zaragoza/Spain 6 months working at an ISP (Internet Service Provider) 1 year working at the radio brunch - Teltronic – Management 9 months working at Infineon (Siemens Semicon) – Development Several projects with Malmo Hogskola (sorry english keyboard)
2
OOP&M - theory lectures2 Courses objectives GUI, I/O, Exceptions, Event Handling, Threads Reaching a minimum comprehension level (everybody) Practical work at the laboratory Satisfying the need of new knowledge (some) Description of the classes There are two different levels of theory classes: Thomas leads the basic course (swedish) David leads the normal course (english) Labs will consist in some explanation (code analysis) and in doing some exercises, that should be finished at the end of the Lab hour. You must give a form filled up IN THAT moment (english please) 1 form per LAB each!! We need: Pictures one picture from each one / with name / end of this week / digital format OOP&M – presentation
3
OOP&M - theory lectures3 Calendar of the classes OOP&M – presentation WeekTheory basicsTheoryLAB number 3Data types, parts of a program, assignment, variables 4Arrays, strings, arithmetics, type conversion I/O: Out Monitor and files 5Boolean, If..ElseI/O: In Keyboard and files1 6MethodsGUI: basics, window2 7LoopsGUI: button, text field3 8??Event Handling: mouse I4 9Event Handling: mouse II5 10Exceptions6 15Exceptions7 16Threads8 17Threads9
4
OOP&M - theory lectures4 OOP&M – presentation WeekTitleLAB number 4None 5-streaming keyboard -showing information -streaming files 1 62 7-placement of windows -placement of buttons -calculator layout 3 84 9-capturing mouse clicks5 106 15-exceptions7 16-threads8 179 Calendar of the labs LAB Objective: Roman number calculator
5
OOP&M - theory lectures5 Information board There is an information board at David’s studio, it contains several information. Some of that is referred to this course, other to deadlines for applications for conferences or design contests … Material (books, notes, web) Everything that is needed will be published on the web as powerpoint files or adobe acrobat files Evaluation methods: Presence at the courses: 80% Presence at the lab: 80% Lab work: 100% or additional work from the 80% Extra work: “Game of life Seminar – first example for programming artificial life” Final project collaborating with the MDI course Questions: David will be Wednesdays at the studio: 9:00 – 12:00 OOP&M – presentation
6
OOP&M - theory lectures6 OOP&M – presentation MondayTuesdayWednesdayThursdayFriday LABQuestionsLAB Theory bTheory Your Java Week This makes a total of: 30 theory hours ~30 lab hours ~21 basics hours
7
OOP&M - theory lectures7 OOP&M – the very beginning “…at the beginning there was nothing…” - the Hollybook -
8
OOP&M - theory lectures8 OOP&M – introduction computer machine has got no aim does nothing by itself if we want the machine to do something it should be PROPERLY feed before the food is made of programs the nutrients in the food are machine code axiom fact possible solutions
9
OOP&M - theory lectures9 OOP&M – introduction inputoutput -joystick -mouse -keyboard -microph. human based input -floppy -HD -CD -ZIP/JAZZ -… prev. rec. infor. as input -joystick -screen -speakers -lights human based output -floppy -HD -CD -ZIP/JAZZ -… infor. as output
10
OOP&M - theory lectures10 OOP&M – a monitor monitor object Most of the programs that we write show information on the monitor Here we will learn how to use one of Java’s predefined objects to control a monitor 1 monitor 2 roles For a user it is a device to read information from For a program it is a device to display information on displayread programmonitor Bjorn
11
OOP&M - theory lectures11 OOP&M – the two monitors example small monitor Bjorn big monitor Lisa “turn up the brightness of the big monitor!” -message: “turn up the brightness of the big one!” -“big one” is a reference to an object -the monitors are the objects -“change brightness” is the behavior -“up” is a part of the further details
12
OOP&M - theory lectures12 OOP&M – Mr. Monitor is an … object Let’s see how a Java program is going to use the monitor for showing information. We want to show the message: “In winter Bjorn and Lisa eat potatoes.” in Java the computer’s monitor is represented as a predefined object the object is an instance of the PrintStream class PrintStream class is one of Java’s predefined classes Objects are instances of classes
13
OOP&M - theory lectures13 OOP&M – Mr. Monitor is an … object If we want the program to show something on the screen, then we need to use a line like the following: System.out.println(“ In winter Bjorn and Lisa eat potatoes.”) We can now compare this situation with the other one that we saw for the other example: reference -Lisa: “big one” -Java: System.out behavior -Lisa: “turn … brightness” -Java: println further details -Lisa: “up” -Java: (“In winter Bj…toes”)
14
OOP&M - theory lectures14 OOP&M – Mr. Monitor is an … object System.out.println(“ In winter Bjorn and Lisa eat potatoes.”) println(“ In winter Bjorn and Lisa eat potatoes.”) behaviordetails reference to the receiver message Sending a message to an object is an action that the programmer specifies and that the computer carries out when the program runs. In Java all actions are specified in STATEMENTS.
15
OOP&M - theory lectures15 OOP&M – Mr. Monitor is an … object Which form will have our program for writing the message to the screen? import java.io.* class Potatis { public static void main(String[] arg) { System.out.println(“In winter …”); } Here is very easy to identify the order that makes the program use the library where the predefined classes for input/output of data using the standard interfaces: import java.io.*
16
OOP&M - theory lectures16 OOP&M – my computer eats disks Most of the mass-storage media organize the information into files. Floppies, HardDrives, ZIP disks, CDs … contain information in the form of files. For many processes we need to store information and not only to show it on the screen. Therefore we will study the use of files, because they are a transparent way of treating the storage of information.
17
OOP&M - theory lectures17 OOP&M – a file never lie … it’s so transparent Advantages of files: persistence: screen information last as long as it is shown on the screen capacity: it can be stored much more data in a file than can be displayed on the screen or even printed reusability: convertible between systems Attributes of files: contents (data): it can be any information. From letters to shopping lists, anything. file name: the rules for choosing file names vary between operating systems. They are more liberal than the rules for governing identifiers. SHOPPING potatis mjolk agg … shopping.lst
18
OOP&M - theory lectures18 OOP&M – a file never lie … it’s so transparent Operations with files: create: programs write data into files delete: removes name and contents rename: changes name but keeps contents overwrite: keeps name but changes contents read: reads data from the contents of the file SHOPPING potatis mjolk agg … shopping.lst
19
OOP&M - theory lectures19 OOP&M – Java has got an affair with file Java provides a predefined class for modeling disk files, called File the constructor for File accepts the file’s name (a String reference) as its argument new File ( filename ) An example of this would be: Filef1, f2; f1 = new File(“Bjorn_receipt”); f2 = new File(“Lisa_receipt”);
20
OOP&M - theory lectures20 OOP&M – Java has got an affair with file If the files exist the class provides us two methods for directly operate with the files: DO NOT FORGET THAT: The creation of the instances f1 and f2 doesn’t mean that the files exist!! Filef; f = new File(“delete_me”); f.delete(); delete Filef1, f2; f1 = new File(“change_me”); f2 = new File(“take_my_name”); f1.renameTo(f2); rename
21
OOP&M - theory lectures21 OOP&M – Java has got an affair with file after this interlude about the files, we can continue talking about the use of the interfaces to Java programs first we analyzed the screen as an output, now we are going to study the files as an output for creating or overwriting a file in Java we need exactly the same resource pathway stream
22
OOP&M - theory lectures22 OOP&M – Java streams into files Java provides a predefined class for modeling a stream of output that goes to a file called FileOutputStream the constructor for FileOutputStream accepts a reference to a File as its argument new FileOutoutStream ( file ) An example of this would be: Filef; f = new File(“Bjorn_nude_sauna”); FileOutputStream fs = new FileOutputStream(f);
23
OOP&M - theory lectures23 OOP&M – Java streams into files Java program FileOutputStream SHOPPING potatis mjolk agg … shopping.lst bytes of data ewsc24rfds53Hej20Hur20m76ar20du20?rsf
24
OOP&M - theory lectures24 OOP&M – Java streams into files Java provides a tool for modeling a stream of bytes sent to a file as if they were sent to a screen the constructor for PrintStream accepts a reference to a FileOutputStream as its argument new PrintStream ( fileoutputstream ) An example of this would be: Filef; FileOutputStream fs; PrintStream target; f = new File(“data.out”); fs = new FileOutputStream(f); target = new PrintStream(fs); target.println(“Lisa drinks a glass onions”);
25
OOP&M - theory lectures25 OOP&M – Java streams into files summary: how to create or overwrite a file in a line Create a File object to represent the file and then use it to Create a FileOutputStream object to represent the output pathway to the file and use it to Create a PrintStream object to provide a convenient output pathway to the file Use the print or println methods of PrintStream as needed to write content to the file PrintStream target = new PrintStream( new FileOutputStream( new File(“data.out”)));
26
OOP&M - theory lectures26 OOP&M – Java streams into files Class exercise: create a Java program that writes information both to the screen and to a file called: “Bjorn_Lisa.log” Consider that Bjorn and Lisa did the following: 1)16:30 Met at Triangeln (she was late) 2)17:00 Drunk coffee at Expresso-House 3)19:15 Met with Lisa’s brother at the cinema 4)21:25 Had dinner at Lillatorg 5)23:00 Had some drinks at the Hippodromen 6)01:00 ?!?! Answer the question: is that possible? How much costs a night like that?
27
OOP&M - theory lectures27 OOP&M – Java streams into files import java.io.* class LogMyDay { public static void main(String[] arg) throws Exception{ PrintStream log; FileOutputStream logfileStream; File logfile; logfile = new File(“Bjorn_Lisa.log”); logfileStream = new FileOutputStream(logfile); log = new PrintStream(logfileStream); System.out.println(“16:30 Met at Triangeln …”); log.println(“16:30 Met at Triangeln …”); … } one possible solution
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.