OOP thema 1 samenvatting PDF

Title OOP thema 1 samenvatting
Author Frederik Pieters
Course Programmeren
Institution Universiteit Gent
Pages 6
File Size 158.5 KB
File Type PDF
Total Downloads 39
Total Views 188

Summary

samenvatting hoofdstuk 1...


Description

OOP 1. Introduction to Computers and Java 1.1

Computer Basics

Computer systems = hardware + software Hardware = physical machine Program = set of instructions for the computer to carry out Software = all the different kinds of programs used to give instructions to the computer Hardware and memory Cpu, central processing unit or processor: device inside your computer that follows a program’s instructions Memory = holds data for the computer to process and holds the results 1 main memory = holds the current program and the data that program is manipulating eg RAM (random access memory) 2 auxiliary memory / secondary memory = holds data in a more or less permanent form, exists even when the power is off, eg all the various kinds of disks ! the computer’s memory exists of a long list of numbered bytes. The number of a byte is called its ADRESS ! A byte is the smallest addressable unit of memory ! When the computer needs to recover the data, it uses its address of the byte to find the data item 1 byte = 8 bits = 8 binary digits For a piece of data that cannot fit into a single byte, it uses several adjacent bytes = memory location, the address of the first byte is used as the address of the memory location ! auxiliary memory is also divided into bytes but these bytes are grouped into much larger units known as files !When you use a program, the contents of the program file are copied from the auxiliary memory to the main memory/ ram ! you can name each file and organize groups of files into directories or folders FAQ: Why just 0s and 1s An electrical device only has 2 stable states Programs When you give the computer a program and some data and tell the computer to follow the instructions in a program  running or executing Two ways to view running of program 2 inputs : data and program , results are output It is also possible to view the program and computer as 1 and the data is the only input and the results the output  more useful to design a program ! Much of what we consider the computer is actually a program (software rather than hardware) eg operating system (supervisory program that oversees the entire operation of the computer, eg if we click on an icon, choosing a menu item or typing in a simple command) Operating systems : Microsoft Windows, Apple’s Mac OS, Linux, UNIX

Programming languages, compilers and interpreters High-level languages : easy for people to understand and use, eg java, Virtual Basic, C++, Python Computer hardware does not understand high-level languages, so they must be translated into a language that the computer can understand (machine language) Assembly language: symbolic form of machine language that is easier for people to read SO assembly language is almost the same as machine language, it needs some additional translation before it can be run on the computer. Low-level languages (eg machine language) can be executed by a computer Translation high-level language to low-level language  program: compiler / interpreter !Once compiled, a program can be run as often as you like without compiling it again ! input program / source program / source code  object program / object code ! interpreter: translates program statements from a high-level language to a low-level language (// compiler) but an interpreter executes a portion of code right after translating it, rather than translating the entire program at once (=/= compiler) translation alternates with execution translation is done every time you run the program COMPILER (can be run over and over again without engaging the compiler again) IS FASTER THAN INTERPRETER ESSENTIE COMPILER Program that translates a program written in a high-level language into a program in a simpler language that the computer can more or less directly understand INTERPRETER Program that alternates the translation and execution of statements in a program written in a high-level language ! you need a different compiler or interpreter for each type of language or computer system ! compiler / interpreter: large program, expensive and time-consuming to build Java combines compiler and interpreter Java Bytecode Java compiler does not translate your program into the machine language for your computer, it translates your java program into BYTECODE. Bytecode = a machine language for a hypothetical computer known as a virtual machine (similar to all typical computers) The bytecode interpreter Java Virtual Machine then translates into machine language for a particular computer THUS: compiler to bytecode, translate each bytecode via particular Java Virtual Machine for your computer system into machine language Compiler=> bytecode => Java Virtual Machine interpreter => machine language

Modern implementations of the JVM use a Just-In-Time compiler  the jit compiler reads the bytecode in chunks and compiles entire chunks to native machine language instructions as needed. (again a chunk needs to be compiled only once) ! why would we use Java Bytecode? It only adds a step to the process. This would indeed be faster but Java Bytecode has the advantage of portability (you can run it on every computer). ! this portability is why Java is good for internet applications ( you can send it over the internet to another computer and have it run easily on that computer regardless of that computers operating system. Another advantage of portability : new type of computer system, no need for new compiler, although does need own bytecode interpreter (JVM) -> compiler; expensive, time-consuming -> bytecode interpreter: much simpler  java can be added to a new computer very quickly and very economically RECAP JAVA COMPILER TRANSLATES YOUR JAVA PROGRAM INTO BYTECODE, THIS IS NOT THE MACHINE LANGUAGE FOR A PARTICULAR COMPUTER BUT IS SIMILAR TO THOSE OF MOST COMMON COMPUTERS. BYTECODE IS EASILY TRANSLATED INTO MACHINE LANGUAGE OF A GIVEN COMPUTER. EACH TYPE OF COMPUTER WILL HAVE ITS OWN INTERPRETER THAT TRANSLATES FROM BYTECODE INSTRUCTIONS TO MACHINE-LANGUAGE FOR THAT COMPUTER Normally you will only give two commands 1. One to compile your Java program into bytecode 2. One to run your program: run command tells the bytecode to execute the bytecode Name bytecode: instructions in this low-level language consist of instructions that can be stored in a few bytes of memory Class Loader Classes  pieces of code, separately compiled To run a program  the bytecode for these various classes must be connected together, this is done by program called class loader (sometimes linker)

1.2

A sip of Java

History of the java language  Programming language for internet applications  General-purpose programming language that can be used without reference to the internet  Brief history: o 1991 Gosling began designing a programming language for programming home appliances (toasters,…) o Home appliances work with a lot of different computer processors/chips, no will to invest in a lot of expensive compilers for every chip o Hence, had to work on all those different processors

o One piece of software that would translate an appliance-language program into a program in an intermediate language ( = bytecode ) that would be the same for all appliances and their processors o Then a small, easy to write, inexpensive program would translate the intermediate language into machine language for a particular appliance o This plan never caught on o 1994 Gosling realized his language would be ideal for developing a web browser that could run programs over the internet -> no longer active but start of Java’s connection to the internet o 1995 web browsers were designed capable of running java programs Applications and Applets Application = regular program, meant to run on your computer Applet = little application, meant to be sent to another location on the internet and run there from a web browser A first Java application program User = person who interacts with the program

Import java.util.Scanner; Tells the compiler that this program uses the class Scanner Class: a piece of software that we can use in a program This class can be found in the package java.util Package: a library of classes that have already been defined for you

Public class … { } + Within these braces we have one or more parts called methods + every java application has a method called main and often other methods + statements within a method define a task and make up the body of the method (software) objects: to perform actions Methods: actions are defined by methods Argument: item(s) inside the parentheses An object performs an action when you invoke or call one of its methods FORM: object.method() Variable: can store a piece of data Data type: eg int, double Grammar: java has precise rules for how you write each part of a program Syntax: the set of grammatical rules for a language Writing, Compiling, and Running a Java Program - Java program consists of classes - Each class definition you write is in a different file, the name of that file is the name of the class + .java

-

To compile al java class, you use the command javac followed by the name of the file containing the class (eg javac MyClass.java) - After compiling, the translated version of the class is placed in a file whose name is the name off the class followed by .class - Command to run a Java program: java FirstProgram  easiest way to write, compile and run = IDE (integrated development environment)

1.3

Programming Basics

Object oriented programming Each object has the ability to perform certain actions, and each action can affect some of the other objects in the world - An object has characteristics: attributes - The values of an objects attributes give the object a state - Actions that an object can take: behaviors - Objects of the same kind are said to have the same data type -> same class - Class...


Similar Free PDFs