Vous êtes sur la page 1sur 31

26/08/2018

Introduction to Computer Programming(CS141)


Introduction

Instructor’s Introduction

Name Usman Ali


Present Attachment: PhD Scholar at IBA

Qualifications: Pursuing PhD in Computer Science

MS(CS) From IBA Karachi

MIT From CIIT Abbottabad

BS(CS) From University of Peshawar

Email: uali@iba.edu.pk

Phone / Mobile 0336-2090484

Usman Ali (uali@iba.edu.pk) 1


26/08/2018

Course Introduction

Course Title Introduction to Computer Programming

Course Code CS141( 3,1,4)

Course Schedule Tue/ Thu : Class: 2:30PM – 3:45PM , Lab: 4:00PM 5:15PM

Class Venue MTL4 – Main Campus ( Present Site)

Credit HRS 4 Hours / Week

Total Marks 100

Total Assessments 3 ( 2 Mid Terms , 1 Final Term)

Course Objectives / Outline

This is the first and a foundation course towards a list of advance programming courses.
• It introduces fundamental problem-solving skills and algorithm development with the
help of a programming language.
• It covers topics like:
• Introduction to computers
• Introduction to programming languages
• Variables & Data Types
• Selection and Iteration Structures
• Flowchart Design & Pseudo-code Approach towards problem solving
• Methods and Recursive Methods
• Arrays and ArrayLists
• File I/O
• Elementary Graphics
• Exception Handling
• Debugging and Testing
• Many programming languages like C, C++, Java, Python etc. support the required
functionalities for this course.

Usman Ali (uali@iba.edu.pk) 2


26/08/2018

Reference Books , Tools and Tutorials

1. Books
1. Java: How to Program- Early Objects(10th Edition) , Paul Deital, Harvey Deital
2. Java: The Complete Reference (10th Edition), Herbert Schildt , Oracle Press
2. Software
1. NetBeans IDE 8.2 (JDK 8u171 with NetBeans 8.2)
(http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-
142931.html)
3. Tutorials
1. Developing Applications with NetBeans IDE 8.0 (PDF)
2. Learn Java Programming – Tutorials Point
3. Sample Java Programs
4. Learn Java Online – No need of Software Installation

Marks Distribution

Component Frequency Weightage


Term Exams (Theory + Code + MCQs) 2 30% (15+15)
Final Exam (Theory + Code + MCQS) 1 40 %
Home Assignments N ( 3 - 5) 10 %
Lab Assignments N ( 8 – 12) 10 %
Quizzes N-1 (3 -5) 10 %
TOTAL 100

Usman Ali (uali@iba.edu.pk) 3


26/08/2018

Grading Policy at IBA

Unit -1
Getting Started

Usman Ali (uali@iba.edu.pk) 4


26/08/2018

What is a Computer?

• A Computer is a device that can be instructed to carry out sequences of arithmetic or logical
operations automatically via computer programming.
• Computers are used as control systems for a wide variety of industrial and consumer devices.
• This includes simple special purpose devices like:
• Microwave ovens
• Remote controls,
• Factory devices such as industrial robots and computer-aided design
• And also general purpose devices like:
• Personal Computers
• Mobile devices such as smartphones.

Hardware and Software

• Hardware
• The term hardware covers all of those parts of a computer that are tangible physical objects. Circuits,
computer chips, graphic cards, sound cards, memory (RAM), motherboard, displays, power supplies,
cables, keyboards, printers and "mice" input devices are all hardware
• Software
• Software refers to parts of the computer which do not have a material form, such as programs, data,
protocols, etc.
• Software is that part of a computer system that consists of encoded information or computer
instructions, in contrast to the physical hardware from which the system is built.
• Computer software includes computer programs, libraries and related non-executable data, such as
online documentation or digital media.

Usman Ali (uali@iba.edu.pk) 5


26/08/2018

Operating System
• An operating system is a software that communicates with the hardware and allows other
programs to run.
• It is comprised of system software, or the fundamental files your computer needs to boot up
and function.
• Every desktop computer, tablet, and smartphone includes an operating system that provides
basic functionality for the device.
• Examples of Desktop Operating Systems
• Windows OS
• Mac OS
• Linux OS
• Examples of Mobile Operating Systems
• Google’s Android OS
• Apple’s iOS
• Windows Phone 8
• BlackBerry OS

Technological Evolution in Computer and


Computer Languages- Moore's Law

Usman Ali (uali@iba.edu.pk) 6


26/08/2018

Technological Evolution (http://web.itu.edu.tr/~gerzeli/History.htm)

• The evolution of digital computing is often divided into generations .


• Every generation is differentiated by the technology to build the computer, the internal
organization of computer system and programming languages.
• The mechanical Era (1650-1945)
• Technology: Electromechanical Relays
• Mechanical Calculators by Blaise Pascal and Leibnitz ( 17th Century)
• First Multi-purpose programmable computing device by Charles Babbage ( 1842)
• Charles Babbage and Augusta Ada Lovelace first time recognized several important programming techniques
like conditional branches, loops and index variables
• Augusta Ada is recognized as the first computer programmer.
• George Scheutz following the Babbage’s design , constructed a machine which could process 15 digit
numbers and fourth order differences. This machine was later used to calculate the orbits of Mars.(1855)
• Dr .Herman Hollerith’s punch card machine was used by the first time to tabulate data for 1890’s US
census.(1890)

Technological Evolution (2)

• First Generation Computers (1937-1953)


• Technology: Electronic Switches in the form of Vacuum Tubes
• Atanasoff-Barry Computer– Not Programmable- could solve 29 simultaneous
equations.(1937)
• Alan Turing: Turing Machine to break codes used by German Army in second world
war(1943)
• J. Presper Eckert and John V. Mauchly developed first programmable electronic
computer called ENIAC . It was used in the preparation of Hydrogen Bomb. ENIAC was
controlled by a set of external switches and dials which limited its speed.
• EDVAC – first time used the notion of stored programs.

Usman Ali (uali@iba.edu.pk) 7


26/08/2018

Technological Evolution (3)

• First Generation Computers ( Software Technology)


• Programs were written in machine code
• By 1950’s Programmers started using symbols called Assembly Language then hand-
translating the symbolic notation into machine code
• Later on, programs known as Assemblers were used to translate the Assembly
Language into machine code.
• Commercial/ Military /Scientific Applications
• Solution of Differential Equations
• Decoding
• Simulation of Hydrogen Bomb
• US Census (1952) Results Prediction

Technological Evolution (4)

• Second Generation Computers (1954-1962)


• Technology : Transistors
• TRADIC at Bell Laboratories: Used Magnetic cores for memory which were capable of
being accessed randomly .
• IBM 704, 709 and 7094
• The Livermore Atomic Research Computer (LARC) and the IBM 7030 (aka Stretch) as
Supercomputers
• Index Registers for controlling loops, Floating point units to handle real numbers
• High Level Languages: FORTRAN (1956), ALGOL (1958), and COBOL (1959)

Usman Ali (uali@iba.edu.pk) 8


26/08/2018

Technological Evolution (5)

• Third Generation Computers (1963-1971)


• Technology: Integrated Circuits ( Several Transistors built into one single component)
• Semiconductor memories used instead of magnetic cores
• Microprogramming as a technique for efficiently designing complex processors
• Introduction of Operating system, Time Sharing and Parallel Processing
• SSI( 10 devices per chip) , MSI ( 100 devices per chip)
• CDC6600, CDC7600 and SOLOMOM computer
• Programming Languages: CPL ( Combined Programming Language), BCPL ( Basic
Computer Programming Language) and B for Unix OS

Technological Evolution (6)

• Fourth Generation Computers ( 1971 – 1980)


• Technology: LSI(1000) and VLSI(100,000) on a single chip called Microprocessor.
• Semiconductor memories replaced core memories as the main memory
• Until this time the use of semiconductor memory in most systems was limited to
registers and cache
• Microcomputers and workstations were introduced and saw wide use as alternatives to
time-shared mainframe computers.
• The development of the C programming language and the UNIX operating system
• Concept of Internet was introduced.

Usman Ali (uali@iba.edu.pk) 9


26/08/2018

Technological Evolution (6)

• Fifth Generation Computers ( 1980s Onwards)


• Technology: ULSI , Parallel Processing and Artificial Intelligence
• Desktops, Laptops, Smartphones
• Programming languages: C, C++, .NET, Java , Python etc
• Natural Language Processing Capabilities
• Robotics and Artificial Neural Networks
• Graphical Processing Units (GPUs)
• Big Data and Deep Learning
• Cloud Computing

Moore’s Law :The Journey is not over !


• Moore's law is an observation and projection of a historical trend
• It is the observation that the number of transistors in a dense integrated circuit doubles
about every two years OR Every year or two , the capacities of computers have
approximately doubled inexpensively
• Moore’s 1965 paper described a doubling every year in the number of components per
integrated circuit. He suggested this trend for the next decade.
• In 1975, he revised the forecast to doubling every two years
• The period is often quoted as 18 months because of Intel executive David House, who
predicted that chip performance would double every 18 months
• Moore's prediction proved accurate for several decades, and has been used in the
semiconductor industry to guide long-term planning and to set targets for research and
development.
• Moore’s Law applies especially to disk storage and processor speed

Usman Ali (uali@iba.edu.pk) 10


26/08/2018

Computer Languages ,Program


Translators, Some Early Programming
Languages

Computer Languages (1)


Language A language is a way of communication between two persons
Computer Language A computer language is a way of communication between a user and a computer.
Programming Language A programming language is a formal language that specifies a set of instructions that can be
used to produce various kinds of output. Programming languages can be used to create
programs that implement specific algorithms.
Machine Language Machine language is sometimes referred to as Machine Code or Object Code. Machine
language is a collection of binary digits or bits that the computer reads or interprets. It is the
only language a computer is capable of understanding. It consists of 0s and 1s only.
Assembly Language An assembly language is a low-level programming language designed for a specific type of
processor. Assembly code can be converted to machine code using an assembler.
High Level Language A high-level language is a programming language designed to simplify computer programming.
It is "high-level" since it is several steps removed from the actual code run on a computer's
processor. High-level source code contains easy-to-read syntax that is later converted into a
low-level language, which can be recognized and run by a specific CPU.

Usman Ali (uali@iba.edu.pk) 11


26/08/2018

Computer Languages (2)

Computer Language (3)

Usman Ali (uali@iba.edu.pk) 12


26/08/2018

Program Translation (1)

Program Translation (2)


Source Code : A program written in a high level language is called Source Code
Object Code: A program translated into machine language is called Object Code.
Byte Code: An intermediate translation between a source code and an Object code . Bytecode is
platform independent.

Usman Ali (uali@iba.edu.pk) 13


26/08/2018

Language Translators

Compiler A translator program that translates an entire source code file into object code .
Interpreter A translator program that translates a source code file into object code one line at a time
Assembler A translator program that converts an Assembly language program into machine language.

Some popular Programming Languages


Programming Description
Language
FORTRAN FORTRAN ( FORmula TRANslation) was developed by IBM Corporation in mid 1950’s. It was developed
for scientific and engineering applications that require complex computations. It is still widely used and
latest versions support Object Oriented programming.
COBOL COBOL ( Common Business Oriented Language) was developed in late 1950’s for commercial
applications that require precise and efficient manipulation of large amounts of data. It is still widely
used and its latest versions support Object Oriented Programming.
Pascal Pascal was developed in 1971 as a structured programming language as remained popular in college
courses for several decades.
Ada Ada is based on Pascal and was developed in early 1980s. It also supports Object Oriented language
BASIC BASIC ( Beginners All Purpose Symbolic Instruction Code) was developed in 1960’s to teach
programming concepts as school and college levels.
C C was developed in early 1970’s by Dennis Ritchie at Bell Laboratories as a language of UNIX OS. Today
most of the OS are written in C or C++. It is basically a procedural system programming language.

Usman Ali (uali@iba.edu.pk) 14


26/08/2018

Some popular Programming Languages (2)


Computer Language Description

C++ C++ is an extended version of C++ and was developed by Bjarne Stroustrup in early 1980’s. It is an
Object Oriented Programming Language.
Objective C Objective C is an Object Oriented language based on C developed in 1980’s. It was acquired by
Apple and now is the OS for all iOS powered devices like iPhones and iPads etc
Visual Basic Visual Basic was developed by Microsoft in 1990’s to develop Windows applications. Its latest
version like VB.net support OOP.
C# C# is an Object Oriented programming language developed by Microsoft. It is based on C++ and
java . It was developed to integrate internet and the web into computer applications.
PHP PHP is an open source Object Oriented language which is platform independent. It is a database
programming language and commonly used with MySQL which is an open source DBMS.
Perl Per is an Object Oriented web-based scripting language , was developed in 1987

Python Python is an open source Object Oriented language especially used for Data Science and Machine
Learning. It was developed in 1991.
Java Java is an Object Oriented language developed at Sun Microsystems by James Gosling in 1991. It is
platform independent mainly used for web and network programming.

Java- An Introduction

Usman Ali (uali@iba.edu.pk) 15


26/08/2018

Java Programming language

• Java was developed at Sun Microsystems by James Gosling in 1991 as an


outcome of the project started in 1970’s.
• It was originally designed to create portable software for consumer
electronics
• Initially it was called Oak after an oak tree outsides Gosling office
• Later , it was given a name Green , and finally Java after Java Coffee
• Java is related to C++ which is a direct descendent of C language
• Java inherits much of its syntax from C language
• Its object oriented features are greatly influenced by C++.

Creation of Java (1)

• Creation of Java was deeply rooted in the process of refinement and adaptation
that has been occurring in computer programming languages for the pas several
decades.
• When a computer language is designed , various trade-offs are made. E.g.
• Ease of use vs power
• Safety vs efficiency
• Rigidity vs extensibility
• Prior to C , three most common languages were COBOL, FORTRAN and BASIC
• BASIC was easy to use but not powerful and was not structured.
• FORTRAN was efficient for scientific applications but not very good for system
code.

Usman Ali (uali@iba.edu.pk) 16


26/08/2018

Creation of Java (2) - Design Trade-Offs

• Assembly languages were very efficient for system programming but not easy
to understand
• Pascal was a structured language but not efficient failed to include some
features .
• So , prior to C language , all the available computer languages like FORTRAN,
COBOL, BASIC etc were not structured due to use of GOTO statements.
• Large programs in these languages were very complex to understand.
• No one language had reconciled these conflicting attributes.

Creation of Java (3) – C language


• C Language was developed in 1970’s by Dennis Ritchie on UNIX platform.
• It was formally standardized in 1989 by ANSI
• The creation of C language is considered as beginning of modern age of
programming
• It successfully synthesized together the conflicting attributes like efficiency,
ease of use, structure and extensibility
• C emerged as a powerful, efficient and structured language that was relatively
easy to learn.
• C became a language programmers liked to use and had a near-religious zeal
for it.
• C is a language designed by and for programmers- Java inherited this legacy

Usman Ali (uali@iba.edu.pk) 17


26/08/2018

Creation of Java (4) – Advent of C ++

• Throughout the programming history , increasing complexity of programs


stimulated the quest of better ways to manage it.
• Although C was a structured procedural language , once a project reached a
certain size, the complexity became unmanageable for the programmer.
• To solve this problem, a new way to programming called Object Oriented
Programming was invented.
• C language was extended with Object Oriented capabilities and C++ was
invented by Bjarne Stroustrup in 1979.
• By the end of 1980s and the early 1990s, C++ took hold in the programming
world.

Creation of Java (4)


• Before 1990s ,the computer world had divided itself in three competing
camps of intel, Macintosh and UNIX.
• Most of the programmers stayed within their confined boundaries .
• With the advent of World Wide Web and internet, need for portability was
strongly felt.
• C and C++ were not portable and platform dependant .
• At this time, around in 1991, java was developed by James Gosling at Sun
Microsystems to create platform-independent software for consumer
electronics.
• The ability to produce portable software drove Java towards web and internet
programming.

Usman Ali (uali@iba.edu.pk) 18


26/08/2018

Applications of Java Programming Language

• Types of Applications that Run on Java


• Desktop GUI Applications: Java provides GUI development through various
means like Abstract Windowing Toolkit (AWT), Swing and JavaFX. ...
• Mobile Applications
• Embedded Systems
• Web Applications
• Web Servers and Application Server
• Enterprise Applications
• Scientific Applications
https://www.invensis.net/blog/it/applications-java-programming-language/

Java Development Environment -


Program Development Process

Usman Ali (uali@iba.edu.pk) 19


26/08/2018

Program Development Process


• The program development life cycle is a set of steps or phases that are used
to develop a program in any programming language.
• Generally, program development life cycle contains 6 phases, they are as
follows….
• Problem Definition
• Problem Analysis
• Algorithm Development
• Coding & Documentation
• Testing & Debugging
• Maintenance

Program Development Process

Usman Ali (uali@iba.edu.pk) 20


26/08/2018

Program Development Process


1. Problem Definition
• we define the problem statement , boundaries of the problem and output of the
solution
2. Problem Analysis
• We determine the requirements like variables, functions, etc. to solve the problem and
the approach that will be used to solve the problem.
3. Algorithm Development
• We develop a step by step procedure to solve the problem using the specification given
in the previous phases.

Program Development Process

4. Coding & Documentation


• We use a programming language to implement the solution. Documentation helps the
users and support team is using the product.
5. Testing & Debugging
• We test the program whether it is solving the problem for various input data values or
not. We also test that whether it is providing the desired output or not.
6. Maintenance
• To maintain the program operations , make changes as per requirements of the user
and provide necessary customer support.

Usman Ali (uali@iba.edu.pk) 21


26/08/2018

Java Development Environment

• Typically, there are 5 steps to create and execute a Java application:


1. Edit / Create the source code
2. Compile the source code to generate Bytecode
3. Loading the program into memory
4. Bytecode verification
5. Execution

Step-1 Create the Source Code in Editor

• A simple text editor like notepad or Notepad ++ can be used to type / create a java
program.
• We can also use an IDE like NetBeans , Eclipse or Intellij IDEA for this.
• Save the program with .java extension.
• The name of the file must be same as the class name
• This file with .java extension that contains the java program is called the source
code.

Usman Ali (uali@iba.edu.pk) 22


26/08/2018

Hello World!

We will save this file as HelloWorld.java

Step-2 Compiling a Java Program into Bytecode


• The Command “Javac” is used to compile the program into Bytecode
• A JDK must be installed on your computer to compile a Java program
• The environment variable path also be set so that proper compiler can be
located.
• To compile a file :
• Open Command prompt
• Go to the directory where source code file is stored.
• Use command javac to compile the program e.g. javac HelloWorld.java
• Or use the Build command in IDE like NetBeans
• The compiler creates .class file which contains Bytecode. In this case
Helloworld.class file will be created

Usman Ali (uali@iba.edu.pk) 23


26/08/2018

Step-3 Loading a Program into Memory


• The command java is used to execute a java program when initiates the
JVM(Java Virtual Machine)
• JVM is a part of JDK which executes Bytecodes
• JVM’s class loader takes the .class file and loads it into memory from the local
hard disk or over a network.

Step 4:Bytecode Verification


• Once the classes are loaded, Bytecode verifier examines the bytecode
• Bytecode should be valid and should not violate Java’s security restrictions
• Programs arriving over the network may contain worms and viruses
• It ensures that Java programs arriving over the network may not harm your
files etc.

Usman Ali (uali@iba.edu.pk) 24


26/08/2018

Step 5- Execution

• During this phase, JVM translates Bytecodes into machine language the host
computer can understand
• JVM uses just-in-time (JIT) compilation i.e. compiling the code at run time
rather than as a preliminary step.
• JIT compiler searches for hot spots- part of the byte code that execute
frequently
• It compiles such hot spots only once – if encountered again it uses the faster
machine code

Step 5- Execution

Usman Ali (uali@iba.edu.pk) 25


26/08/2018

Summary – Typical Java Development Environment

Installing a Compiler and an IDE

Usman Ali (uali@iba.edu.pk) 26


26/08/2018

Java Editions

• Java is available in three different Editions


• Java Standard Edition (Java SE)
• This is the core Java programming platform for developing applications on desktop and servers.
• It contains all of the libraries and APIs that any Java programmer should learn (java.lang, java.io,
java.math, java.net, java.util, etc...).
• Java Enterprise Edition ( Java EE)
• Java EE is geared towards developing large-scale, distributed networking applications and web-
based applications.
• Java Micro Edition ( Java ME)
• Java ME is a subset of Java SE and is geared towards developing applications for embedded devices
like ATMS, smart Meters, Tablets , smartphones etc

Java Development Kit ( JDK) –Standard Edition

1. Visit the following link:


https://www.oracle.com/technetwork/java/javase/downloads/index.html
2. The latest version is JDK 10

Usman Ali (uali@iba.edu.pk) 27


26/08/2018

NetBeans IDE 8.2


• NetBeans is an integrated development environment for Java.
• NetBeans allows applications to be developed from a set of modular
software components called modules.
• NetBeans runs on Microsoft Windows, macOS, Linux and Solaris.
• NetBeans is an IDE for a number of computer languages like : Java, C, C++,
PHP, JavaScript and HTML

NetBeans IDE 8.2 https://netbeans.org/downloads/

Usman Ali (uali@iba.edu.pk) 28


26/08/2018

JDK 8u171 with NetBeans 8.2

First Program- HelloWorld ( Lab 1)

Usman Ali (uali@iba.edu.pk) 29


26/08/2018

Step 1- Create Source Code in Editor


• Using Notepad or Notepad ++ type the following source code

• Save the file as HelloWorld.java

2- Compile the Source Code into Bytecode

• Open command prompt ,move to the directory where HelloWorld.java is


saved
• Use command set path=C:\Program Files\Java\jdk1.8.0_171\bin if needed
• This command may vary as per installed version of JDK
• Use command javac HelloWorld.java to compile the source code
• This will generate a HelloWorld.class file in the directory where source code
file is saved.

Usman Ali (uali@iba.edu.pk) 30


26/08/2018

Run The Command

• Use command java HelloWorld to run the Java program

HelloWorld Application – Using NetBeans

• https://netbeans.org/kb/docs/java/quickstart.html

Usman Ali (uali@iba.edu.pk) 31

Vous aimerez peut-être aussi