Programming for Beginners

Slides:



Advertisements
Similar presentations
Designing a Program & the Java Programming Language
Advertisements

CS105 INTRODUCTION TO COMPUTER CONCEPTS INTRO TO PROGRAMMING Instructor: Cuong (Charlie) Pham.
Chapter 1: Introduction
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
How to Create a Java program CS115 Fall George Koutsogiannakis.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Outline Java program structure Basic program elements
01 Introduction1June Introduction CE : Fundamental Programming Techniques.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 1: Getting Started by George Lamperti & BU Faculty.
Introduction to a Programming Environment
Programming Concepts and Languages Chapter 12 – Computers: Understanding Technology, 3 rd edition 1November
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Programming a computer. What does programming a computer mean ? Programming a computer: Since a computer can only execute machine instructions (encoded.
CS190/295 Programming in Python for Life Sciences: Lecture 1 Instructor: Xiaohui Xie University of California, Irvine.
Programming In C++ Spring Semester 2013 Programming In C++, Lecture 1.
CS102 Introduction to Computer Programming
1 Chapter-01 Introduction to Computers and C++ Programming.
CHAPTER 4: INTRODUCTION TO COMPUTER ORGANIZATION AND PROGRAMMING DESIGN Lec. Ghader Kurdi.
Introducing Java.
1 TOPIC 1 INTRODUCTION TO COMPUTER SCIENCE AND PROGRAMMING Topic 1 Introduction to Computer Science and Programming Notes adapted from Introduction to.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Hello World 2 What does all that mean?.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
CS 106 Introduction to Computer Science I 01 / 25 / 2010 Instructor: Michael Eckmann.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 13: An Introduction to C++
Programming With C.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Board Activity Find your seat on the seating chart Login – Remember your login is your first initial your last name and the last three numbers of your.
The Joy of Programming (also known as) Introduction to Object-Oriented Programming.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Fundamental Programming: Fundamental Programming K.Chinnasarn, Ph.D.
Fall 2006Slides adapted from Java Concepts companion slides1 Introduction Advanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Introduction to programming in the Java programming language.
Basic of Programming Language Skill Area Computer System Computer Program Programming Language Programmer Translators.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
JAVA Practical Creating our first program 2. Source code file 3. Class file 4. Understanding the different parts of our program 5. Escape characters.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
CS 106 Introduction to Computer Science I 01 / 22 / 2007 Instructor: Michael Eckmann.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
CS 177 Recitation Week 1 – Intro to Java. Questions?
ITP 109 Week 2 Trina Gregory Introduction to Java.
1 CSC160 Chapter 1: Introduction to JavaScript Chapter 2: Placing JavaScript in an HTML File.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Dept of Computer Science University of Maryland College Park
Working with Java.
Lecture 1 Introduction Richard Gesick.
CSCI-235 Micro-Computer Applications
Introduction to.
Java programming lecture one
CS190/295 Programming in Python for Life Sciences: Lecture 1
Hello World 2 What does all that mean?.
Comp1202: Building Better Programs
Programming Languages
Introduction CSC 111.
CS105 Introduction to Computer Concepts Intro to programming
Introduction to Computer Programming
Focus of the Course Object-Oriented Software Development
ICT Programming Lesson 1:
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Computer Programming-1 CSC 111
CS105 Introduction to Computer Concepts Intro to programming
Presentation transcript:

Programming for Beginners Lecture 1: Introduction: Program Structure & Java Syntax Martin Nelson Elizabeth FitzGerald

Aims & objectives of this course Write your own programmes in a procedural language Understand basic concepts such as procedural logic, variables, flow control, input and output principles Identify important programming concepts

Course website Course materials, exercises and useful web links can be found at: www.maths.nottingham.ac.uk/~pmzmn/GSTPFB.html

Session 1 - aims & objectives Appreciate how computer programs are constructed Understand the differences between: Compiled and interpreted languages Procedural and object-oriented languages Find out the basics of Java programming Write a few simple programs making use of statements, comments and basic arithmetic

Computer programmes Set of instructions for the CPU Assembly language “Switch settings” Machine language Assembly language Mnemonics representing binary code Assembler 3rd generation languages “High level” languages Compiled or interpreted (or both!)

High Level Languages (3GL) Examples: Fortran COBOL Pascal C C++ C# Java

Program construction Computers are 'stupid' Mathematical and logical instructions are executed very quickly and accurately They obediently but stupidly do what you tell them to – not necessarily what you want them to! Tiny errors in a program can cause major problems when it is executed Careful planning is essential Flow charts are a useful tool to represent program flow visually

Algorithms Algorithm = how you go about solving a puzzle; your solution to a task Example: how do you make a cup of tea? In programming, you should plan your algorithm before you start coding Boil kettle Put tea in cup Pour boiling water into cup

Tea-making program – 1 Is kettle full? Fill kettle Boil kettle No Is kettle full? Fill kettle Yes Boil kettle Put tea in cup Pour boiling water into cup

Elements of tea-making program Fill kettle Open tap Wait Is kettle full? Yes No Close tap Place kettle under tap Has kettle boiled? Pour water into cup Boil kettle Switch kettle on Wait No Yes Plug kettle into electrical socket

Tea-making program – 2 Is kettle full? Put tea in cup No Yes Pour boiling water into cup

Now for some jargon… Compiled vs interpreted languages (… but don’t worry about this too much  ) Compiled vs interpreted languages Handy hint: If you’re not sure what these and other words mean, look at the ‘Glossary’ section of the course website

Compiled languages Data storage Source code Machine code CPU/memory Compiler Program execution

Interpreted languages Data storage Source code CPU/memory Interpreter Machine code Program execution

Compiled vs interpreted Development more cumbersome Easy to distribute Machine code generated at compile time e.g. most high-level languages Interpreted Easy to develop Distribution of interpreter required Machine code generated at runtime e.g. BASIC, LISP, Perl

The Java model Java is an object-oriented high level language "write once, run anywhere" It is both compiled and interpreted Java source code has .java extension Source code is compiled to produce a .class file (bytecode) – not human-readable Bytecode is interpreted by the Java VM (virtual machine)

How Java works Data storage CPU/memory Interpreter Compiler Bytecode myprogram.class Source code myprogram.java CPU/memory Interpreter Compiler Machine code Program execution

A bit more jargon… Procedural vs object-oriented programmes (… nearly finished though  ) Procedural vs object-oriented programmes What is all this object-oriented stuff about? Does it matter? Does it mean anything?

Procedural vs object-oriented Early high-level languages Contain functions (or sub-routines) written and used inside the main program Cannot use external functions easily Object-oriented (OO) Later high-level languages Contain methods (or functions) and variables that can be written in main or external programs Can call external functions or variables easily

Some examples Procedural Fortran COBOL (old versions) Pascal C Perl Object-oriented (OO) COBOL (latest version) Delphi C++ C# Java Visual Basic Perl

What’s Java all about then? NOT the same as JavaScript Java SDK consists of 2 components: Java VM (Virtual Machine) Java API (Application Programming Interface) + accompanying documentation If you alter your code you need to re-compile it before you can run the program ONLY use Java version 2 and above (Java 1.2/Java 1.3/Java 1.4 etc)

On with the code! Quick intro to using Java Then YOU start to code your first Java program!

Writing your first Java program Use a text editor to write the source code Save it as a .java file Compile it using Java SDK on Granby You need to have a Granby account before you can start writing your programs – if you haven't you will need to apply for one as soon as possible!

'Hello world' program in Java class myprog { public static void main(String[] args) System.out.println(“Hello world!”); }

Be careful what you type! If you type something wrong, your code will either give you an error or won’t work properly. If you get an error, check the following: Capital letters are different to lower case – don’t mix them up. { }, ( ) and [ ] all do different things – have you used the right one? Some lines need to end with a semi-colon – miss them off and your code won’t work.

Code Presentation Tips – 1 Indent code inside curly braces Every time you open a pair of curly braces, indent the next line by 1 tab or three/four spaces. When you close braces, unindent. You can then see straight away if you have a brace missing. class myprog { Some code Some more code New braces, so indent again. } More code

Code Presentation Tips – 2 You can add comments to your code to remind you (or someone else) how the code works. Comments are ignored by the compiler. On a single line, anything after // will be ignored. Over many lines, anything between /* and */ will be ignored. /* This is my first java code * I really enjoyed writing it – I hope you like it */ class myprog { public static void main(String[] args) // The following line will say hello System.out.println(“Hello!”); }

Code Presentation Tips – 3 Comments should be brief and helpful. No need to add comments which state the obvious. Blank lines help to make the code readable – use them to separate each of the code’s tasks.

Coming up in Session 2... Using variables to store information. An introduction to the range of data types available.