100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
Summary Object-oriented Programming CSE1100 €5,49
In winkelwagen

Samenvatting

Summary Object-oriented Programming CSE1100

 70 keer bekeken  0 keer verkocht

A summary of the course Object-oriented Programming (CSE1100) of TU Delft, part of the bachelor Computer Science and Engineering.

Laatste update van het document: 2 jaar geleden

Voorbeeld 3 van de 16  pagina's

  • 7 september 2022
  • 8 september 2022
  • 16
  • 2018/2019
  • Samenvatting
Alle documenten voor dit vak (1)
avatar-seller
sachakorte
Lecture 1: Introduction

Programming: you are telling the hardware what should happen.
Higher level languages à assembly language à machine code à binary code.
Difference in higher-level programming languages:
• C, C++, Haskell, Go … à compiled for a specific (hardware) platform
o Programmer à program code à compiler à machine code à program user
• Java, C#, Scala … à compiled to an intermediate format.
o For Java, this intermediate format is called bytecode (.class files).
o Bytecodes are executed (“played”) by a virtual machine (“video-recorder”), a piece of
software that translates your program to run on the hardware underneath it.
o Java programmer à program code à java compiler à java byte code à JVM
o We have a JVM for Windows, Apple, Unix and Linux so you can write and compile
the code ones and execute it on multiple machines.
o Call to compiler: javac Hello.java; call to virtual machine: java Hello
• Python, Ruby, PHP, … à not compiled at all, a special program (interpreter) directly
executes them.

Imperative programming: program is composed of a list of statements; a statement is a
combination of data and operations.
Object-oriented programming: program consists of classes, objects and a list of statements; the
statements are composed of objects, data and operations.

Floating-point numbers cannot precisely represent all real numbers, precision is limited. A
programmer must be aware of this while programming a program that does computations.

Java type bits These are Java’s eight primitive types.
Booleans 1. boolean String is not a primitive data type, but a reference
2. byte 8 data type.
Integers 3. short 16
4. int 32
5. long 64
Real numbers 6. float 32
7. double 64
Characters 8. char 16

Question: what is the value of a local variable after its declaration?
Answer: it is unassigned, and you will get a compiler error if you try to use it before initializing it.

Assignment operator: =
Arithmetic operators (for integer and floating-point types): +, −, ∗, /, % à be aware of overflow.
The result of the remainder operator is such that (𝑎 / 𝑏 ) ∗ 𝑏 + (𝑎%𝑏) = 𝑎

,Lecture 2: Programming Structures

Rules of thumb, in your program, there should be:
• Structure;
• Cohesion: show parts that logically belong together;
• Separation: use spaces, empty lines, capital/smaller letters;
• Indentation: to show that certain parts belong together;
• Comments: use comments to explain;
• Variable naming: use variable names that clearly express the role of the variable;

Equality operators: == equal to, ! = not equal to. You should not use equality for Strings, also be
careful when testing floats or doubles, because they may be not precise.

Relational operators: <, <=, >, >= à only used for numerical comparison (including characters).

Boolean logical operators: & logical AND, | logical OR, ^ logical XOR, ! logical complement.
&& and || are “lazy” operators: the right-hand side is only evaluated when necessary.

𝑖𝑓, 𝑒𝑙𝑠𝑒 𝑖𝑓 and 𝑒𝑙𝑠𝑒: used for selection
𝑠𝑤𝑖𝑡𝑐ℎ: used for selection à 𝑏𝑟𝑒𝑎𝑘𝑠 are needed, type of condition can be byte, short, char, int,
Character, Byte, Short, Integer, String and enum types.
Character is a class (contains methods such as 𝑖𝑠𝑈𝑝𝑝𝑒𝑟𝐶𝑎𝑠𝑒()) char is a primitive type.

For iteration we can use a 𝑓𝑜𝑟-statement, a 𝑤ℎ𝑖𝑙𝑒-loop or a 𝑑𝑜 … 𝑤ℎ𝑖𝑙𝑒-loop (this loop is always
executed at least once, only after the first execution, the condition is checked).

Lecture 3: Methods

Methods are added to code to prevent code duplication (and duplicating mistakes). A method can
accept parameters and can give a return value.
The parameter types along with the return type form the function’s signature.
A 𝑣𝑜𝑖𝑑 method does not return something, a 𝑟𝑒𝑡𝑢𝑟𝑛 is not obligatory but you can use it.

Precondition: defines the initial state before the calculation in the method.
Postcondition: defines the end state after the calculation in the method.

Overloading: you can use the name of a method more than once, if:
• The number of parameters for both methods is different;
• The number of parameters is equal, but its types are different (or have a different order).

Formal parameters: the identifier used in a method to stand for the value that is passed into the
method by a caller.
Actual parameter: the actual value that is passed into the method by a caller.

A variable declared within a block, will get cleaned (garbage collected) when control leaves the
block à garbage collection is freeing up unused memory.

, Lecture 4: Classes

Class: a software module that is composed of attributes and methods. It is a blueprint for object, it
defines attributes and methods.
Object: an instance of a class, with its own values for the attributes.
Constructor: special method (same name as class) is called when memory needs to be allocated
for the class.
𝑂𝑏𝑗𝑒𝑐𝑡1 == 𝑂𝑏𝑗𝑒𝑐𝑡2: compares memory addresses. To compare two objects, you should write an
𝑒𝑞𝑢𝑎𝑙𝑠 method in a class. The parameter of this 𝑒𝑞𝑢𝑎𝑙𝑠 methods should be of type 𝑂𝑏𝑗𝑒𝑐𝑡.
Then you can check of the 𝑂𝑏𝑗𝑒𝑐𝑡 to which we compare is actually an instance of the class, if so
you can cast 𝑂𝑏𝑗𝑒𝑐𝑡 to an instance of this class.

A static method does not work on an object. This implies:
• No reference to “this”
• No access to attributes (it can access static attributes).
A static method is called through the class: 𝑆𝑡𝑟𝑖𝑛𝑔. 𝑟𝑒𝑎𝑑(𝑥)
The compiler will give a warning when a static method is called through an object: 𝑠. 𝑟𝑒𝑎𝑑(𝑥),
where 𝑠 is of type String.

Private: other classes cannot access it (UML: -). Why private?
• To hide implementation: the consumer of your class cannot know how something is
implemented internally;
• As a protective measure against yourself (the programmer).
• All objects of a type can access a private value.
Public: other classes can access it (UML: +)
A static attribute is common to all objects of a class.

Java passes arguments by value, if you want to change objects who are made in main in other
functions, you should pass the address of the objects to these functions (addresses are passed by
value). Now, the memory addresses can’t be changed, but the objects the addresses points to,
can be changed.

When a method is called, Java will always create a copy of the arguments (actual parameters).
This copy is stored in the local table of the method. For reference types parameters it is the
reference that is copied, not the memory block where the reference points to.

Lecture 5: Debugging

Solution to fix problems in your code:
• Add print statements to see what is going on.
• Make use of the debugger in Eclipse: “playing your program in slow motion”.
o Set breakpoints.
§ A breakpoint on an entire class will suspend execution when something from
the class is called.
§ A breakpoint on a method will suspend execution when method is called.
§ “Watch point”: debugger will suspend execution when an attribute is read
and/or changed (this can be configured).
§ Advanced breakpoints: you can add the properties of a breakpoint.
• After reaching the breakpoint 𝑥 times à stop execution.
• Conditional breakpoints.
o Continue executing: until next breakpoint (or end, in case of no breakpoints).
o Stop the execution.
o Stepping into: look what is happening inside a method call.
o Step over: step over the statement.

Voordelen van het kopen van samenvattingen bij Stuvia op een rij:

Verzekerd van kwaliteit door reviews

Verzekerd van kwaliteit door reviews

Stuvia-klanten hebben meer dan 700.000 samenvattingen beoordeeld. Zo weet je zeker dat je de beste documenten koopt!

Snel en makkelijk kopen

Snel en makkelijk kopen

Je betaalt supersnel en eenmalig met iDeal, creditcard of Stuvia-tegoed voor de samenvatting. Zonder lidmaatschap.

Focus op de essentie

Focus op de essentie

Samenvattingen worden geschreven voor en door anderen. Daarom zijn de samenvattingen altijd betrouwbaar en actueel. Zo kom je snel tot de kern!

Veelgestelde vragen

Wat krijg ik als ik dit document koop?

Je krijgt een PDF, die direct beschikbaar is na je aankoop. Het gekochte document is altijd, overal en oneindig toegankelijk via je profiel.

Tevredenheidsgarantie: hoe werkt dat?

Onze tevredenheidsgarantie zorgt ervoor dat je altijd een studiedocument vindt dat goed bij je past. Je vult een formulier in en onze klantenservice regelt de rest.

Van wie koop ik deze samenvatting?

Stuvia is een marktplaats, je koop dit document dus niet van ons, maar van verkoper sachakorte. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

Nee, je koopt alleen deze samenvatting voor €5,49. Je zit daarna nergens aan vast.

Is Stuvia te vertrouwen?

4,6 sterren op Google & Trustpilot (+1000 reviews)

Afgelopen 30 dagen zijn er 52355 samenvattingen verkocht

Opgericht in 2010, al 14 jaar dé plek om samenvattingen te kopen

Start met verkopen
€5,49
  • (0)
In winkelwagen
Toegevoegd