Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Programming (FEB22012X)

Rating
-
Sold
2
Pages
12
Uploaded on
07-09-2022
Written in
2020/2021

Comprehensive summary of Programming (econometrics EUR)

Institution
Course

Content preview

Week 1
Primitive types
The eight primitive types are: byte, short, int, long, float, double, char and boolean
All other types are non-primitive types
Automatic conversion is only possible if the conversion goes from a more specific to a more
general type
Non-primitive types
String, Scanner and arrays are examples of non-primitive types. Classes created yourself
result in new non-primitive types. For every primitive type there is an associated non-
primitive type. Java supports autoboxing of primitive types, so these types are automatically
converted to the right type
Objects
Objects hold data in their instance variables, the configuration of these instance variables is
the state of the object. Objects do things when methods are called on the object.
Every object (instance of a class) has its own copy of the non-static instance variables
Public/private
Public instance variables can be accessed from anywhere, private ones only within the same
.java file as where they are defined
Method
A method operates on the object we call it on, can use the current instance variables of the
object and can modify the state of the instance variables of the object if it is mutable
Class variables
Class variables are static, final values, such as Math.PI
Static/non-static
Static methods are not associated with an object and cannot access instance variables.
A static variable belongs to and class and not to an object. Static methods can access only
static variables. A not-static method can access both static and non-static variables
Objects and references
Variables of a primitive type store a value and variables of a non-primitive type store a
reference. So, when a non-primitive type is copied, it means it just has the same reference
Immutable objects
Immutable objects never change their state, they hold values just as primitive types.
Non-primitive versions of primitive types are all immutable
Immutable class
When making an immutable class, make all the instance variables final, and let the methods
return new instances instead of change the current instance

Week 2
‘this’ keyword
When instance variables are used in methods and constructors, we implicitly assume they
refer to the current or local instance. We can refer to the current or local instance explicitly
with the keyword this. So, that will be this.instanceVariable = …
Null
The null reference is used to indicate that there is no object. Instance variables with a non-
primitive type always get ‘null’ as the default value. If we try to call a method on a variable
that is null, we will get a ‘NullPointerException’ and the program will stop. When concerned
a variables is ‘null’, you can do a ‘null’ check. It is important to initialize your non-primitive
instance variables in your constructor, or you will run into the risk of getting
‘NullPointerExceptions’. ‘null’ can also be used to return if for example no object was found.

, Random numbers
Since computers words deterministically, generating random numbers is not easy. The idea
to get a pseudo random number is to define an extremely long sequence of numbers, then
start at a point in this sequence, the seed, and use the following numbers in the sequence as
your random values. The seed can be picked randomly by using current time for example.
Errors
- Syntax errors: grammatical error, program will not run
- Type error: error when wrong type is used, program will not run
- Structural error: error concerning the structure of the code, program will not run
- Semicolon on the wrong spot
- Wrong mathematics
- ‘ArrayIndexOutOfBoundException’: the index is not existing in the array
- ‘OutOfMemoryError’: loop goes on too long
- ‘StackOverFlowError’: method refers to itself, memory is stored at stack and fits no more
Types of errors
- Compiler errors: syntax, types, structure
- Runtime errors: something unexpected happens during execution
- Logical errors: program executes fine but gives wrong answer/behaviour
Exception handling
Java has special features incorporated into the language that can pass control from the point
a runtime error was detected to a handler. You can raise an exception with the ‘throw’
keyword. After a ‘throw’ action, the method will stop. You can put ‘throws’ in the method
header to indicate that the method might throw an exception. An exception is an object
Exception types
Exceptions that may be caught:
- IllegalArgumentException
- NumberFormatExcteption
- IllegalStateException
Exceptions that must be caught or declared in the method header using ‘throws’:
- IOException
- FileNotFoundException
Some problems are so severe that you should stop your program if occur, these are errors:
- OutOfMemory Error
- StackOverflowError
‘finally’
‘finally’ can also be used with ‘try’. The ‘finally’ block is always executed as soon as the try
block is exited, no matter for what reason. Try to avoid finally.
Design principles
Exceptions are meant to deal with exceptional situation, they should not be used for regular
control flow. Throwing and handling of exceptions is not optimized.
You should throw early and catch late. Check the input of a method before you start doing
computations. If the input is not okay, throw an exception. If an exception can occur within a
method that is not able to provide a good solution to the problem, the exception should be
thrown to the caller. And never use return in a finally block.

Week 3
Polymorphism
Treating objects of completely different classes in a uniform way.

Written for

Institution
Study
Course

Document information

Uploaded on
September 7, 2022
Number of pages
12
Written in
2020/2021
Type
SUMMARY

Subjects

$9.06
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
LeonVerweij Cals College Nieuwegein (Nieuwegein)
Follow You need to be logged in order to follow users or courses
Sold
33
Member since
8 year
Number of followers
19
Documents
28
Last sold
9 months ago

2.0

1 reviews

5
0
4
0
3
0
2
1
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions