1 CSC 201: Computer Programming I B. S. Afolabi. Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm.

Slides:



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

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Hello, world! Dissect HelloWorld.java Compile it Run it.
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Day 4 Objectives Constructors Wrapper Classes Operators Java Control Statements Practice the language.
Java Software Solutions Lewis and Loftus Chapter 2 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Software Concepts -- Introduction.
Introducing Java.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
CSC204 – Programming I Lecture 4 August 28, 2002.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Introduction to Computer Systems and the Java Programming Language.
JAVA BASICS: Variables and References SYNTAX, ERRORS, AND DEBUGGING.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
Lecture 8 February 29, Topics Questions about Exercise 4, due Thursday? Object Based Programming (Chapter 8) –Basic Principles –Methods –Fields.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Introduction to Java Java Translation Program Structure
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
Lecture 6: Midterm Review Tami Meredith. Programming Process How do we fill in the yellow box? Text Editor Compiler (javac) Interpreter (JVM: java) User.
Final Jeopardy Fundamen tal Java Numerical Data type Boolean Expressi on If/THEN/ WHILE Miscellan eous
By Mr. Muhammad Pervez Akhtar
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
COP 2551 Introduction to Object Oriented Programming with Java Topics –Introduction to the Java language –Code Commenting –Java Program Structure –Identifiers.
 2003 Prentice Hall, Inc. All rights reserved. 1 Basic C++ Programming.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Programming for Interactivity Professor Bill Tomlinson Tuesday & Wednesday 6:00-7:50pm Fall 2005.
David Streader Computer Science Victoria University of Wellington Copyright: David Streader, Victoria University of Wellington Java Programing Basics COMP.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Eastside Robotics Alliance / Newport Robotics Group 1 T/Th, 6:30 – 8:30 PM Big Picture School Day 3 · 10/9/2014.
Introduction to java (class and object). Programming languages: –Easier to understand than CPU instructions –Needs to be translated for the CPU to understand.
Midterm preview.
Information and Computer Sciences University of Hawaii, Manoa
Lecture 1b- Introduction
The need for Programming Languages
Dept of Computer Science University of Maryland College Park
Yanal Alahmad Java Workshop Yanal Alahmad
Java Primer 1: Types, Classes and Operators
Yanal Alahmad Java Workshop Yanal Alahmad
Lecture 2: Data Types, Variables, Operators, and Expressions
Statements, Comments & Simple Arithmetic
Starting JavaProgramming
An Introduction to Java – Part I, language basics
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
COM-152: Computer Programming Types, Variables, Operators Part 1 of 2
Chapter 2 Programming Basics.
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Lecture 13 Introduction to High-Level Programming (S&G, §§7.1–7.6)
In this class, we will cover:
General Computer Science for Engineers CISC 106 Lecture 03
Presentation transcript:

1 CSC 201: Computer Programming I B. S. Afolabi

Introduction  3 unit course  2 hours of lecture/week Thursdays 4.00pm – 6.00pm Mondays 4.00pm – 6.00pm  3 hours of practical/week To be determined next week Course Lecturers: 2 Dr. A. O. Ajayi Dr. F. O. Asaiah Mrs. H. O. Odukoya Dr. B. S. Afolabi (Coordinator) Dr. P. A. Idowu Dr. A. R. Iyanda Mr. I. P. Gambo Mr. Okegbile Miss Lawal

Textbooks  No textbook is required  For programming beginners: Java Software Solutions: Foundations of Program Design, John Lewis and William Loftus, Publisher: Addison Wesley, 2002  For experienced programmers: — Learning the Java TM Language at / / — Thinking in Java, Bruce Eckel, Prentice Hall

Software is required  Download Java onto your home machine  /index.html /index.html  Follow the instructions to install it  Then, follow the instructions to install Eclipse 

Functional versus imperative languages  Functional languages are ideal for expressing the functional (the problem to be solved) component of any problem however...  at least 50% of all programs deal with input/output rather than a problem and functional languages aren’t very good at input/output.  Think of the programs you use now: editor mail language translator() web browser  Functional programming should have taught you to appreciate concise elegant programs.

The Computer Central Processing Unit (CPU) Memory Input / Output Devices

CPU Instructions z = x + y Read location x Read location y AddWrite to location z

Programming Languages  Easier to understand than CPU instructions  Needs to be translated for the CPU to understand it

JAVA  “Most popular” language  Runs on a “virtual machine” (JVM)  More complex than some (eg. Python)  Simpler than others (eg. C++)

Compiling Java Source Code (.javac ) javac Byte Code (.class) java

First Program class Hello { public static void main(String[] arguments){ //Program execution begins here System.out.println("Hello world."); }

Program Structure class CLASSNAME public static void main(String[] arguments){ STATEMENTS }

Output System.out.println(some String) outputs to the console Example: System.out.println(“output”);

Second Program class Hello2 { public static void main(String[] arguments){ //Program execution begins here System.out.println("Hello world."); //Print once System.out.println(“Line number 2."); // Again }

Types Kinds of values that can be stored and manipulated. boolean: Truth value (true or false). int: Integer (0, 1, -47). double: Real number (3.14, 1.0, -2.1). String: Text (“hello”, “example”).

Variables Named location that stores a value of one particular type. Form: TYPE NAME; Example: String foo;

Assignment Use “=“ to give variables a value. Example: String foo; foo = “IAP 6.092”;

Assignment Can be combined with a variable declaration. Example: double badPi = 3.14; boolean isJanuary = true;

class Hello3 { public static void main(String[] arguments){String foo = "IAP 6.092"; System.out.println(foo);foo = "Something else"; System.out.println(foo); }

Operators Symbols that perform simple computations Assignment: = Addition: + Subtraction: - Multiplication: * Division: /

Order of Operations Follows standard math rules: Parentheses Multiplication and division Addition and subtraction

class DoMath { public static void main(String[] Arguments){ double score = * 3.0; System.out.println(score); score = score / 2.0; System.out.println(score); }

class DoMath { public static void main(String[] Arguments){ double score = * 3.0; System.out.println(score); double copy = score; copy =copy/ 2.0; System.out.println(copy); System.out.println(score); }

String Concatenation (+) String text = "hello" + " world"; text = text + " number " + 5; // text = "hello world number 5"

Examples 1 class Comment { // This is a one-line comment; it extends to the end of the line /* This is a delimited comment, extending over several lines */ int /* A delimited comment, extending over part of a line */ x = 117; } 25

Examples 2 class Layout { // Class declaration int a; Layout(int a) { this.a = a; } // One-line constructor body int sum(int b) { // Multi-line method body if (a > 0) // If statement return a + b; // Single statement else if (a < 0) { // Nested if-else, block statement int res = -a + b; return res * 117; } else { // a == 0 // Terminal else, block statement int sum = 0; for (int i=0; i<10; i++) // For loop sum += (b - i) * (b - i); return sum; } 26

…Examples 2 static boolean checkdate(int mth, int day) { int length; switch (mth) { // Switch statement case 2: // Single case length = 28; break; case 4: case 6: case 9: case 11: // Multiple case length = 30; break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: length = 31; break; default: return false; } return (day >= 1) && (day <= length); } 27

Example 4 class Scope {... // void m1(int x) { // declaration of parameter x (#1)... // x #1 in scope } //... // void m2(int v2) { //... // x #5 in scope } //... // void m3(int v3) { //... // x #5 in scope int x; // declaration of variable x (#2)... // x #2 in scope } //... // 28

…Example 4 void m4(int v4) { //... // x #5 in scope { // int x; // declaration of variable x (#3)... // x #3 in scope } //... // x #5 in scope { // int x; // declaration of variable x (#4)... // x #4 in scope } //... // x #5 in scope } //... // int x; // declaration of field x (#5)... // x #5 in scope } 29

30