Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK."— Presentation transcript:

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

2 EE936 Lecture 1 Introducing Java

3 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?

4 An entirely hypothetical project scenario… Bunch of data Visualise Calculate 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.

5 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

6 Another entirely hypothetical project scenario… Extract features Pre-process Bunch 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.

7 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

8 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?

9 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

10 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

11 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’

12 What’s Special About Java?  Platform Independent  Automatic Garbage Collection  Object Oriented  Fully Featured  Objects and Syntax based around good programming practices

13 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

14 Using the Command Line

15 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

16 Command Line Commands: CD  CD - this tells you what the current directory is  CD - this changes directory to the named directory  CD.. - this changes directory to the directory immediately above

17 The Development Cycle Source File Build OK? Write/Edit Code Run in JVM Compile Using JAVAC Great. Do What you Expected? NO YES

18 // ----------------------------------------------------------- // ----------- 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 declaration of 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

19 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 ‘{‘ & ‘}’

20 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!"); }

21 Your First Java Application HelloMum! public class Lecture1Example1 { public static void main(String[] args) { System.out.println("Hello Mum!"); }

22 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.

23 Example 2 HelloMum! public class Lecture1Example2 { public static void main(String[] args) { System.out.print("Hello "); System.out.println("Mum!"); }

24 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

25 Example 3 HelloMum! public class Lecture1Example3 { public static void main(String[] args) { System.out.print("Hello "); System.out.print("Mum!"); System.out.println(); }

26 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

27 Example 4 Hello Mum! public class Lecture1Example4 { public static void main(String[] args) { System.out.println("Hello "); System.out.print("Mum!"); }

28 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

29 Example 5 HelloMum! 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("!"); }

30 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

31 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

32 Questions? Next 2 hours are Lab Time (work through the Eclipse tutorial and do the exercises provided)


Download ppt "EE936 Computer Technology and Modern Programming Concepts Dr B. Stephen Institute for Energy & Environment, University of Strathclyde Glasgow UK."

Similar presentations


Ads by Google