Presentation is loading. Please wait.

Presentation is loading. Please wait.

Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”

Similar presentations

Presentation on theme: "Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”"— Presentation transcript:

1 Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”

2 Aalborg Media Lab 21-Jun-15 Lecture Overview Chapter 1.4 -1.6 of “Java Software Solutions” Slides and exercises can be found on:

3 Aalborg Media Lab 21-Jun-15 Java Fundamentals Java is a object oriented language Java is accompanied by the “Java standard library ” Java can be executed using the web Is constantly under development Chapter 1.4

4 Aalborg Media Lab 21-Jun-15 A simple Java Application //************************************************** //Application printing a single line in console //************************************************** class HelloDan { public static void main(String args[]) //entry point { System.out.println (“What’s the frequency Kenneth?”); }

5 Aalborg Media Lab 21-Jun-15 Java’s Structure Every Java application consists of class definitions In the Java programming language: –A program is made up of one or more classes –A class contains one or more methods –A method contains program statements A Java application always contains a method called main (entry point)

6 Aalborg Media Lab 21-Jun-15 Using Objects The System.out object represents a destination to which we can send output In the HelloDan program, we invoked the println method of the System.out object: System.out.println ("What’s the frequency Kenneth?"); object methodinformation provided to the method (parameters)

7 Aalborg Media Lab 21-Jun-15 Using Comments Comments allow programmers to communicate their thoughts independent of the code Serves as documentation, VERY IMPORTANT !! Comments are “inline documentation” // this is a single line comment /* This is a block comment */

8 Aalborg Media Lab 21-Jun-15 Identifiers and Reserved Words Language consists of identifiers –Words we make up –Words another programmer did choose (for example when using the Java standard library) –Reserved words Java is case sensitive –Class  start with capital letter –Methods  start with small letter

9 Aalborg Media Lab 21-Jun-15 Code Style Use descriptive names Make your code readable by using blank spaces and new lines (Listing 1.2 & 1.3)

10 Aalborg Media Lab 21-Jun-15 About languages All programs must be translated to machine language in order to be executed and each type of CPU has its own specific binary machine language (01101…) There are four programming language levels: –machine language –assembly language –high-level language –fourth-generation language Chapter 1.5

11 Aalborg Media Lab 21-Jun-15 Compiler & Interpreters 1/2 Compilers are small programs translating a language (source code) into another language (target language) Interpreters interweaves translation and execution (one line at a time)

12 Aalborg Media Lab 21-Jun-15 Compiler

13 Aalborg Media Lab 21-Jun-15 Java Using Compiler & Interpreter

14 Aalborg Media Lab 21-Jun-15 Syntax & Semantic The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program The semantics of a program statement define what that statement means (its purpose or role in a program) A program that is syntactically correct is not necessarily logically (semantically) correct A program will always do what we tell it to do, not what we meant to tell it to do

15 Aalborg Media Lab 21-Jun-15 Errors The compiler will find syntax errors and other basic problems (compile-time errors) –If compile-time errors exist, an executable version of the program is not created A problem can occur during program execution, such as trying to divide by zero, which causes a program to terminate abnormally (run-time errors) A program may run, but produce incorrect results, perhaps using an incorrect formula (logical errors)

16 Aalborg Media Lab 21-Jun-15 Environment JDK –compile and execute BlueJ (editor) –writing the code

17 Aalborg Media Lab 21-Jun-15 Compiling and Execution The JDK and a simple Editor (Notepad) are enough for coding, compiling and execution

18 Aalborg Media Lab 21-Jun-15 BlueJ Environment Java based development environment for Java BlueJ

19 Aalborg Media Lab 21-Jun-15 Object-Oriented Programming Object is fundamental entity in Java Developing software by defining objects that interact with each other OOP is mapping real life situations into a program –Mapping objects and their behavior Chapter 1.6

20 Aalborg Media Lab 21-Jun-15 Problem Solving Life cycle of program development –Understand the problem –Design a solution –Considering alternatives / refining –Implementing the solution –Testing / fixing / refining the solution

21 Aalborg Media Lab 21-Jun-15 Concepts/Terminology of OOP Object (real object of the problem domain) Attribute (characteristics of objects, state) Method (objects behavior) Class (objects are defined trough classes, concept) –Multiple object can be created from a class Encapsulation –Only object itself can change his state (manages itself) Inheritance –Reuse of class concepts for similar classes Polymorphism

22 Aalborg Media Lab 21-Jun-15 Inheritance Bank Account Account Charge Account Savings Account Checking Account One class can be used to derive another via inheritance Classes can be organized into inheritance hierarchies

23 Aalborg Media Lab 21-Jun-15 Exercises Use BlueJ for following exercises –JSS 1.1 –JSS 1.3 Try out the Hello application (BlueJ demos) –Add method stop, printing “Bye, world”.

Download ppt "Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”"

Similar presentations

Ads by Google