100% tevredenheidsgarantie Direct beschikbaar na betaling Zowel online als in PDF Je zit nergens aan vast
logo-home
Programming (2IP90) Summary 2019 €3,99
In winkelwagen

Samenvatting

Programming (2IP90) Summary 2019

 6 keer verkocht

EN: Programming (2IP90) is a course given at Eindhoven University of Technology. This course is mandatory for Bachelor Computer Science and Engineering students. It is a good introduction to a necessary skill. Programming teaches students how to program using the programming language Java. It sho...

[Meer zien]
Laatste update van het document: 4 jaar geleden

Voorbeeld 2 van de 46  pagina's

  • 28 mei 2020
  • 1 september 2020
  • 46
  • 2019/2020
  • Samenvatting
Alle documenten voor dit vak (1)
avatar-seller
IsabelRutten
2019 Q1 Programming Summary
Running a Java program: (1) type the text with at least 1 class (2) save file with name class
(3) compile file (checks for errors) (4) run the class file.
For naming things, use CamelCase(start each new word in a name with an uppercase letter)
Types of rules: (1) syntax (grammar) (2) semantic (meaning) (3) conventions (wise advice)

Topic How to write it in Java What it means
How to make a public class <nameClass> { This is the class declaration and is at the beginning of
program <statements> } every source code, it contains the whole program.
void <method>() { <statements> } Method declaration, it contains the activity of the
program.
System.out.println(“<text>”); Gives output and newline statement
public static void main(String[] args) { This is at the end of your program. The first part
new <class>().<method>(); } marks the start-up code and the second part creates
an active object from the class and starts the method.
Numeric/ int <name variable>; This creates a variable that is a integral number. Use
primitive data CamelCase but start with a lower case letter. Values:
types …, -1, 0, 1, … . Operations: +, -, *, /, %. E.g. (17+4)/2
gives 10. Equality by x==y, inequality by x!=y
Double <name variable>; This creates a variable that is a floating point number.
Values: … , -0.5, …, 0.7, … . (in)equal: see int.
Operations: +, -, *, / E.g. (17.0+4.0)/2.0 gives 1.5
Arithmeric 5 * 2 gives 10 Multiplication
operators (on Int: gives 2. D: 5. gives 2.5 Integer division (ordinary division)
numeric types) 1 + 1 gives 2. “1” + “1” gives “11” Arithmetic addition (string concatenation)
5 – 2 gives 3. – (5 - 2) gives -3 Subtraction (minus)
10 % 5 gives 0. 7 % 5 gives 2 Remainder or modulo (rest bij deling)
Math.pow(x,y) Machtsverheffen (x^y)
Textual data char <name variable>; This creates a variable that is a single character.
types Values: ‘a’, ‘0’, ‘?’, … . No operations!
String <name variable>; This creates a variable that has sequences of
characters (also “a”!). Values: “seven”, “a”, …
Operations: +, … E.g. “seven” + ”teen” gives
“seventeen”. Equal identity: x==y.
To compare strings, use “<String>”.equals(“...”).
To look at the alphabetical ordering, use
“<String1>”.compareTo(“<String2>”).
0: same place, -1: String1 is closer to beginning than
String2, 1: vice versa.
“<String>”.length() gives the number of characters.
“<String>”substring: gives subsequence by position
(e.g.“Building”.substring(1,4) → “uil”)
“<String>”.indexOf(“…”):gives position of substring
(e.g. “Building”.indexOf(“uil”) → 1)
Data type boolean <name variable>; This creates a variables that can evaluate to true or
Boolean false, depending on the input. Values: true, false
Operations: && (logical and), || (inclusive or),
! (logical not), ^ (exclusive or), == (equality)




1
By Isabel Rutten

, 2019 Q1 Programming Summary
Comparison 5 +7 == Comparing all primitive types (int, double, Boolean)
operators gives a true or false, it’s a Boolean value.
<string1>.equals(<string2>) Comparing String types (DON’T USE ==)




Scanner Input import java.util.Scanner; The user can insert values which can be used in the
class <name> { program by applying a scanner. Here, you can see all
Double amount; the necessary parts of using a scanner.
This: Scanner = new When no input is available, the scanner waits for
Scanner(System.in); input.
Public void <method>() { “scanner” can also be replaced by another word.
amount = scanner.nextDouble(); } Variants of “scanner.nextDouble()” (which reads the
Or like this: Scanner; next Double & stores it) are “scanner.nextInt()” (for
Public void <method>() { integers), “scanner.next()” (for Strings/a word),
scanner = new Scanner(System.in); “scanner.nextLine()” (for lines (whole line=String)).
amount = scanner.nextDouble; } It is also possible to “read” whether there even is a Int
or a Double with “scanner.hasNext()” (e.g.
scanner.hasNextDouble() checks for Doubles). These
statements will return “true” or “false.
If-construct if ( condition ) { The if-construct is used to execute statements only
... then-part when the condition is true, uses Boolean expressions.
} else { Here you can see the if-else construct.
... else-part If you leave out the part in bold, you have a if-
} construct with one branch only.
if ( A ) { Here you can see the if-else if construct.
... executed if A is true
} else if ( B ) {
... executed if B is true and A is not
true
} else if ( C ) {
... executed if C is true and neither A
nor B are true
} else {
... executed if A nor B nor C is true
}
if ( A1 ) { Here you can see the usage of nesting. This is hard to
if ( B1 ) { manage so it is better not to use it!
... A1 true and B1 true If you do, try to figure out what each branch means:
} else { this way you can avoid errors.
... A1 true and B1 false
}
} else {
if ( B2 ) {
... A1 false and B2 true
} else {
... A1 false and B2 false
}}




2
By Isabel Rutten

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 IsabelRutten. Stuvia faciliteert de betaling aan de verkoper.

Zit ik meteen vast aan een abonnement?

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

Is Stuvia te vertrouwen?

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

Afgelopen 30 dagen zijn er 75282 samenvattingen verkocht

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

Start met verkopen
€3,99  6x  verkocht
  • (0)
In winkelwagen
Toegevoegd