Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis...
-
Upload
jonas-harrison -
Category
Documents
-
view
214 -
download
0
Transcript of Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis...
![Page 1: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/1.jpg)
Jens Dalsgaard Nielsen
Jan Dimon BendtsenDept. of Electronic Systems
Basic Programming
INS-basis GF, PDP and HST
![Page 2: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/2.jpg)
Course Goals
• To understand the activity of programming
• To become familiar with computing environments, compilers etc.
• To be able to program, compile and run Java programs
• To be able to recognize (and fix) syntax and logic errors
• To be able to use computer programs as an engineering tool
![Page 3: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/3.jpg)
Prerequisites
• Computer savvy (file management, text editing)
• Problem solving skills
• Time management
• High school math (algebra, trigonometry)
• No prior programming background required
![Page 4: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/4.jpg)
Course Organization• Introduction to the course, getting started
• Tools, getting operational
• Classes and objects
• Program control
• Basic GUI programming
• Data structures
• File I/O
• Slightly less basic GUI programming
1)+10) Mini-project
![Page 5: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/5.jpg)
Examination
• “Mini-project” - at the end of the course, you write a program that: Satisfies a “requirement specification” posed by
the lecturers Demonstrates that you know how to program in
Java Demonstrates that you are able to use an
Integrated Development Environment (Eclipse)
• Individual examination (but it is OK to do the actual work in small groups)
![Page 6: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/6.jpg)
Chapter 1
Introduction to Java Programming
![Page 7: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/7.jpg)
What Is Programming?
• Computers are programmed to perform tasks
• Different tasks = different programs
• Program Sequence of basic operations executed in
succession Contains instruction sequences for all tasks it
can execute
• Sophisticated programs require teams of highly skilled programmers and other professionals
•
![Page 8: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/8.jpg)
Schematic Diagram of a Computer
Figure 5: Schematic Diagram of a Computer
![Page 9: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/9.jpg)
The Java Programming Language• Simple
• Safe
• Platform-independent ("write once, run anywhere")
• Rich library (packages)
• Designed for the internet
![Page 10: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/10.jpg)
An Integrated Development Environment
Figure 9:An Integrated Development Environment
![Page 11: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/11.jpg)
File HelloTester.java
1: public class HelloTester 2: { 3: public static void main(String[] args) 4: { 5: // Display a greeting in the console window 6: 7: System.out.println("Hello, World!"); 8: } 9: }
OutputHello, World!
![Page 12: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/12.jpg)
HelloTester in an IDE
Figure 12:Running the HelloTester Program in an Integrated Development Environment
![Page 13: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/13.jpg)
A Simple Program
Figure 13:Calling a Method
System ClassSystem.out Objectprintln Method
• public class ClassName • public static void main(String[] args) • // comment• Method call
![Page 14: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/14.jpg)
Syntax 1.1: Method Call
object.methodName(parameters)
Example: System.out.println("Hello, Dave!");
Purpose:To invoke a method of an object and supply any additional parameters
![Page 15: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/15.jpg)
Errors
• Syntax errors
• Detected by the compiler
• Logic errors
• Detected (hopefully) through testing
System.ouch.print(". . .");System.out.print("Hello);
System.out.print("Hell");
![Page 16: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/16.jpg)
The Compilation Process
Figure 14:From Source Code to Running Program
![Page 17: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/17.jpg)
Chapter 2
Using Objects
![Page 18: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/18.jpg)
Types and Variables
• Every value has a type
• Variable declaration examples:
• Variables Store values
Can be used in place of the objects they store
String greeting = "Hello, World!";PrintStream printer = System.out;int luckyNumber = 13;
![Page 19: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/19.jpg)
Types and Variables
• Every value has a type
• Variable declaration examples:
• Variables Store values
Can be used in place of the objects they store
String greeting = "Hello, World!";PrintStream printer = System.out;int luckyNumber = 13;
![Page 20: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/20.jpg)
Syntax 2.1: Variable Definition
typeName variableName = value; or typeName variableName;
Example: String greeting = "Hello, Dave!";
Purpose:To define a new variable of a particular type and optionally supply an initial value
![Page 21: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/21.jpg)
Identifiers
• Identifier: name of a variable, method, or class
• Rules for identifiers in Java: Can be made up of letters, digits, and the underscore
(_) character Cannot start with a digit Cannot use other symbols such as ? or % Spaces are not permitted inside identifiers You cannot use reserved words They are case sensitive
Continued…
![Page 22: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/22.jpg)
The Assignment Operator
• Assignment operator: =
• Not used as a statement about equality
• Used to change the value of a variable
int luckyNumber = 13; luckyNumber = 12;
Figure 1:Assigning a New Value to a Variable
![Page 23: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/23.jpg)
Uninitialized Variables
• Error:
Figure 2:An Uninitialized Object Variable
int luckyNumber;System.out.println(luckyNumber); // ERROR - uninitialized variable
![Page 24: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/24.jpg)
Syntax 2.2: Assignment
variableName = value;
Example: luckyNumber = 12;
Purpose:To assign a new value to a previously defined variable.
![Page 25: Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems Basic Programming INS-basis GF, PDP and HST.](https://reader030.fdocuments.net/reader030/viewer/2022032806/56649f0b5503460f94c1ed08/html5/thumbnails/25.jpg)
Summary Main goal: Programming as an Engineering
tool Examination: Mini-project Organization: Short(?) lectures and plenty of
programming at the PC Programming exercises are carried out in
Eclipse “Hello World” Variables are used for storing values, via
assignment; they are referred to using identifiers (names)