Professional Documents
Culture Documents
SD Lecture p1.1
SD Lecture p1.1
15/11/2021
PROGRAMMING LINE OVERVIEW
Week 1 Week 2 Week 3
Values and variables Classes and objects Interfaces and Inheritance
Control flow Testing Subtyping
Security 1
Week 4 Week 5 Week 6
Arrays and Lists Stream I/O and MVC Concurrency
List implementations Exceptions Project kick-off
Collections Security 2 IDE Tips & Tricks
Week 7 Week 8/9 Week 10
Basic Networking Advanced Java facilities Project
Networking and Test Test resit
Multithreading
GUIs
2
MODULE 2 PROGRAMMING THIS WEEK
3
P1.1 Values and Variables
‘HELLO WORLD’ IN PYTHON
4
P1.1 Values and Variables
HELLO WORLD IN JAVA
File: ss/week1/Hello.java Usage
Usage
5
P1.1 Values and Variables
LINEAR SEARCH IN PYTHON VS. JAVA
SPOT THE DIFFERENCES!
Python Java
3 4
2
5 6 7 8
9
10
6
P1.1 Values and Variables
DIFFERENCES!
Conceptually the same!
1. Surrounding class declaration
2. Visibility modifiers (public, private)
3-5. Explicit data types (return, method variables and local
variables)
6. length as an attribute instead of a method
7. && instead of and
8. ( ) condition delimitation instead of :
9. { } block delimitation instead of indentation
10. ; statement separators instead of newline
7
P1.1 Values and Variables
JAVA PROGRAM
§ Sequence of instructions
Bootstrapping
§ In Java, to start a program the JVM is called with a reference
to a class that has a main method (main class)
§ Sequences of instructions are then called in the order in which
they are declared in the body of main method (between { and })
§ Comments after // (single line) or between /* and */ (many
lines)
9
P1.1 Values and Variables
VARIABLES
10
P1.1 Values and Variables
VARIABLES
In Java
int count;
declaration count = 10;
assignment
In memory
count 10
reference value
11
P1.1 Values and Variables
EXPRESSIONS
isOK true
13
P1.1 Values and Variables
SUBROUTINES (JAVA METHODS)
DIVIDE AND CONQUER!
14
P1.1 Values and Variables
STRINGS
JAVA STRING API
• Some functions:
• int s1.length(): returns length of s1
• boolean s1.equals(s2): returns true if s1 and s2 are the same String
• char s1.charAt(n): returns char value in position n (first position 0!)
15
P1.1 Values and Variables
AUTOBOXING & UNBOXING
16
P1.1 Values and Variables
TEXTUAL OUTPUT
Example
• System.out.printf("Formatted string: %8d %.3f %c %s", x , y, c, s)
String
left aligned with 8 positions
3 digits after comma character
17
P1.1 Values and Variables
TEXT IO LIBRARY
USED IN THE LAB SESSIONS
18
P1.1 Values and Variables
CONSTANTS
‘VARIABLE’ WITH VALUES THAT CANNOT BE CHANGED
• constants
19
P1.1 Values and Variables
TAKE HOME MESSAGES
20
P1.1 Values and Variables