1 / 25

Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems

Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems. Basic Programming INS-basis GF, PDP and HST. Course Goals. To understand the activity of programming To become familiar with computing environments, compilers etc. To be able to program, compile and run Java programs

Download Presentation

Jens Dalsgaard Nielsen Jan Dimon Bendtsen Dept. of Electronic Systems

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jens Dalsgaard NielsenJan Dimon BendtsenDept. of Electronic Systems Basic ProgrammingINS-basis GF, PDP and HST

  2. Course Goals • To understand the activity of programming • To become familiar with computing environments, compilers etc. • To be able to program, compile and run Java programs • To be able to recognize (and fix) syntax and logic errors • To be able to use computer programs as an engineering tool

  3. Prerequisites • Computer savvy (file management, text editing) • Problem solving skills • Time management • High school math (algebra, trigonometry) • No prior programming background required

  4. Course Organization • Introduction to the course, getting started • Tools, getting operational • Classes and objects • Program control • Basic GUI programming • Data structures • File I/O • Slightly less basic GUI programming • +10) Mini-project

  5. Examination • “Mini-project” - at the end of the course, you write a program that: • Satisfies a “requirement specification” posed by the lecturers • Demonstrates that you know how to program in Java • Demonstrates that you are able to use an Integrated Development Environment (Eclipse) • Individual examination (but it is OK to do the actual work in small groups)‏

  6. Chapter 1Introduction to Java Programming

  7. What Is Programming? • Computers are programmed to perform tasks • Different tasks = different programs • Program • Sequence of basic operations executed in succession • Contains instruction sequences for all tasks it can execute • Sophisticated programs require teams of highly skilled programmers and other professionals

  8. Schematic Diagram of a Computer Figure 5: Schematic Diagram of a Computer

  9. The Java Programming Language • Simple • Safe • Platform-independent ("write once, run anywhere") • Rich library (packages) • Designed for the internet

  10. An Integrated Development Environment Figure 9:An Integrated Development Environment

  11. File HelloTester.java 1:public class HelloTester 2: { 3:public static void main(String[] args) 4: { 5:// Display a greeting in the console window6:7: System.out.println("Hello, World!"); 8: } 9: } Output Hello, World!

  12. HelloTester in an IDE Figure 12:Running the HelloTester Program in an Integrated Development Environment

  13. A Simple Program • public class ClassName • public static void main(String[] args) • // comment • Method call Figure 13:Calling a Method System Class System.out Object println Method

  14. Syntax 1.1: Method Call object.methodName(parameters)‏ Example:  System.out.println("Hello, Dave!"); Purpose: To invoke a method of an object and supply any additional parameters

  15. Errors • Syntax errors • Detected by the compiler • Logic errors • Detected (hopefully) through testing System.ouch.print(". . .");System.out.print("Hello); System.out.print("Hell");

  16. The Compilation Process Figure 14:From Source Code to Running Program

  17. Chapter 2Using Objects

  18. Types and Variables • Every value has a type • Variable declaration examples: • Variables • Store values • Can be used in place of the objects they store String greeting = "Hello, World!";PrintStream printer = System.out;int luckyNumber = 13;

  19. Types and Variables • Every value has a type • Variable declaration examples: • Variables • Store values • Can be used in place of the objects they store String greeting = "Hello, World!";PrintStream printer = System.out;int luckyNumber = 13;

  20. Syntax 2.1: Variable Definition typeName variableName = value; ortypeName variableName; Example:   String greeting = "Hello, Dave!"; Purpose: To define a new variable of a particular type and optionally supply an initial value

  21. Identifiers • Identifier: name of a variable, method, or class • Rules for identifiers in Java: • Can be made up of letters, digits, and the underscore (_) character • Cannot start with a digit • Cannot use other symbols such as ? or % • Spaces are not permitted inside identifiers • You cannot use reserved words • They are case sensitive Continued…

  22. The Assignment Operator • Assignment operator: = • Not used as a statement about equality • Used to change the value of a variableint luckyNumber = 13; luckyNumber = 12; Figure 1:Assigning a New Value to a Variable

  23. Uninitialized Variables • Error: int luckyNumber;System.out.println(luckyNumber);   // ERROR - uninitialized variable Figure 2:An Uninitialized Object Variable

  24. Syntax 2.2: Assignment variableName = value; Example: luckyNumber = 12; Purpose: To assign a new value to a previously defined variable.

  25. Summary • Main goal: Programming as an Engineering tool • Examination: Mini-project • Organization: Short(?) lectures and plenty of programming at the PC • Programming exercises are carried out in Eclipse • “Hello World” • Variables are used for storing values, via assignment; they are referred to using identifiers (names)‏

More Related