Computer Programming-1 CSC 111

Slides:



Advertisements
Similar presentations
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Advertisements

IT151: Introduction to Programming
Dale Roberts Introduction to Java - First Program Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
University of Palestine software engineering department Introduction to data structures Introduction to java application instructor: Tasneem Darwish.
Chapter 1 Introduction to JAVA. Why Learn JAVA? Java is one of the fastest growing programming language in the world. Java is one of the fastest growing.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
INSTRUCTOR: SHIH-SHINH HUANG Windows Programming Using Java Chapter2: Introduction to Java Applications 1.
Chapter 2 - Introduction to Java Applications
Object Orientated Programming
Introduction To Computers and Programming Lecture 2: Your first program Professor: Evan Korth New York University.
Chapter 1: An Overview of Computers and Programming Languages J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program.
CMT Programming Software Applications
Three types of computer languages
 2003 Prentice Hall, Inc. All rights reserved. Customized by Sana Odeh for the use of this class. 1 Introduction to Computers and Programming in JAVA.
Chapter 2 - Introduction to Java Applications
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 1 – Introduction to Computers, the Internet, and the Web Outline 1.1 Introduction 1.2 What Is a.
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Introducing Java.
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Training Course Dr. H.E. Dunsmore Purdue University Java – How to Program, Deitel (5 th Edition)
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
Java Programming, Second Edition Chapter One Creating Your First Java Program.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
8/31: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
1 COMP 241: Object-Oriented Programming with Java Fall 2004 Lecture 1 September 27, 2004 Serdar Taşıran.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 1 st semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CT1513 Introduction To java © A.AlOsaimi.
J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition Second Edition D.S. Malik D.S. Malik.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
Chapter 1: An Overview of Computers and Programming Languages
Introduction to Java Applications Part I. In this chapter you will learn:  Why Java?  History of Java.  To write simple Java applications. 2.
Introducing Java Chapter 3 Review. Why Program in Java? Java, is an object-oriented programming language. OOP languages evolved out of the need to better.
1 Introduction Read D&D Sec 1.8; Sec 1.13 THE Java tutorial -
1 Chapter 1 Java –Originally for intelligent consumer-electronic devices –Then used for creating Web pages with dynamic content –Now also used for: Develop.
1/16: Intro to Java, Languages, and Environments Types of programming languages –machine languages –assembly languages –high-level languages Java environment.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Introduction to 1. What is Java ? Sun Microsystems Java is a programming language and computing platform first released by Sun Microsystems in The.
Chapter 1 Introduction 2nd Semester H
Introduction to Java Applications
Introduction to Computers, the Internet and the World Wide Web
Chapter 1: Introduction to computers and C++ Programming
CSC201: Computer Programming
Chapter 1 – Introduction to Computers, the Internet, and the Web
GC101 Introduction to computer and program
hardware bits and bytes Java
Chapter 3 GC 101 Java Fundamentals.
Lecture 1: Introduction to JAVA
Console Output, Variables, Literals, and Introduction to Type
Introduction to.
Chapter 2 Introduction to Java Applications
Data types and variables
Java programming lecture one
C++ Programming: From Problem Analysis to Program Design
Chapter 2 - Introduction to Java Applications
Introduction CSC 111.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Introduction to Java Applications
Presentation transcript:

Computer Programming-1 CSC 111 Chapter 1 : Introduction

What Is a Computer? Computer Computer programs Executes statements (computations/logical decisions) Computer programs A sequence of instructions to be performed by a computer Hardware :Physical devices of computer system Software: Programs that run on computers

Computer Organization

Computer Organization II Input unit (Mouse, keyboard) Output unit (Printer, monitor, audio speakers) Memory unit (Retains input and processed information) Central processing unit (CPU) which consists of: Secondary storage unit (Hard drives, floppy drives)

The Programmer’s Algorithm An algorithm is a series of step by step instructions that produces a solution to a problem The programmer’s algorithm: Define the problem. Plan the problem solution. Code the program. Test and debug the program.

Program Execution steps output data input data executing program Keyboard Screen

Example 1: Area and Perimeter of a rectangle Input Length width Process Area = length*width Perimeter = 2*( length + width) Output Area Perimeter

Example 2: Sum and Average of 5 numbers Input five number x1, x2, x3, x4, x5 Process Sum = x1+x2+x3+x4+x5 Average = Sum/5 Output Sum Average

Example 3: Area and Perimeter of a circle Input Radius PI Process Area = PI * Radius * Radius Perimeter = 2 * PI * Radius Output Area Perimeter

Test and Debug the Program Check the program, Compile the program. Run the program. Debug the program using a debugger.

Typical Java Environment Java programs undergo five phases Edit Programmer writes program (and stores program on disk as .java file) Compile Compiler creates bytecodes from program (.class file generated from the .java file) Load Class loader stores bytecodes in memory

Typical Java Environment Verify Verifier ensures bytecodes do not violate security requirements Execute Interpreter translates bytecodes into machine language

The Java Virtual Machine The class Loader, the Bytecode Verifier and Interpreter constitute the Java Virtual Machine (JVM). JVM is platform specific. The interpreter translates the bytecodes into specific machine commands.

Phase 1 Editor Phase 2 Compiler Phase 3 Class Loader Bytecode Verifier Primary Memory . Disk Editor Compiler Class Loader Program is created in an editor and stored on disk in a file ending with .java. Compiler creates bytecodes and stores them on disk in a file ending with .class. Class loader reads .class files containing bytecodes from disk and puts those bytecodes in memory. Phase 1 Phase 2 Phase 3 Bytecode Verifier Bytecode verifier confirms that all bytecodes are valid and do not violate Java’s security restrictions. Phase 4 Interpreter Interpreter reads bytecodes and translates them into a language that the computer can understand, possibly storing data values as the program executes. Phase 5

Running Programs The Java compiler produces bytecode not machine code Bytecode is converted into machine code using a Java Interpreter Bytecode is runnable on any computer that has a Java Interpreter installed

Java Class Libraries Classes Java contains class libraries Include methods that perform tasks Return information after task completion Used to build Java programs Java contains class libraries Known as Java APIs (Application Programming Interfaces)

Characteristics of Java Object-Oriented Combines data and behavior into one unit  objects Provides Data abstraction and encapsulation Decompose program into objects. Programs are collections of interacting and cooperating between objects.

Characteristics of Java (2) Platform-independent Portable Architecture neutral ”Write-once, run-anywhere”

Characteristics of Java (3) Secure The bytecode verifier of the JVM : checks untrusted bytecode controls the permissions for high level actions.

A Simple Program 1 // Hello.java 2 Import javax.swing.* 3 public class Hello { 4 5 // main method 6 public static void main( String args[] ) { JFrame myWindow ; myWindow = new JFrame() ; myWindow.setSize(300,200); myWindow.setTitle(“ Hello !!!!!!”); myWindow.setVisible(true); } // end main } // end class Hello

A First Program in Java: Printing a Line of Text 1 // Welcome1.java Comments start with: // Comments ignored during program execution Documents code Provides code readability Traditional comments: /* ... */ /* This is a traditional comment. It can be split over many lines */ Note: line numbers not part of program, added for reference

A Simple Program Blank line Begins class declaration for class Hello 2 Blank line Makes program more readable Blank lines, spaces, and tabs are white-space characters Ignored by compiler Begins class declaration for class Hello Every Java program has at least one user-defined class Keyword: words reserved for use by Java class keyword followed by class name Naming classes: capitalize every word MyClassName 3 public class Hello {

A Simple Program: Printing a Line of Text 3 public class Hello { Name of class called identifier Series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) Does not begin with a digit, has no spaces Examples: Hello1, $value, _value, button7 7button is invalid Java is case sensitive (capitalization matters) a1 and A1 are different

A Simple Program: Printing a Line of Text 3 public class Hello { Saving files File name must be class name with .java extension Hello.java Left brace { Begins body of every class Right brace ends declarations (line 12) Part of every Java application Applications begin executing at main Parenthesis indicate main is a method Java applications contain one or more methods 6 public static void main( String args[] ) {

A Simple Program: Printing a Line of Text 6 public static void main( String args[] ) { Exactly one method must be called main Methods can perform tasks and return information void means main returns no information For now, mimic main's first line Left brace begins body of method declaration Ended by right brace } (line 10)

A Simple Program: Printing a Line of Text 8 System.out.println( “Hello Every Body!" ); Instructs computer to perform an action Prints string of characters String - series characters inside double quotes White-spaces in strings are not ignored by compiler System.out Standard output object Print to command window Method System.out.println Displays line of text Argument inside parenthesis This line known as a statement Statements must end with semicolon ;

A Simple Program: Printing a Line of Text 10 } // end main Ends method declaration Ends class declaration Can add comments to keep track of ending braces Lines 7 and 8 could be rewritten as: Remember, compiler ignores comments Comments can start on same line after code 12 } // end class Hello