+ All Categories
Home > Documents > 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

Date post: 21-Dec-2015
Category:
View: 217 times
Download: 0 times
Share this document with a friend
Popular Tags:
21
01 Introduction 1 31 Mar 2022 01 Introduction CE00858-1: Fundamental Programming Techniques
Transcript
Page 1: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 118 Apr 2023

01 Introduction

CE00858-1: Fundamental Programming Techniques

Page 2: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 218 Apr 2023

Objectives

In this session, we will:• review the structure of the module • introduce the Java programming language• develop a simple Java application

Page 3: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 318 Apr 2023

Introduction to module

• focus on developing applications using Java • each week you are expected to attend

• 2 lectures – to receive new concepts about programming

• 2 tutorials – to practice the new concepts in Java

• weekly sessions:• presented with new material• opportunity to practise new skills• ask for help with problems• exercises to complete

Page 4: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 4

Emphasis on learning• your goal is to learn about programming• our goal is to help you learn

• you have many resources to help achieve your goal

• lecturers – ask them many questions• lecture materials – use them often• tutorial exercises – aim to do them all• Blackboard, books, and the Internet

• take time to learn• 150 hours for this module• 48 hours in class – lectures and tutorials• 102 hours out of class

• finish the tutorial exercises each week; don’t get behind• read books and web sites about Java

18 Apr 2023

Page 5: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 5

Programmingis a

practical skillthat is

masteredby

doing it,not just

reading about it!

18 Apr 2023

Page 6: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 618 Apr 2023

Assessment

• 100% coursework• exercises build into portfolio

• your responsibility to:• attempt as many exercises as possible• include in your portfolio what is indicated in

specification• keep portfolio up-to-date

• 3 in-class tests • using Blackboard• questions about material presented in lectures• questions about your portfolio• you will need your electronic portfolio available

Page 7: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 7

Your portfolio

• your portfolio will need to be on electronic media• use the H: drive or a pen drive• make sure you organise and index your work• you will need to refer to it quickly and easily in the

tests• make sure you have a back-up

• tutorial worksheets indicate what to include• do as many tutorial exercises as possible• you will not know which exercises will feature in the

in-class tests

18 Apr 2023

Page 8: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 818 Apr 2023

Introduction to Java

• high level object oriented programming language

• designed to be:• simple• object oriented• distributed• robust• secure• architecture-neutral• portable• multithreaded

Page 9: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 9

What is computer programming?

• writing solutions to problems in a language that the computer can understand and execute

• several stages:• identify the problem

• understand the problem – analysis

• describe the solution - design

• write the solution in a programming language - coding

• evaluate the solution and improve it if necessary - testing

18 Apr 2023

Page 10: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 10

Programming lifecycle

Identify problem

Understand the problem

Describe the solution

Program the solution

Test the program

18 Apr 2023

Page 11: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1118 Apr 2023

Program development stages

Write / edit source code

Compile source code into bytecode(computer understandable form)

Run program (bytecode)

javac

java

Hello.java

Hello.class

Results on screen

syntax errors

logic errors

Page 12: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1218 Apr 2023

A Simple Java Application

//output Hello Worldpublic class Hello{ public static void main (String[] args) { System.out.println ("Hello World"); System.out.println ("Welcome to Java"); }}

Comment - ignored when program runs

this line is always written like this

output a message to console window

class name

Page 13: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1318 Apr 2023

Write source code

• program can be written using any simple editor • can use Notepad, Wordpad• source file must be saved with an extension

of .java

File name has the form:<classname>.java

Page 14: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1418 Apr 2023

Source code structure

• the first line is a comment indicated by //• comments are ignored when the program is executed• all Java code must be in a class• every class has:

• a header that names it• a body enclosed by { } that defines what it does

• code must be saved in a file called Hello.java

public class Hello{ //all code must be placed inside the braces}

Class header

Class body

Page 15: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1518 Apr 2023

The main method

• classes are made up of at least one method • all Java applications have a main method• automatically run when the program is executed• contains statements to perform a task• every method has:

• a header that names it• a body enclosed by { } that defines what it does

public static void main (String[] args){ //all code must be placed inside the braces}

Method header

Method body

Page 16: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1618 Apr 2023

Program statements

• the main method contains statements• each statement is terminated with ;

System.out.println ("Hello World");System.out.println ("Welcome to Java");

• these statements are method calls to the println method which is found in the System.out class

• all method calls are followed by parameters enclosed by ( )

• brackets must be included even if there are no parameters

• the println method has a string parameter which will be output

• strings are enclosed by ""

Class bodySemicolons

Page 17: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1718 Apr 2023

Pitfalls - programming

• Java is case sensitive• Hello and hello are not the same• main and Main are also different

• every statement finishes with ;• headers are not statements – so no ;• program blocks are bracketed using { }• method names are always followed by ( )• strings are enclosed by ""

• compilers are very fussy – you must be accurate

Page 18: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1818 Apr 2023

Compiling a Java application

• Java source code is in a human-readable format

• compiler:• checks that code is grammatically correct• converts valid code into bytecode which can be

executed by the computer if there are no errors• produces a .class file if there are no errors

• Sun provide a compiler called javac• invoked from the command prompt• javac Hello.java

• any errors will be displayed in window• no output means no errors

Page 19: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 1918 Apr 2023

Executing a Java application

• bytecode is executed using interpreter provided by Sun

• invoked from the command prompt• java Hello

Page 20: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 2018 Apr 2023

Pitfalls – compiling and running

• file name must be same as class name in code with .java as the extension• public class Hello• filename Hello.java

• the extension must be specified when file is compiled:• javac Hello.java

• the extension must NOT be specified when the class is interpreted• java Hello

Class name

File name

Page 21: 01 Introduction1June 15 01 Introduction CE00858-1: Fundamental Programming Techniques.

01 Introduction 2118 Apr 2023

Summary

In this session we have:• covered the module assessment requirements• looked at the structure of a Java application• introduced the main method• seen how to output strings to the screen• written, compiled and executed a Java application

In the next session we will:• look at using data within our programs


Recommended