+ All Categories
Home > Documents > EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy &...

EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy &...

Date post: 14-Dec-2015
Category:
Upload: gretchen-tibbals
View: 215 times
Download: 2 times
Share this document with a friend
Popular Tags:
32
EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK
Transcript
Page 1: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

EE936 Computer Technology and Modern Programming Concepts

Dr B. Stephen

Institute for Energy & Environment,University of Strathclyde

Glasgow UK

Page 2: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

EE936 Lecture 1

Introducing Java

Page 3: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Why Program?

Put your ideas into practice without the constraints of high level and/or third party tools:

File formats

Processing limitations

Output visualisation

Do you need any other reason?

Page 4: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

An entirely hypothetical project scenario…

Bunch of

data

VisualiseCalculate statistics

Pre-process

Take this data (yes, all 500m records)

and…

…throw away values

that are more than 3

days old and…

…calculate higher order (not mean and variance) moments and cumulants

(what?!!?) then…

…do a time series 3D scatter plot with vector overlays. Do it again tomorrow.

Page 5: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

An entirely hypothetical project scenario (made real)…

‘Bunch of data’ could be:

Windspeed and air temperature/pressure for every weather station in the UK at 10 second intervals every day this century

‘Pre-Process’ could be:

Downsample the data to an hourly average

‘Calculate statistics’ could be:

Extract max/min temp and wind speed variance

‘Visualise’ could be:Vector diagram overlaid on contour plot

Page 6: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Another entirely hypothetical project scenario…

Extractfeatures

Pre-processBunch

of documents

Bunch of

data

Take these document

s and…

…ensure they’re in the right format…

…take only parameters A, B and C

and…

…put it into a relational database.

Do it again in 5 minutes.

Page 7: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Another entirely hypothetical project scenario (made real again)…

‘Bunch of documents’ could be:

Satellite Images

Fault Recorder Data

Substation Maintenance Reports

‘Pre-Process’ could be:

Get rid of the ones with clouds

Average current levels

Validate report fields

‘Extract features’ could be:

Retain areas over land only (cut out areas of water)

Calculate current variance

Put reports into bins according to keywords used

Try doing that by hand – digital acquisition of data has lead to enormous data archives that need automated (and usually specialised) processing

Page 8: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Project Work Pitfalls

Could do this manually in Excel but:

Time consuming and labour intensive

Scope for human error

Can Excel do everything you need it to?

Limit on the number of rows…

Could possibly do this in Matlab

Automation still tricky

Do you have a Matlab license? ($$$’s…)

Can you deploy your solution everywhere?

Page 9: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Why Program in Java?

More functional than C and FORTRAN

Easier than C++

Not tied to a specific platform unlike C#

More widely available than Smalltalk, Ruby, Eiffel and Dylan

Still in widespread use 12 years after its first appearance

Page 10: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What this course will do for you:

Prepare you for project work

Show you how to build useful applications that may support future coursework

Introduce the basic concepts of Object Oriented Programming

Allow you to put your existing knowledge (as an Engineer) into practice

Page 11: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What this course won’t do for you:

Teach you how to manage software development projects

Teach you how to write Java Applets, Servlets or Spotlets

Although you will get the foundation knowledge to go ahead and pursue this yourself

Teach you ‘how to make Web pages’

Page 12: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What’s Special About Java?

Platform Independent

Automatic Garbage Collection

Object Oriented

Fully Featured

Objects and Syntax based around good programming practices

Page 13: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Developing Java Applications

You’ll need a text editor such as:

Forte

JBuilder

MS Wordpad (which we’ll look at)

JEdit (which we’ll not use)

Eclipse (which you can use if you want)

And a copy of the Java Development Kit (try to use the latest version wherever possible)

The Lab PCs have all we need to get started

Page 14: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Using the Command Line

Page 15: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Command Line Commands: DIR

DIR - lists the contents of the current directory and emits its path

DIR /P - as with DIR but only a page at a time

DIR *.exe - only lists exe files in the current directory

Page 16: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Command Line Commands: CD

CD - this tells you what the current directory is

CD <path> - this changes directory to the named directory

CD .. - this changes directory to the directory immediately above

Page 17: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

The Development Cycle

SourceFile

Build OK?

Write/Edit Code

Run in JVM

Compile Using JAVAC

Great.

Do What you Expected?NO

NO YES

YES

Page 18: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

// ----------------------------------------------------------- // ----------- EE936 Computer Technology & Modern ------------ // ------------------ Programming Concepts ------------------- // ----------------------------------------------------------- // Lecture 1, Example 1: The simplest program you can possibly // write in Java. // Version 1: 26th September 2005 // Version 2: 28th September 2006 // Version 3: 17th September 2007 // Author: Bruce Stephen // ----------------------------------------------------------- // -----------------------------------------------------------

public class Lecture1Example1 { public static void main(String[] args)

{ System.out.println("Hello Mum!"); }

}

Anatomy of a Java Program

The bodies of all classes

are encapsulated in

curly brackets

This is a comment. It does nothing

in any program.

Every time a statement is made

it must be terminated by a semi-colon

This is the declarationof your one and only public class

This is the method name

This is the method

argument

This is a method declaration

The bodies of all methods are enclosed

in curly brackets

Page 19: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Anatomy of a Java Program

Must have ONE public class per file

Must have the same filename as the public class name

Only ONE public class must have a method that is called ‘main’

‘main’ must be declared as shown

Method and class bodies must follow declarations and be enclosed in ‘{‘ & ‘}’

Page 20: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What is a Method?

A method is some code that carries out a task whenever it is called

This way you can repeat that task just by calling the method

Methods take inputs known as

arguments (more about this later)

public static void main(String[] args) { System.out.println("Hello

Mum!"); }

Page 21: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Your First Java Application

H e l l o M u m !

public class Lecture1Example1 { public static void main(String[] args)

{ System.out.println("Hello Mum!"); }

}

Page 22: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What does Example 1 do?

The program has a public class called Lecture1Example1

The main method of the program writes an inane message to the command line, takes a new line then exits

That’s all it does.

Page 23: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Example 2

H e l l o M u m !

public class Lecture1Example2 { public static void main(String[] args)

{ System.out.print("Hello "); System.out.println("Mum!"); }

}

Page 24: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What does Example 2 do?

Same inane message - different way of delivering it

This time we use the method print to output some text

We then output some more text and take a new line as before using println

Both print and println belong to an object already provided called System.out

Page 25: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Example 3

H e l l o M u m !

public class Lecture1Example3 { public static void main(String[] args)

{ System.out.print("Hello "); System.out.print("Mum!"); System.out.println(); }

}

Page 26: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What does Example 3 do?

Same as the last one! But done differently again…

Again we use the print and println methods in System.out but we gave them different arguments

Page 27: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Example 4

H e l l o

M u m !

public class Lecture1Example4 { public static void main(String[] args)

{ System.out.println("Hello "); System.out.print("Mum!"); }

}

Page 28: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What does Example 4 do?

Ha! Not exactly the same this time - each word is printed on its own line

The choice of method, arguments and the order the method is called dictates what the program does

Page 29: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Example 5

H e l l o M u m !

public class Lecture1Example5 { public static void main(String[] args)

{ System.out.print("H"); System.out.print("e"); System.out.print("l"); System.out.print("l"); System.out.print("o"); System.out.print(" "); System.out.print("Mum"); System.out.println("!"); }

}

Page 30: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What does Example 5 do?

Back to the same thing: inane message on one line but notice the labour intensive way we have achieved it this time

Again this serves to show how what method you call and when you call it affects your programs behaviour

Page 31: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

What you should now know…

How to use the windows command line

How to navigate the Windows file system using cd and dir

The anatomy of a simple Java program

What to call your source files

What method you should always have in at least one of your classes

What your source files should always contain

How to build Java programs using javac.exe

How to run Java programs using java.exe

How to write to the command line window in a Java application

Page 32: EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK.

Questions?

Next 2 hours are Lab Time(work through the Eclipse tutorial and do the

exercises provided)


Recommended