Thursday, November 29, 2007
Monday, November 26, 2007
Sunday, September 9, 2007
Sunday, June 3, 2007
Developing Plug-Ins for the Eclipse 3.0 Platform
Developing Plug-Ins for the Eclipse 3.0 Platform
Duration: 5 days
Audience
Prerequisites
This course is for developers who already know Java and want to learn the Eclipse platform.
Java developers
Architects
Participants must be proficient in Java in order to do the labs.
Description
Eclipse is a platform for building Rapid Application Development (RAD) environments. The Eclipse framework is based on a plug-in model that enables software tool vendors to plug in their own development tools. The platform provides a common user interface model for working with tools. It is designed to run on multiple operating systems. Plug-ins can be built using the Eclipse portable APIs and may run unchanged on any of the supported operating systems. This course teaches attendees the architecture of the Eclipse platform. It covers the whole spectrum of writing a plug-in for the platform. This is a highly hands-on course, with programming labs constituting about 60% of the course.
Objectives
Upon completion of this course, attendees will be able to:
Understand the architecture of the Eclipse platform
Use the Standard Widget Toolkits to write their own widgets
Use the JFace UI framework
Develop a full-fledged plug-in
Productize a plug-in
Course Outline
Eclipse Overview
What is Eclipse
Eclipse platform architecture
Eclipse SDK
Write your first plug-in
The plug-in.xml file
Packaging and installing a plug-in Plug-in Development Environment (PDE)
PDE Concepts
plug-in.xml editor
Using PDE to build a simple plug-in
Debugging plug-in code SWT - The Standard Widget Toolkit
SWT overview - What, why, and how
SWT widgets
Layouts
SWT event model
Graphics
Color model
Thread model JFace - The User Interface Framework for Plug-Ins
JFace overview
Viewers
Using the Tree Viewer
Using the Text Viewer
Editors
JFace resource module
JFace wizard module
Progress indicators
Dialogs
Resources and Resources Plug-In
Resources overview
Resources and workspace
Resources and file systems
The Resources API
Resource markers
Tracking resource changes
Incremental project builders
Project natures
Participating in workspace save
Project natures
Writing Workbench Plug-ins
Overview of Workbench Components
Overview of workbench extension points
The plug-in class
View Actions Extension Point
Editors Extension Point
Editor Action Extension Point
Popup Menus Extension Point
Workbench Menu contribution
Action Sets Extension Point
Perspectives Extension Point
New Wizards Extension Point
Process of Creating a Wizard
Preferences
Property pages
Dialogs and Wizards
Dialogs Overview
JFace Dialog Framework
SWT Dialog Widgets
Wizards Overview
newWizards Extension Point
Process of Creating a Wizard
Preferences and Properties
Extending the Preferences Dialog
How are Preferences Used
How are Preferences Stored
Defining a Preference Page Extension
The Preference Page Class
Preference Page Implementation
Interacting Between GUI and Preference Store
Reacting to Preference Setting Changes
Extending Properties Dialog
How Is Properties Dialog Used
Process for creating a Property Page
Defining a Property Page Extension
Defining the Property Page Class
Implementing Property Page User Interface
Accessing Properties
Help
Contributing Online Help
Process of offering Help
Creating HTML contents
Creating Table of Contents Files
Linking Table of Contents Files
Providing Anchors
Declaring the Help Extension
Providing Context Sensitive Help
Process of adding Context Sensitive Help
Declaring a Help Context Extension
Creating the Infopop Contents
Associating the Context Id with UI Component
Fragments
What is a Plug-in Fragment
Where is Fragment defined
The fragment.xml file
PDE and Fragments
Features
Update Manager
Overview of Features
Default Features in Eclipse
Translatable Strings
Primary Feature
Description, License URL, etc.
Updating Features
Plug-ins in a Feature
Prerequisite Plug-ins
Prerequisite Matching Rule
Root and Included Features
PDE Project for Features
feature.xml Editor
Exporting Feature
Feature and Product Branding
Feature Branding
Feature Branding Information
Product Branding
Files for Product Branding
The install.ini File
How is Product Branding Information Used
The Splash Screen
Packaging for Delivery
Packaging as a Product
Process of Packaging an Eclipse-Based product
Packaging as an Extension
Using Installatoin Tool to create an Installer
Packaging for Update Manager
The site.xml File
Using PDE to create site.xml File
Duration: 5 days
Audience
Prerequisites
This course is for developers who already know Java and want to learn the Eclipse platform.
Java developers
Architects
Participants must be proficient in Java in order to do the labs.
Description
Eclipse is a platform for building Rapid Application Development (RAD) environments. The Eclipse framework is based on a plug-in model that enables software tool vendors to plug in their own development tools. The platform provides a common user interface model for working with tools. It is designed to run on multiple operating systems. Plug-ins can be built using the Eclipse portable APIs and may run unchanged on any of the supported operating systems. This course teaches attendees the architecture of the Eclipse platform. It covers the whole spectrum of writing a plug-in for the platform. This is a highly hands-on course, with programming labs constituting about 60% of the course.
Objectives
Upon completion of this course, attendees will be able to:
Understand the architecture of the Eclipse platform
Use the Standard Widget Toolkits to write their own widgets
Use the JFace UI framework
Develop a full-fledged plug-in
Productize a plug-in
Course Outline
Eclipse Overview
What is Eclipse
Eclipse platform architecture
Eclipse SDK
Write your first plug-in
The plug-in.xml file
Packaging and installing a plug-in Plug-in Development Environment (PDE)
PDE Concepts
plug-in.xml editor
Using PDE to build a simple plug-in
Debugging plug-in code SWT - The Standard Widget Toolkit
SWT overview - What, why, and how
SWT widgets
Layouts
SWT event model
Graphics
Color model
Thread model JFace - The User Interface Framework for Plug-Ins
JFace overview
Viewers
Using the Tree Viewer
Using the Text Viewer
Editors
JFace resource module
JFace wizard module
Progress indicators
Dialogs
Resources and Resources Plug-In
Resources overview
Resources and workspace
Resources and file systems
The Resources API
Resource markers
Tracking resource changes
Incremental project builders
Project natures
Participating in workspace save
Project natures
Writing Workbench Plug-ins
Overview of Workbench Components
Overview of workbench extension points
The plug-in class
View Actions Extension Point
Editors Extension Point
Editor Action Extension Point
Popup Menus Extension Point
Workbench Menu contribution
Action Sets Extension Point
Perspectives Extension Point
New Wizards Extension Point
Process of Creating a Wizard
Preferences
Property pages
Dialogs and Wizards
Dialogs Overview
JFace Dialog Framework
SWT Dialog Widgets
Wizards Overview
newWizards Extension Point
Process of Creating a Wizard
Preferences and Properties
Extending the Preferences Dialog
How are Preferences Used
How are Preferences Stored
Defining a Preference Page Extension
The Preference Page Class
Preference Page Implementation
Interacting Between GUI and Preference Store
Reacting to Preference Setting Changes
Extending Properties Dialog
How Is Properties Dialog Used
Process for creating a Property Page
Defining a Property Page Extension
Defining the Property Page Class
Implementing Property Page User Interface
Accessing Properties
Help
Contributing Online Help
Process of offering Help
Creating HTML contents
Creating Table of Contents Files
Linking Table of Contents Files
Providing Anchors
Declaring the Help Extension
Providing Context Sensitive Help
Process of adding Context Sensitive Help
Declaring a Help Context Extension
Creating the Infopop Contents
Associating the Context Id with UI Component
Fragments
What is a Plug-in Fragment
Where is Fragment defined
The fragment.xml file
PDE and Fragments
Features
Update Manager
Overview of Features
Default Features in Eclipse
Translatable Strings
Primary Feature
Description, License URL, etc.
Updating Features
Plug-ins in a Feature
Prerequisite Plug-ins
Prerequisite Matching Rule
Root and Included Features
PDE Project for Features
feature.xml Editor
Exporting Feature
Feature and Product Branding
Feature Branding
Feature Branding Information
Product Branding
Files for Product Branding
The install.ini File
How is Product Branding Information Used
The Splash Screen
Packaging for Delivery
Packaging as a Product
Process of Packaging an Eclipse-Based product
Packaging as an Extension
Using Installatoin Tool to create an Installer
Packaging for Update Manager
The site.xml File
Using PDE to create site.xml File
Oracle9i Application Server Basic Administration
Oracle9i Application Server Basic Administration
Duration: 3 days
Audience
Prerequisites
Description
This course provides comprehensive background on the new Orable9i Application Server.
Objectives
At the conclusion of this course, participants will have an understanding of the new Oracle9i Application Server.
Course Outline
Overview of Oracle9i Application Server
Orcle9i Application Server as a component of Oracle Internet Suite
Summary of the services provided by Oracle9i Application Server
The role of Oracle9i Application Server in multi-tier system architecture
Architecture of Oracle9i Application Server - Standard, Enterprise, Wireless Technologies supported Communication Services - HTTP Server Overview of Apache web server
Workshop: Configuring and using Apache web server
Configuration of Apache JServ, installing and running servlets
Workshop: Configuring Apache JServ and installing servlets
HTTP server modules - PERL, PL/SQL, Secure Socket Layer (SSL)Content Management
Oracle Internet File System (iFS) concepts and components
Setting up Oracle iFS
Administration tools
Workshop: Setting up and using Oracle iFSBusiness Logic Services
Business components for Java (BC4J)
Oracle Java Virtual Machine (JVM) and its supported technologies
CORBA
EJB
stored procedures
JDBC
JPublisher
Servlets
JSP
SQLJ
PL/SQL
Oracle Form Services
Presentations Services
Java servlets with Apache JServ
JavaServer Pages (JSP)
Workshop: Installing and configuring example JSP
PL/SQL Server Pages (PSP)
Perl InterpreterDeveloper Kits
Oracle database client development with
JDBC
JMS
OCI
SQLJ
Java Messaging Service Toolkit
SQLJ translator and runtime environment
JDBC drivers
Oracle Call Interface (OCI)
Extensible Markup Language (XML)
Lightweight Directory Access Protocol (LDAP)Portal Services
Oracle Portal
Portal-to-GoCaching Services
Database cache
Web cacheSystem ServicesBusiness Intelligence Services
Oracle Reports
Oracle Discoverer Viewer
Duration: 3 days
Audience
Prerequisites
Description
This course provides comprehensive background on the new Orable9i Application Server.
Objectives
At the conclusion of this course, participants will have an understanding of the new Oracle9i Application Server.
Course Outline
Overview of Oracle9i Application Server
Orcle9i Application Server as a component of Oracle Internet Suite
Summary of the services provided by Oracle9i Application Server
The role of Oracle9i Application Server in multi-tier system architecture
Architecture of Oracle9i Application Server - Standard, Enterprise, Wireless Technologies supported Communication Services - HTTP Server Overview of Apache web server
Workshop: Configuring and using Apache web server
Configuration of Apache JServ, installing and running servlets
Workshop: Configuring Apache JServ and installing servlets
HTTP server modules - PERL, PL/SQL, Secure Socket Layer (SSL)Content Management
Oracle Internet File System (iFS) concepts and components
Setting up Oracle iFS
Administration tools
Workshop: Setting up and using Oracle iFSBusiness Logic Services
Business components for Java (BC4J)
Oracle Java Virtual Machine (JVM) and its supported technologies
CORBA
EJB
stored procedures
JDBC
JPublisher
Servlets
JSP
SQLJ
PL/SQL
Oracle Form Services
Presentations Services
Java servlets with Apache JServ
JavaServer Pages (JSP)
Workshop: Installing and configuring example JSP
PL/SQL Server Pages (PSP)
Perl InterpreterDeveloper Kits
Oracle database client development with
JDBC
JMS
OCI
SQLJ
Java Messaging Service Toolkit
SQLJ translator and runtime environment
JDBC drivers
Oracle Call Interface (OCI)
Extensible Markup Language (XML)
Lightweight Directory Access Protocol (LDAP)Portal Services
Oracle Portal
Portal-to-GoCaching Services
Database cache
Web cacheSystem ServicesBusiness Intelligence Services
Oracle Reports
Oracle Discoverer Viewer
Java Programming for COBOL Programmers
Java Programming for COBOL Programmers
Duration: 5 days
Audience
Prerequisites
Application Developers
System Designers
Experience with at least one structured programming language
Description
This course is specially designed for COBOL programmers seeking to design and develop applications using the Java 2 Standard Edition (J2SE). Based on InferData's well-received training methodologies, the course provides for a rapid and efficient transition to object-oriented software development using J2SE. The attendees are expected to be familiar with COBOL or some other structured programming language. Experience with object orientation would be helpful but is not required.This five-day course covers topics in object-orientation, the basics of programming using Java, including syntax, compilation, packaging and deployment. The J2SE class library and architecture are also covered as well as multi-threaded programming in Java. Other topics covered include concepts in "Interface based design for de-coupled and concurrent development". The Java class libraries covered include: Java utilities, input and output (I/O), web based client development using Java "Applets", a brief introduction to graphical user interfaces development using the Java Swing library, and an introduction to the Java Database Connectivity (JDBC). Where applicable, all the concepts will be conveyed in a way such that COBOL programmers can relate to their familiar COBOL counterparts.This course consists of a large number of fully worked out example code illustrating various concepts introduced during the course. The concepts are further reinforced through the use of well-crafted exercises at appropriate points throughout the course.
Objectives
objectives
Course Outline
Java Basics
Java Object Model
Class definitions
Class and instance variables
Basic data types
Inheritance and code reuse
Data encapsulation and access protection
Compilation and the Java run-time environment
The "String" and "System" classes
Basic Java application Java Interfaces
Design by contract
Java Interface
De-coupled design
Using the factory design pattern
Implementing multiple inheritance Comparing and Mapping COBOL Concepts to Java Language ConstructsJava Packages
Name spaces
Standard Java conventions
File system dependencies
Access protection Error Handling
Java Exceptions
Separating business logic from error handling logic
Using "try", "catch" and "finally"
Throwing exceptions
Checked and unchecked exceptions
Navigating the stack trace
Repackaging and re-throwing exceptions Threads
Concurrent and parallel programming
Deadlocks
Tread Class
Managing groups of threads using Thread Group
Managing thread priorities
Thread Synchronization
Designing cooperating multithreaded applications
Using the "Runnable" interface
Java Class Library
J2SE Class Library Architecture
Naming conventions
Java Utility Package (java.util)
Collections Library
Storage Structures (Array, Vector, HashMaps etc.)
Aggregation operations Input and Output
The java.io class Library
Input and Output structure
Handling textual data with "Reader" and "Writer" streams
File System I/O Basic Graphics
The Java graphics framework
Abstract Windowing Toolkit (java.awt)
The Java Swing Library (javax.swing)
The Java event model
Basic UI elements
Labels
TextFields
Buttons
Panels
Frames
Event Processing and Propagation
Handling Graphical Events using Event Listeners Java Applets
Web-based client Development
The java.applet package
Issues in network security
The java "Sandbox" model of security
Applet limitations
Building an applet-based application Java Database Connectivity (JDBC)
Fundamentals of Database Programming
Using the JDBC API
JDBC connectivity types
Bridging technology
Native API
Middleware
Pure Java Drivers
Loading JDBC drivers
Connection
Statements
ResultSets
Meta Data
Duration: 5 days
Audience
Prerequisites
Application Developers
System Designers
Experience with at least one structured programming language
Description
This course is specially designed for COBOL programmers seeking to design and develop applications using the Java 2 Standard Edition (J2SE). Based on InferData's well-received training methodologies, the course provides for a rapid and efficient transition to object-oriented software development using J2SE. The attendees are expected to be familiar with COBOL or some other structured programming language. Experience with object orientation would be helpful but is not required.This five-day course covers topics in object-orientation, the basics of programming using Java, including syntax, compilation, packaging and deployment. The J2SE class library and architecture are also covered as well as multi-threaded programming in Java. Other topics covered include concepts in "Interface based design for de-coupled and concurrent development". The Java class libraries covered include: Java utilities, input and output (I/O), web based client development using Java "Applets", a brief introduction to graphical user interfaces development using the Java Swing library, and an introduction to the Java Database Connectivity (JDBC). Where applicable, all the concepts will be conveyed in a way such that COBOL programmers can relate to their familiar COBOL counterparts.This course consists of a large number of fully worked out example code illustrating various concepts introduced during the course. The concepts are further reinforced through the use of well-crafted exercises at appropriate points throughout the course.
Objectives
objectives
Course Outline
Java Basics
Java Object Model
Class definitions
Class and instance variables
Basic data types
Inheritance and code reuse
Data encapsulation and access protection
Compilation and the Java run-time environment
The "String" and "System" classes
Basic Java application Java Interfaces
Design by contract
Java Interface
De-coupled design
Using the factory design pattern
Implementing multiple inheritance Comparing and Mapping COBOL Concepts to Java Language ConstructsJava Packages
Name spaces
Standard Java conventions
File system dependencies
Access protection Error Handling
Java Exceptions
Separating business logic from error handling logic
Using "try", "catch" and "finally"
Throwing exceptions
Checked and unchecked exceptions
Navigating the stack trace
Repackaging and re-throwing exceptions Threads
Concurrent and parallel programming
Deadlocks
Tread Class
Managing groups of threads using Thread Group
Managing thread priorities
Thread Synchronization
Designing cooperating multithreaded applications
Using the "Runnable" interface
Java Class Library
J2SE Class Library Architecture
Naming conventions
Java Utility Package (java.util)
Collections Library
Storage Structures (Array, Vector, HashMaps etc.)
Aggregation operations Input and Output
The java.io class Library
Input and Output structure
Handling textual data with "Reader" and "Writer" streams
File System I/O Basic Graphics
The Java graphics framework
Abstract Windowing Toolkit (java.awt)
The Java Swing Library (javax.swing)
The Java event model
Basic UI elements
Labels
TextFields
Buttons
Panels
Frames
Event Processing and Propagation
Handling Graphical Events using Event Listeners Java Applets
Web-based client Development
The java.applet package
Issues in network security
The java "Sandbox" model of security
Applet limitations
Building an applet-based application Java Database Connectivity (JDBC)
Fundamentals of Database Programming
Using the JDBC API
JDBC connectivity types
Bridging technology
Native API
Middleware
Pure Java Drivers
Loading JDBC drivers
Connection
Statements
ResultSets
Meta Data
Advanced J2EE
Advanced J2EE
Duration: 5 Days
Audience
Prerequisites
This course has been specially designed for professionals with prior exposure to J2EE and looking to build large-scale, scalable, robust, secure, transactional distributed E-Business systems using the advanced features of the J2EE platform. Professionals who have at least one year of experience with programming in Java.
Architects
Designers
Consultants
Developers
J2EE
Description
The Java 2 Enterprise Edition (J2EE) provides an object-oriented, distributed and cross-platform framework for developing and deploying robust, secure and scalable E-Business and E-Commerce applications. In this course, you will master advanced concepts, design strategies and implementation techniques for building highly efficient and maintainable production-strength J2EE based systems.
This course may be delivered on Rational Application Developer 6.0, WSAD 5.1.2, or WebLogic Server 8.x. Please contact us if you need delvery on other platforms.
Objectives
This course teaches an advanced set of concepts and technologies of the J2EE platform with an emphasis in the areas of performance, security, distributed transactions, advanced persistence mapping of components, asynchronous components and Web tier architecture. On completion, attendees would be able to:
Configuring application server's security settings to support J2EE's declarative security features
Develop portable and extensible security features in a J2EE application using JAAS
Master the transaction model in J2EE to develop applications that span transactions over multiple transactional resources
Master the EJB QL query language to implement custom finders and ejbSelect ejbHome methods
Design and implement asynchronous enterprise components using the Message-Driven Bean
Master the J2EE Connector 1.5 architecture
Design and implement a model-2 framework for the Web tier
Course Outline
OOA/D for Enterprise Development
System development process
Domain modeling: informal sketch
Instance diagram
Structure: type diagram
System analysis: context model
Design: architecture
Sequence diagram
Design class diagram
Type model
Advanced Topics in Developing CMP Beans
CMP relationships and assignment semantics
EJB Query language
EJB QL queries - Select Clause
EJB QL queries - From Clause
EJB QL queries - Where Clause
Writing complex EJB QL queries
ejbSelect methods
ejbHome methods
Developing BMP Entity Beans
Why BMP beans
Lide-cycle of BMP entity bean
Activation and persistence of BMP beanss
Data source and BMP beans
Using Data Access Objects to implement BMP beans
EJB Transactions
Overview of transaction concepts
Container managed transaction attributes
Bean managed transactions
UserTransaction interface
SessionSynchronization interface
Exception handlings and transactions
Advanced Web Tier Architecture
Model-2 Architecture
Life Cycle Events
Event Handling for the Model-2 Framework
Sensitive Form Resubmission
Event Handling for Sensitive Forms
J2EE Security Architecture
Overview of security issues in enterprise applications
Security Roles and Principals
Web Tier Security
EJB Security
Issues in Authentication (declarative vs imperative)
Class and instance security
Security context propagation
JAAS
Overview of the JAAS Framework
Authentication using LoginContext and LoginModule
Using the JAAS configuration file to dynamically plug in modules
Specifying permissions using JAAS policy files
Java Connector Architecture (JCA)
Overview of JCA 1.5
Legacy integration
Connection management
Transaction management
JCA security architecture
Connection to Messaging Systems (WebSphere MQ, etc.)
JCA resource adapter
Developing Message-Driven Beans
Message-Driven Beans and JMS destination
Client view of MDB
MDB lifecycle
Deployment descriptors for MDB
MDB with JCA resource adapter
J2EE and Clustered Deployment Environment
Clustering overview
J2EE and clustering
Clustering in WebSphere Application Server
Addressing performance or scalability problems
Duration: 5 Days
Audience
Prerequisites
This course has been specially designed for professionals with prior exposure to J2EE and looking to build large-scale, scalable, robust, secure, transactional distributed E-Business systems using the advanced features of the J2EE platform. Professionals who have at least one year of experience with programming in Java.
Architects
Designers
Consultants
Developers
J2EE
Description
The Java 2 Enterprise Edition (J2EE) provides an object-oriented, distributed and cross-platform framework for developing and deploying robust, secure and scalable E-Business and E-Commerce applications. In this course, you will master advanced concepts, design strategies and implementation techniques for building highly efficient and maintainable production-strength J2EE based systems.
This course may be delivered on Rational Application Developer 6.0, WSAD 5.1.2, or WebLogic Server 8.x. Please contact us if you need delvery on other platforms.
Objectives
This course teaches an advanced set of concepts and technologies of the J2EE platform with an emphasis in the areas of performance, security, distributed transactions, advanced persistence mapping of components, asynchronous components and Web tier architecture. On completion, attendees would be able to:
Configuring application server's security settings to support J2EE's declarative security features
Develop portable and extensible security features in a J2EE application using JAAS
Master the transaction model in J2EE to develop applications that span transactions over multiple transactional resources
Master the EJB QL query language to implement custom finders and ejbSelect ejbHome methods
Design and implement asynchronous enterprise components using the Message-Driven Bean
Master the J2EE Connector 1.5 architecture
Design and implement a model-2 framework for the Web tier
Course Outline
OOA/D for Enterprise Development
System development process
Domain modeling: informal sketch
Instance diagram
Structure: type diagram
System analysis: context model
Design: architecture
Sequence diagram
Design class diagram
Type model
Advanced Topics in Developing CMP Beans
CMP relationships and assignment semantics
EJB Query language
EJB QL queries - Select Clause
EJB QL queries - From Clause
EJB QL queries - Where Clause
Writing complex EJB QL queries
ejbSelect methods
ejbHome methods
Developing BMP Entity Beans
Why BMP beans
Lide-cycle of BMP entity bean
Activation and persistence of BMP beanss
Data source and BMP beans
Using Data Access Objects to implement BMP beans
EJB Transactions
Overview of transaction concepts
Container managed transaction attributes
Bean managed transactions
UserTransaction interface
SessionSynchronization interface
Exception handlings and transactions
Advanced Web Tier Architecture
Model-2 Architecture
Life Cycle Events
Event Handling for the Model-2 Framework
Sensitive Form Resubmission
Event Handling for Sensitive Forms
J2EE Security Architecture
Overview of security issues in enterprise applications
Security Roles and Principals
Web Tier Security
EJB Security
Issues in Authentication (declarative vs imperative)
Class and instance security
Security context propagation
JAAS
Overview of the JAAS Framework
Authentication using LoginContext and LoginModule
Using the JAAS configuration file to dynamically plug in modules
Specifying permissions using JAAS policy files
Java Connector Architecture (JCA)
Overview of JCA 1.5
Legacy integration
Connection management
Transaction management
JCA security architecture
Connection to Messaging Systems (WebSphere MQ, etc.)
JCA resource adapter
Developing Message-Driven Beans
Message-Driven Beans and JMS destination
Client view of MDB
MDB lifecycle
Deployment descriptors for MDB
MDB with JCA resource adapter
J2EE and Clustered Deployment Environment
Clustering overview
J2EE and clustering
Clustering in WebSphere Application Server
Addressing performance or scalability problems
about Advance java
Advanced Java
Duration: 5 days
Audience
Prerequisites
Application Developers
System Designers
Experience with Java is essential
Intense Java for C/C++ Programmers, or
Basic Java or Java for COBOL Programmers with practical Java Programming experience after completion of the course.
Description
This advanced course is designed for software professionals seeking to design and develop applications using the Java 2 Standard Edition (J2SE) and WebSphere Application Developer (WSAD). Based on InferData's well-received training methodologies, the course provides for a rapid, efficient (and, yes, intense) immersion into advanced Java topics.This five-day course covers topics in Java Foundation Classes (JFC), Swing Components, JavaBeans, Reflection, Network Programming, Remote Method Invocation (RMI), Java Database Connectivity (JDBC) and JDBC 2.0 and Java Security.Participants will master the fundamentals of graphical user interface development using the Java Swing library. Using the Visual Composition Editor in VisualAge for Java, attendees build, package, deploy and test JavaBeans. This course cover topics in distributed computing using both the Java network class library and the RMI framework. Database programming topics also include Transactions, query execution with ad-hoc queries, compiled queries and stored procedure statements using JDBC. We also cover advanced JDBC topics, such as distributed transactions, scrollable result sets etc., using the JDBC 2.0 and JDBC 3.0 API. The Java security model and the class library is also covered in sufficient detail.This course consists of a large number of fully worked out example code illustrating various concepts introduced during the course. The concepts are further reinforced through the use of well-crafted exercises at appropriate points throughout the course.
Objectives
objectives
Course Outline
Java Swing
Event Model
GUI Elements
JFrame
JPanel
Jbutton
Scrollbars
Split Panes
Tabled Panes
Layout Managers
Flow Layout
Grid Layout
Gridbad Layout
Border Layout
Box Layout
JTable
Table model
Table events
Listeners
Selections
Custom rendering of cells
Editing table elements
Writing custom editors JList
List model
Events & Listeners
Selection models
Custom rendering
Editing elements Combo Box
Model
Events & Listeners
Selection
Custom rendering
Custom editors JTree
Tree Model
Listeners
Selection model
Custom rendering
Custom editing Network Programming
Java.net package
Sockets
Client-Server Programing
Mapping Streams to Sockets
Building a multithreaded client server system Remote Method Invocation (RMI)
Distributed Objects
Concepts in distributed computing
The Proxy design pattern
Specifying remote interfaces
Distributed Java Objects
Using RMI compiler
Specifying security policies
Installing security managers
RMI-IIOP protocol Java Database Connectivity (JDBC)
Fundamentals of Database Programming
Using the JDBC API
JDBC connectivity types
Bridging technology
Native API
Middleware
Pure Java Drivers
Loading JDBC drivers
Connection
Statements
ResultSets
Meta Data
Database MetaData
ResultSet MetaData
JDBC Extentions (JDBC 2.0)
Scrollable Result Sets
Accessing the Transaction Manager
Two-Phase Commit
Data Sources
Connection Pools
Text Editors
Text Model
Editor & Editor kits
Events & Listeners
Selections
Displaying data
Multiple colors
Multiple fonts
Embedding images in text areas
Embedding components in text areas
Displaying HTML Java Reflection
Reflection programming
Concept of a "Meta" class
Benefits of meta programming
Runtime representation of classes
The Class class
Dynamic loading of classes
Instantiating objects programmatically
Representing methods
Invoking methods dynamically
Runtime representation of attributes
Dealing with primitive types Java Beans
Component based application development
Fundamentals of Java Beans
Properties
Conventions
Property Editors
Building Simple Java Beans
Exporting Properties Explicitly
Using the "BeanInfo" interface
Property Descriptors
Method Descriptors
Event Descriptors
Custom rendering of properties
Specifying property editors
Design and development of custom property editors
Designing Java Bean customizers
Packaging and deploying Java Beans Using Java Beans
Accessing pre-built Java Beans from the visual composition editor
Instantiation and customization of Java Beans using property editors
Assembling Java Beans to build applications visually
Storing and distributing a Java Bean assembled application Fundamentals of Cryptography
Public Key Cryptography
Signatures
Digest
Certificates (X.509)
Authentication Java Security
Sandbox model
Security Manager
Policy
Permissions
Domains
Java Cryptography Extension (JCE) Java Security Tools
Policy Tool
Key Tool
Jar Signer
Duration: 5 days
Audience
Prerequisites
Application Developers
System Designers
Experience with Java is essential
Intense Java for C/C++ Programmers, or
Basic Java or Java for COBOL Programmers with practical Java Programming experience after completion of the course.
Description
This advanced course is designed for software professionals seeking to design and develop applications using the Java 2 Standard Edition (J2SE) and WebSphere Application Developer (WSAD). Based on InferData's well-received training methodologies, the course provides for a rapid, efficient (and, yes, intense) immersion into advanced Java topics.This five-day course covers topics in Java Foundation Classes (JFC), Swing Components, JavaBeans, Reflection, Network Programming, Remote Method Invocation (RMI), Java Database Connectivity (JDBC) and JDBC 2.0 and Java Security.Participants will master the fundamentals of graphical user interface development using the Java Swing library. Using the Visual Composition Editor in VisualAge for Java, attendees build, package, deploy and test JavaBeans. This course cover topics in distributed computing using both the Java network class library and the RMI framework. Database programming topics also include Transactions, query execution with ad-hoc queries, compiled queries and stored procedure statements using JDBC. We also cover advanced JDBC topics, such as distributed transactions, scrollable result sets etc., using the JDBC 2.0 and JDBC 3.0 API. The Java security model and the class library is also covered in sufficient detail.This course consists of a large number of fully worked out example code illustrating various concepts introduced during the course. The concepts are further reinforced through the use of well-crafted exercises at appropriate points throughout the course.
Objectives
objectives
Course Outline
Java Swing
Event Model
GUI Elements
JFrame
JPanel
Jbutton
Scrollbars
Split Panes
Tabled Panes
Layout Managers
Flow Layout
Grid Layout
Gridbad Layout
Border Layout
Box Layout
JTable
Table model
Table events
Listeners
Selections
Custom rendering of cells
Editing table elements
Writing custom editors JList
List model
Events & Listeners
Selection models
Custom rendering
Editing elements Combo Box
Model
Events & Listeners
Selection
Custom rendering
Custom editors JTree
Tree Model
Listeners
Selection model
Custom rendering
Custom editing Network Programming
Java.net package
Sockets
Client-Server Programing
Mapping Streams to Sockets
Building a multithreaded client server system Remote Method Invocation (RMI)
Distributed Objects
Concepts in distributed computing
The Proxy design pattern
Specifying remote interfaces
Distributed Java Objects
Using RMI compiler
Specifying security policies
Installing security managers
RMI-IIOP protocol Java Database Connectivity (JDBC)
Fundamentals of Database Programming
Using the JDBC API
JDBC connectivity types
Bridging technology
Native API
Middleware
Pure Java Drivers
Loading JDBC drivers
Connection
Statements
ResultSets
Meta Data
Database MetaData
ResultSet MetaData
JDBC Extentions (JDBC 2.0)
Scrollable Result Sets
Accessing the Transaction Manager
Two-Phase Commit
Data Sources
Connection Pools
Text Editors
Text Model
Editor & Editor kits
Events & Listeners
Selections
Displaying data
Multiple colors
Multiple fonts
Embedding images in text areas
Embedding components in text areas
Displaying HTML Java Reflection
Reflection programming
Concept of a "Meta" class
Benefits of meta programming
Runtime representation of classes
The Class class
Dynamic loading of classes
Instantiating objects programmatically
Representing methods
Invoking methods dynamically
Runtime representation of attributes
Dealing with primitive types Java Beans
Component based application development
Fundamentals of Java Beans
Properties
Conventions
Property Editors
Building Simple Java Beans
Exporting Properties Explicitly
Using the "BeanInfo" interface
Property Descriptors
Method Descriptors
Event Descriptors
Custom rendering of properties
Specifying property editors
Design and development of custom property editors
Designing Java Bean customizers
Packaging and deploying Java Beans Using Java Beans
Accessing pre-built Java Beans from the visual composition editor
Instantiation and customization of Java Beans using property editors
Assembling Java Beans to build applications visually
Storing and distributing a Java Bean assembled application Fundamentals of Cryptography
Public Key Cryptography
Signatures
Digest
Certificates (X.509)
Authentication Java Security
Sandbox model
Security Manager
Policy
Permissions
Domains
Java Cryptography Extension (JCE) Java Security Tools
Policy Tool
Key Tool
Jar Signer
Thursday, May 31, 2007
Pointer types and Arrays
CHAPTER 2: Pointer types and Arrays
Okay, let's move on. Let us consider why we need to identify the type of variable that a pointer points to, as in:
int *ptr;
One reason for doing this is so that later, once ptr "points to" something, if we write:
*ptr = 2;
the compiler will know how many bytes to copy into that memory location pointed to by ptr. If ptr was declared as pointing to an integer, 4 bytes would be copied. Similarly for floats and doubles the appropriate number will be copied. But, defining the type that the pointer points to permits a number of other interesting ways a compiler can interpret code. For example, consider a block in memory consisting if ten integers in a row. That is, 40 bytes of memory are set aside to hold 10 integers.
Now, let's say we point our integer pointer ptr at the first of these integers. Furthermore lets say that integer is located at memory location 100 (decimal). What happens when we write:
ptr + 1;
Because the compiler "knows" this is a pointer (i.e. its value is an address) and that it points to an integer (its current address, 100, is the address of an integer), it adds 4 to ptr instead of 1, so the pointer "points to" the next integer, at memory location 104. Similarly, were the ptr declared as a pointer to a short, it would add 2 to it instead of 1. The same goes for other data types such as floats, doubles, or even user defined data types such as structures. This is obviously not the same kind of "addition" that we normally think of. In C it is referred to as addition using "pointer arithmetic", a term which we will come back to later.
Similarly, since ++ptr and ptr++ are both equivalent to ptr + 1 (though the point in the program when ptr is incremented may be different), incrementing a pointer using the unary ++ operator, either pre- or post-, increments the address it stores by the amount sizeof(type) where "type" is the type of the object pointed to. (i.e. 4 for an integer).
Since a block of 10 integers located contiguously in memory is, by definition, an array of integers, this brings up an interesting relationship between arrays and pointers.
Consider the following:
int my_array[] = {1,23,17,4,-5,100};
Here we have an array containing 6 integers. We refer to each of these integers by means of a subscript to my_array, i.e. using my_array[0] through my_array[5]. But, we could alternatively access them via a pointer as follows:
int *ptr;
ptr = &my_array[0]; /* point our pointer at the first
integer in our array */
And then we could print out our array either using the array notation or by dereferencing our pointer. The following code illustrates this:
----------- Program 2.1 -----------------------------------
/* Program 2.1 from PTRTUT10.HTM 6/13/97 */
#include
int my_array[] = {1,23,17,4,-5,100};
int *ptr;
int main(void)
{
int i;
ptr = &my_array[0]; /* point our pointer to the first
element of the array */
printf("\n\n");
for (i = 0; i < 6; i++)
{
printf("my_array[%d] = %d ",i,my_array[i]); /*<-- A */
printf("ptr + %d = %d\n",i, *(ptr + i)); /*<-- B */
}
return 0;
}
Compile and run the above program and carefully note lines A and B and that the program prints out the same values in either case. Also observe how we dereferenced our pointer in line B, i.e. we first added i to it and then dereferenced the new pointer. Change line B to read:
printf("ptr + %d = %d\n",i, *ptr++);
and run it again... then change it to:
printf("ptr + %d = %d\n",i, *(++ptr));
and try once more. Each time try and predict the outcome and carefully look at the actual outcome.
In C, the standard states that wherever we might use &var_name[0] we can replace that with var_name, thus in our code where we wrote:
ptr = &my_array[0];
we can write:
ptr = my_array;
to achieve the same result.
This leads many texts to state that the name of an array is a pointer. I prefer to mentally think "the name of the array is the address of first element in the array". Many beginners (including myself when I was learning) have a tendency to become confused by thinking of it as a pointer. For example, while we can write
ptr = my_array;
we cannot write
my_array = ptr;
The reason is that while ptr is a variable, my_array is a constant. That is, the location at which the first element of my_array will be stored cannot be changed once my_array[] has been declared.
Earlier when discussing the term "lvalue" I cited K&R-2 where it stated:
"An object is a named region of storage; an lvalue is an expression referring to an object".
This raises an interesting problem. Since my_array is a named region of storage, why is my_array in the above assignment statement not an lvalue? To resolve this problem, some refer to my_array as an "unmodifiable lvalue".
Modify the example program above by changing
ptr = &my_array[0];
to
ptr = my_array;
and run it again to verify the results are identical.
Now, let's delve a little further into the difference between the names ptr and my_array as used above. Some writers will refer to an array's name as a constant pointer. What do we mean by that? Well, to understand the term "constant" in this sense, let's go back to our definition of the term "variable". When we declare a variable we set aside a spot in memory to hold the value of the appropriate type. Once that is done the name of the variable can be interpreted in one of two ways. When used on the left side of the assignment operator, the compiler interprets it as the memory location to which to move that value resulting from evaluation of the right side of the assignment operator. But, when used on the right side of the assignment operator, the name of a variable is interpreted to mean the contents stored at that memory address set aside to hold the value of that variable.
With that in mind, let's now consider the simplest of constants, as in:
int i, k;
i = 2;
Here, while i is a variable and then occupies space in the data portion of memory, 2 is a constant and, as such, instead of setting aside memory in the data segment, it is imbedded directly in the code segment of memory. That is, while writing something like k = i; tells the compiler to create code which at run time will look at memory location &i to determine the value to be moved to k, code created by i = 2; simply puts the 2 in the code and there is no referencing of the data segment. That is, both k and i are objects, but 2 is not an object.
Similarly, in the above, since my_array is a constant, once the compiler establishes where the array itself is to be stored, it "knows" the address of my_array[0] and on seeing:
ptr = my_array;
it simply uses this address as a constant in the code segment and there is no referencing of the data segment beyond that.
This might be a good place explain further the use of the (void *) expression used in Program 1.1 of Chapter 1. As we have seen we can have pointers of various types. So far we have discussed pointers to integers and pointers to characters. In coming chapters we will be learning about pointers to structures and even pointer to pointers.
Also we have learned that on different systems the size of a pointer can vary. As it turns out it is also possible that the size of a pointer can vary depending on the data type of the object to which it points. Thus, as with integers where you can run into trouble attempting to assign a long integer to a variable of type short integer, you can run into trouble attempting to assign the values of pointers of various types to pointer variables of other types.
To minimize this problem, C provides for a pointer of type void. We can declare such a pointer by writing:
void *vptr;
A void pointer is sort of a generic pointer. For example, while C will not permit the comparison of a pointer to type integer with a pointer to type character, for example, either of these can be compared to a void pointer. Of course, as with other variables, casts can be used to convert from one type of pointer to another under the proper circumstances. In Program 1.1. of Chapter 1 I cast the pointers to integers into void pointers to make them compatible with the %p conversion specification. In later chapters other casts will be made for reasons defined therein.
Well, that's a lot of technical stuff to digest and I don't expect a beginner to understand all of it on first reading. With time and experimentation you will want to come back and re-read the first 2 chapters. But for now, let's move on to the relationship between pointers, character arrays, and strings.
Continue with Pointer Tutorial
Okay, let's move on. Let us consider why we need to identify the type of variable that a pointer points to, as in:
int *ptr;
One reason for doing this is so that later, once ptr "points to" something, if we write:
*ptr = 2;
the compiler will know how many bytes to copy into that memory location pointed to by ptr. If ptr was declared as pointing to an integer, 4 bytes would be copied. Similarly for floats and doubles the appropriate number will be copied. But, defining the type that the pointer points to permits a number of other interesting ways a compiler can interpret code. For example, consider a block in memory consisting if ten integers in a row. That is, 40 bytes of memory are set aside to hold 10 integers.
Now, let's say we point our integer pointer ptr at the first of these integers. Furthermore lets say that integer is located at memory location 100 (decimal). What happens when we write:
ptr + 1;
Because the compiler "knows" this is a pointer (i.e. its value is an address) and that it points to an integer (its current address, 100, is the address of an integer), it adds 4 to ptr instead of 1, so the pointer "points to" the next integer, at memory location 104. Similarly, were the ptr declared as a pointer to a short, it would add 2 to it instead of 1. The same goes for other data types such as floats, doubles, or even user defined data types such as structures. This is obviously not the same kind of "addition" that we normally think of. In C it is referred to as addition using "pointer arithmetic", a term which we will come back to later.
Similarly, since ++ptr and ptr++ are both equivalent to ptr + 1 (though the point in the program when ptr is incremented may be different), incrementing a pointer using the unary ++ operator, either pre- or post-, increments the address it stores by the amount sizeof(type) where "type" is the type of the object pointed to. (i.e. 4 for an integer).
Since a block of 10 integers located contiguously in memory is, by definition, an array of integers, this brings up an interesting relationship between arrays and pointers.
Consider the following:
int my_array[] = {1,23,17,4,-5,100};
Here we have an array containing 6 integers. We refer to each of these integers by means of a subscript to my_array, i.e. using my_array[0] through my_array[5]. But, we could alternatively access them via a pointer as follows:
int *ptr;
ptr = &my_array[0]; /* point our pointer at the first
integer in our array */
And then we could print out our array either using the array notation or by dereferencing our pointer. The following code illustrates this:
----------- Program 2.1 -----------------------------------
/* Program 2.1 from PTRTUT10.HTM 6/13/97 */
#include
int my_array[] = {1,23,17,4,-5,100};
int *ptr;
int main(void)
{
int i;
ptr = &my_array[0]; /* point our pointer to the first
element of the array */
printf("\n\n");
for (i = 0; i < 6; i++)
{
printf("my_array[%d] = %d ",i,my_array[i]); /*<-- A */
printf("ptr + %d = %d\n",i, *(ptr + i)); /*<-- B */
}
return 0;
}
Compile and run the above program and carefully note lines A and B and that the program prints out the same values in either case. Also observe how we dereferenced our pointer in line B, i.e. we first added i to it and then dereferenced the new pointer. Change line B to read:
printf("ptr + %d = %d\n",i, *ptr++);
and run it again... then change it to:
printf("ptr + %d = %d\n",i, *(++ptr));
and try once more. Each time try and predict the outcome and carefully look at the actual outcome.
In C, the standard states that wherever we might use &var_name[0] we can replace that with var_name, thus in our code where we wrote:
ptr = &my_array[0];
we can write:
ptr = my_array;
to achieve the same result.
This leads many texts to state that the name of an array is a pointer. I prefer to mentally think "the name of the array is the address of first element in the array". Many beginners (including myself when I was learning) have a tendency to become confused by thinking of it as a pointer. For example, while we can write
ptr = my_array;
we cannot write
my_array = ptr;
The reason is that while ptr is a variable, my_array is a constant. That is, the location at which the first element of my_array will be stored cannot be changed once my_array[] has been declared.
Earlier when discussing the term "lvalue" I cited K&R-2 where it stated:
"An object is a named region of storage; an lvalue is an expression referring to an object".
This raises an interesting problem. Since my_array is a named region of storage, why is my_array in the above assignment statement not an lvalue? To resolve this problem, some refer to my_array as an "unmodifiable lvalue".
Modify the example program above by changing
ptr = &my_array[0];
to
ptr = my_array;
and run it again to verify the results are identical.
Now, let's delve a little further into the difference between the names ptr and my_array as used above. Some writers will refer to an array's name as a constant pointer. What do we mean by that? Well, to understand the term "constant" in this sense, let's go back to our definition of the term "variable". When we declare a variable we set aside a spot in memory to hold the value of the appropriate type. Once that is done the name of the variable can be interpreted in one of two ways. When used on the left side of the assignment operator, the compiler interprets it as the memory location to which to move that value resulting from evaluation of the right side of the assignment operator. But, when used on the right side of the assignment operator, the name of a variable is interpreted to mean the contents stored at that memory address set aside to hold the value of that variable.
With that in mind, let's now consider the simplest of constants, as in:
int i, k;
i = 2;
Here, while i is a variable and then occupies space in the data portion of memory, 2 is a constant and, as such, instead of setting aside memory in the data segment, it is imbedded directly in the code segment of memory. That is, while writing something like k = i; tells the compiler to create code which at run time will look at memory location &i to determine the value to be moved to k, code created by i = 2; simply puts the 2 in the code and there is no referencing of the data segment. That is, both k and i are objects, but 2 is not an object.
Similarly, in the above, since my_array is a constant, once the compiler establishes where the array itself is to be stored, it "knows" the address of my_array[0] and on seeing:
ptr = my_array;
it simply uses this address as a constant in the code segment and there is no referencing of the data segment beyond that.
This might be a good place explain further the use of the (void *) expression used in Program 1.1 of Chapter 1. As we have seen we can have pointers of various types. So far we have discussed pointers to integers and pointers to characters. In coming chapters we will be learning about pointers to structures and even pointer to pointers.
Also we have learned that on different systems the size of a pointer can vary. As it turns out it is also possible that the size of a pointer can vary depending on the data type of the object to which it points. Thus, as with integers where you can run into trouble attempting to assign a long integer to a variable of type short integer, you can run into trouble attempting to assign the values of pointers of various types to pointer variables of other types.
To minimize this problem, C provides for a pointer of type void. We can declare such a pointer by writing:
void *vptr;
A void pointer is sort of a generic pointer. For example, while C will not permit the comparison of a pointer to type integer with a pointer to type character, for example, either of these can be compared to a void pointer. Of course, as with other variables, casts can be used to convert from one type of pointer to another under the proper circumstances. In Program 1.1. of Chapter 1 I cast the pointers to integers into void pointers to make them compatible with the %p conversion specification. In later chapters other casts will be made for reasons defined therein.
Well, that's a lot of technical stuff to digest and I don't expect a beginner to understand all of it on first reading. With time and experimentation you will want to come back and re-read the first 2 chapters. But for now, let's move on to the relationship between pointers, character arrays, and strings.
Continue with Pointer Tutorial
Pointer types and Arrays
CHAPTER 2: Pointer types and Arrays
Okay, let's move on. Let us consider why we need to identify the type of variable that a pointer points to, as in:
int *ptr;
One reason for doing this is so that later, once ptr "points to" something, if we write:
*ptr = 2;
the compiler will know how many bytes to copy into that memory location pointed to by ptr. If ptr was declared as pointing to an integer, 4 bytes would be copied. Similarly for floats and doubles the appropriate number will be copied. But, defining the type that the pointer points to permits a number of other interesting ways a compiler can interpret code. For example, consider a block in memory consisting if ten integers in a row. That is, 40 bytes of memory are set aside to hold 10 integers.
Now, let's say we point our integer pointer ptr at the first of these integers. Furthermore lets say that integer is located at memory location 100 (decimal). What happens when we write:
ptr + 1;
Because the compiler "knows" this is a pointer (i.e. its value is an address) and that it points to an integer (its current address, 100, is the address of an integer), it adds 4 to ptr instead of 1, so the pointer "points to" the next integer, at memory location 104. Similarly, were the ptr declared as a pointer to a short, it would add 2 to it instead of 1. The same goes for other data types such as floats, doubles, or even user defined data types such as structures. This is obviously not the same kind of "addition" that we normally think of. In C it is referred to as addition using "pointer arithmetic", a term which we will come back to later.
Similarly, since ++ptr and ptr++ are both equivalent to ptr + 1 (though the point in the program when ptr is incremented may be different), incrementing a pointer using the unary ++ operator, either pre- or post-, increments the address it stores by the amount sizeof(type) where "type" is the type of the object pointed to. (i.e. 4 for an integer).
Since a block of 10 integers located contiguously in memory is, by definition, an array of integers, this brings up an interesting relationship between arrays and pointers.
Consider the following:
int my_array[] = {1,23,17,4,-5,100};
Here we have an array containing 6 integers. We refer to each of these integers by means of a subscript to my_array, i.e. using my_array[0] through my_array[5]. But, we could alternatively access them via a pointer as follows:
int *ptr;
ptr = &my_array[0]; /* point our pointer at the first
integer in our array */
And then we could print out our array either using the array notation or by dereferencing our pointer. The following code illustrates this:
----------- Program 2.1 -----------------------------------
/* Program 2.1 from PTRTUT10.HTM 6/13/97 */
#include
int my_array[] = {1,23,17,4,-5,100};
int *ptr;
int main(void)
{
int i;
ptr = &my_array[0]; /* point our pointer to the first
element of the array */
printf("\n\n");
for (i = 0; i < 6; i++)
{
printf("my_array[%d] = %d ",i,my_array[i]); /*<-- A */
printf("ptr + %d = %d\n",i, *(ptr + i)); /*<-- B */
}
return 0;
}
Compile and run the above program and carefully note lines A and B and that the program prints out the same values in either case. Also observe how we dereferenced our pointer in line B, i.e. we first added i to it and then dereferenced the new pointer. Change line B to read:
printf("ptr + %d = %d\n",i, *ptr++);
and run it again... then change it to:
printf("ptr + %d = %d\n",i, *(++ptr));
and try once more. Each time try and predict the outcome and carefully look at the actual outcome.
In C, the standard states that wherever we might use &var_name[0] we can replace that with var_name, thus in our code where we wrote:
ptr = &my_array[0];
we can write:
ptr = my_array;
to achieve the same result.
This leads many texts to state that the name of an array is a pointer. I prefer to mentally think "the name of the array is the address of first element in the array". Many beginners (including myself when I was learning) have a tendency to become confused by thinking of it as a pointer. For example, while we can write
ptr = my_array;
we cannot write
my_array = ptr;
The reason is that while ptr is a variable, my_array is a constant. That is, the location at which the first element of my_array will be stored cannot be changed once my_array[] has been declared.
Earlier when discussing the term "lvalue" I cited K&R-2 where it stated:
"An object is a named region of storage; an lvalue is an expression referring to an object".
This raises an interesting problem. Since my_array is a named region of storage, why is my_array in the above assignment statement not an lvalue? To resolve this problem, some refer to my_array as an "unmodifiable lvalue".
Modify the example program above by changing
ptr = &my_array[0];
to
ptr = my_array;
and run it again to verify the results are identical.
Now, let's delve a little further into the difference between the names ptr and my_array as used above. Some writers will refer to an array's name as a constant pointer. What do we mean by that? Well, to understand the term "constant" in this sense, let's go back to our definition of the term "variable". When we declare a variable we set aside a spot in memory to hold the value of the appropriate type. Once that is done the name of the variable can be interpreted in one of two ways. When used on the left side of the assignment operator, the compiler interprets it as the memory location to which to move that value resulting from evaluation of the right side of the assignment operator. But, when used on the right side of the assignment operator, the name of a variable is interpreted to mean the contents stored at that memory address set aside to hold the value of that variable.
With that in mind, let's now consider the simplest of constants, as in:
int i, k;
i = 2;
Here, while i is a variable and then occupies space in the data portion of memory, 2 is a constant and, as such, instead of setting aside memory in the data segment, it is imbedded directly in the code segment of memory. That is, while writing something like k = i; tells the compiler to create code which at run time will look at memory location &i to determine the value to be moved to k, code created by i = 2; simply puts the 2 in the code and there is no referencing of the data segment. That is, both k and i are objects, but 2 is not an object.
Similarly, in the above, since my_array is a constant, once the compiler establishes where the array itself is to be stored, it "knows" the address of my_array[0] and on seeing:
ptr = my_array;
it simply uses this address as a constant in the code segment and there is no referencing of the data segment beyond that.
This might be a good place explain further the use of the (void *) expression used in Program 1.1 of Chapter 1. As we have seen we can have pointers of various types. So far we have discussed pointers to integers and pointers to characters. In coming chapters we will be learning about pointers to structures and even pointer to pointers.
Also we have learned that on different systems the size of a pointer can vary. As it turns out it is also possible that the size of a pointer can vary depending on the data type of the object to which it points. Thus, as with integers where you can run into trouble attempting to assign a long integer to a variable of type short integer, you can run into trouble attempting to assign the values of pointers of various types to pointer variables of other types.
To minimize this problem, C provides for a pointer of type void. We can declare such a pointer by writing:
void *vptr;
A void pointer is sort of a generic pointer. For example, while C will not permit the comparison of a pointer to type integer with a pointer to type character, for example, either of these can be compared to a void pointer. Of course, as with other variables, casts can be used to convert from one type of pointer to another under the proper circumstances. In Program 1.1. of Chapter 1 I cast the pointers to integers into void pointers to make them compatible with the %p conversion specification. In later chapters other casts will be made for reasons defined therein.
Well, that's a lot of technical stuff to digest and I don't expect a beginner to understand all of it on first reading. With time and experimentation you will want to come back and re-read the first 2 chapters. But for now, let's move on to the relationship between pointers, character arrays, and strings.
Continue with Pointer Tutorial
Okay, let's move on. Let us consider why we need to identify the type of variable that a pointer points to, as in:
int *ptr;
One reason for doing this is so that later, once ptr "points to" something, if we write:
*ptr = 2;
the compiler will know how many bytes to copy into that memory location pointed to by ptr. If ptr was declared as pointing to an integer, 4 bytes would be copied. Similarly for floats and doubles the appropriate number will be copied. But, defining the type that the pointer points to permits a number of other interesting ways a compiler can interpret code. For example, consider a block in memory consisting if ten integers in a row. That is, 40 bytes of memory are set aside to hold 10 integers.
Now, let's say we point our integer pointer ptr at the first of these integers. Furthermore lets say that integer is located at memory location 100 (decimal). What happens when we write:
ptr + 1;
Because the compiler "knows" this is a pointer (i.e. its value is an address) and that it points to an integer (its current address, 100, is the address of an integer), it adds 4 to ptr instead of 1, so the pointer "points to" the next integer, at memory location 104. Similarly, were the ptr declared as a pointer to a short, it would add 2 to it instead of 1. The same goes for other data types such as floats, doubles, or even user defined data types such as structures. This is obviously not the same kind of "addition" that we normally think of. In C it is referred to as addition using "pointer arithmetic", a term which we will come back to later.
Similarly, since ++ptr and ptr++ are both equivalent to ptr + 1 (though the point in the program when ptr is incremented may be different), incrementing a pointer using the unary ++ operator, either pre- or post-, increments the address it stores by the amount sizeof(type) where "type" is the type of the object pointed to. (i.e. 4 for an integer).
Since a block of 10 integers located contiguously in memory is, by definition, an array of integers, this brings up an interesting relationship between arrays and pointers.
Consider the following:
int my_array[] = {1,23,17,4,-5,100};
Here we have an array containing 6 integers. We refer to each of these integers by means of a subscript to my_array, i.e. using my_array[0] through my_array[5]. But, we could alternatively access them via a pointer as follows:
int *ptr;
ptr = &my_array[0]; /* point our pointer at the first
integer in our array */
And then we could print out our array either using the array notation or by dereferencing our pointer. The following code illustrates this:
----------- Program 2.1 -----------------------------------
/* Program 2.1 from PTRTUT10.HTM 6/13/97 */
#include
int my_array[] = {1,23,17,4,-5,100};
int *ptr;
int main(void)
{
int i;
ptr = &my_array[0]; /* point our pointer to the first
element of the array */
printf("\n\n");
for (i = 0; i < 6; i++)
{
printf("my_array[%d] = %d ",i,my_array[i]); /*<-- A */
printf("ptr + %d = %d\n",i, *(ptr + i)); /*<-- B */
}
return 0;
}
Compile and run the above program and carefully note lines A and B and that the program prints out the same values in either case. Also observe how we dereferenced our pointer in line B, i.e. we first added i to it and then dereferenced the new pointer. Change line B to read:
printf("ptr + %d = %d\n",i, *ptr++);
and run it again... then change it to:
printf("ptr + %d = %d\n",i, *(++ptr));
and try once more. Each time try and predict the outcome and carefully look at the actual outcome.
In C, the standard states that wherever we might use &var_name[0] we can replace that with var_name, thus in our code where we wrote:
ptr = &my_array[0];
we can write:
ptr = my_array;
to achieve the same result.
This leads many texts to state that the name of an array is a pointer. I prefer to mentally think "the name of the array is the address of first element in the array". Many beginners (including myself when I was learning) have a tendency to become confused by thinking of it as a pointer. For example, while we can write
ptr = my_array;
we cannot write
my_array = ptr;
The reason is that while ptr is a variable, my_array is a constant. That is, the location at which the first element of my_array will be stored cannot be changed once my_array[] has been declared.
Earlier when discussing the term "lvalue" I cited K&R-2 where it stated:
"An object is a named region of storage; an lvalue is an expression referring to an object".
This raises an interesting problem. Since my_array is a named region of storage, why is my_array in the above assignment statement not an lvalue? To resolve this problem, some refer to my_array as an "unmodifiable lvalue".
Modify the example program above by changing
ptr = &my_array[0];
to
ptr = my_array;
and run it again to verify the results are identical.
Now, let's delve a little further into the difference between the names ptr and my_array as used above. Some writers will refer to an array's name as a constant pointer. What do we mean by that? Well, to understand the term "constant" in this sense, let's go back to our definition of the term "variable". When we declare a variable we set aside a spot in memory to hold the value of the appropriate type. Once that is done the name of the variable can be interpreted in one of two ways. When used on the left side of the assignment operator, the compiler interprets it as the memory location to which to move that value resulting from evaluation of the right side of the assignment operator. But, when used on the right side of the assignment operator, the name of a variable is interpreted to mean the contents stored at that memory address set aside to hold the value of that variable.
With that in mind, let's now consider the simplest of constants, as in:
int i, k;
i = 2;
Here, while i is a variable and then occupies space in the data portion of memory, 2 is a constant and, as such, instead of setting aside memory in the data segment, it is imbedded directly in the code segment of memory. That is, while writing something like k = i; tells the compiler to create code which at run time will look at memory location &i to determine the value to be moved to k, code created by i = 2; simply puts the 2 in the code and there is no referencing of the data segment. That is, both k and i are objects, but 2 is not an object.
Similarly, in the above, since my_array is a constant, once the compiler establishes where the array itself is to be stored, it "knows" the address of my_array[0] and on seeing:
ptr = my_array;
it simply uses this address as a constant in the code segment and there is no referencing of the data segment beyond that.
This might be a good place explain further the use of the (void *) expression used in Program 1.1 of Chapter 1. As we have seen we can have pointers of various types. So far we have discussed pointers to integers and pointers to characters. In coming chapters we will be learning about pointers to structures and even pointer to pointers.
Also we have learned that on different systems the size of a pointer can vary. As it turns out it is also possible that the size of a pointer can vary depending on the data type of the object to which it points. Thus, as with integers where you can run into trouble attempting to assign a long integer to a variable of type short integer, you can run into trouble attempting to assign the values of pointers of various types to pointer variables of other types.
To minimize this problem, C provides for a pointer of type void. We can declare such a pointer by writing:
void *vptr;
A void pointer is sort of a generic pointer. For example, while C will not permit the comparison of a pointer to type integer with a pointer to type character, for example, either of these can be compared to a void pointer. Of course, as with other variables, casts can be used to convert from one type of pointer to another under the proper circumstances. In Program 1.1. of Chapter 1 I cast the pointers to integers into void pointers to make them compatible with the %p conversion specification. In later chapters other casts will be made for reasons defined therein.
Well, that's a lot of technical stuff to digest and I don't expect a beginner to understand all of it on first reading. With time and experimentation you will want to come back and re-read the first 2 chapters. But for now, let's move on to the relationship between pointers, character arrays, and strings.
Continue with Pointer Tutorial
What is a pointer?
CHAPTER 1: What is a pointer?
One of those things beginners in C find difficult is the concept of pointers. The purpose of this tutorial is to provide an introduction to pointers and their use to these beginners.
I have found that often the main reason beginners have a problem with pointers is that they have a weak or minimal feeling for variables, (as they are used in C). Thus we start with a discussion of C variables in general.
A variable in a program is something with a name, the value of which can vary. The way the compiler and linker handles this is that it assigns a specific block of memory within the computer to hold the value of that variable. The size of that block depends on the range over which the variable is allowed to vary. For example, on 32 bit PC's the size of an integer variable is 4 bytes. On older 16 bit PCs integers were 2 bytes. In C the size of a variable type such as an integer need not be the same on all types of machines. Further more there is more than one type of integer variable in C. We have integers, long integers and short integers which you can read up on in any basic text on C. This document assumes the use of a 32 bit system with 4 byte integers.
If you want to know the size of the various types of integers on your system, running the following code will give you that information.
#include
int main()
{
printf("size of a short is %d\n", sizeof(short));
printf("size of a int is %d\n", sizeof(int));
printf("size of a long is %d\n", sizeof(long));
}
When we declare a variable we inform the compiler of two things, the name of the variable and the type of the variable. For example, we declare a variable of type integer with the name k by writing:
int k;
On seeing the "int" part of this statement the compiler sets aside 4 bytes of memory (on a PC) to hold the value of the integer. It also sets up a symbol table. In that table it adds the symbol k and the relative address in memory where those 4 bytes were set aside.
Thus, later if we write:
k = 2;
we expect that, at run time when this statement is executed, the value 2 will be placed in that memory location reserved for the storage of the value of k. In C we refer to a variable such as the integer k as an "object".
In a sense there are two "values" associated with the object k. One is the value of the integer stored there (2 in the above example) and the other the "value" of the memory location, i.e., the address of k. Some texts refer to these two values with the nomenclature rvalue (right value, pronounced "are value") and lvalue (left value, pronounced "el value") respectively.
In some languages, the lvalue is the value permitted on the left side of the assignment operator '=' (i.e. the address where the result of evaluation of the right side ends up). The rvalue is that which is on the right side of the assignment statement, the 2 above. Rvalues cannot be used on the left side of the assignment statement. Thus: 2 = k; is illegal.
Actually, the above definition of "lvalue" is somewhat modified for C. According to K&R II (page 197): [1]
"An object is a named region of storage; an lvalue is an expression referring to an object."
However, at this point, the definition originally cited above is sufficient. As we become more familiar with pointers we will go into more detail on this.
Okay, now consider:
int j, k;
k = 2;
j = 7; <-- line 1
k = j; <-- line 2
In the above, the compiler interprets the j in line 1 as the address of the variable j (its lvalue) and creates code to copy the value 7 to that address. In line 2, however, the j is interpreted as its rvalue (since it is on the right hand side of the assignment operator '='). That is, here the j refers to the value stored at the memory location set aside for j, in this case 7. So, the 7 is copied to the address designated by the lvalue of k.
In all of these examples, we are using 4 byte integers so all copying of rvalues from one storage location to the other is done by copying 4 bytes. Had we been using two byte integers, we would be copying 2 bytes.
Now, let's say that we have a reason for wanting a variable designed to hold an lvalue (an address). The size required to hold such a value depends on the system. On older desk top computers with 64K of memory total, the address of any point in memory can be contained in 2 bytes. Computers with more memory would require more bytes to hold an address. The actual size required is not too important so long as we have a way of informing the compiler that what we want to store is an address.
Such a variable is called a pointer variable (for reasons which hopefully will become clearer a little later). In C when we define a pointer variable we do so by preceding its name with an asterisk. In C we also give our pointer a type which, in this case, refers to the type of data stored at the address we will be storing in our pointer. For example, consider the variable declaration:
int *ptr;
ptr is the name of our variable (just as k was the name of our integer variable). The '*' informs the compiler that we want a pointer variable, i.e. to set aside however many bytes is required to store an address in memory. The int says that we intend to use our pointer variable to store the address of an integer. Such a pointer is said to "point to" an integer. However, note that when we wrote int k; we did not give k a value. If this definition is made outside of any function ANSI compliant compilers will initialize it to zero. Similarly, ptr has no value, that is we haven't stored an address in it in the above declaration. In this case, again if the declaration is outside of any function, it is initialized to a value guaranteed in such a way that it is guaranteed to not point to any C object or function. A pointer initialized in this manner is called a "null" pointer.
The actual bit pattern used for a null pointer may or may not evaluate to zero since it depends on the specific system on which the code is developed. To make the source code compatible between various compilers on various systems, a macro is used to represent a null pointer. That macro goes under the name NULL. Thus, setting the value of a pointer using the NULL macro, as with an assignment statement such as ptr = NULL, guarantees that the pointer has become a null pointer. Similarly, just as one can test for an integer value of zero, as in if(k == 0), we can test for a null pointer using if (ptr == NULL).
But, back to using our new variable ptr. Suppose now that we want to store in ptr the address of our integer variable k. To do this we use the unary & operator and write:
ptr = &k;
What the & operator does is retrieve the lvalue (address) of k, even though k is on the right hand side of the assignment operator '=', and copies that to the contents of our pointer ptr. Now, ptr is said to "point to" k. Bear with us now, there is only one more operator we need to discuss.
The "dereferencing operator" is the asterisk and it is used as follows:
*ptr = 7;
will copy 7 to the address pointed to by ptr. Thus if ptr "points to" (contains the address of) k, the above statement will set the value of k to 7. That is, when we use the '*' this way we are referring to the value of that which ptr is pointing to, not the value of the pointer itself.
Similarly, we could write:
printf("%d\n",*ptr);
to print to the screen the integer value stored at the address pointed to by ptr;.
One way to see how all this stuff fits together would be to run the following program and then review the code and the output carefully.
------------ Program 1.1 ---------------------------------
/* Program 1.1 from PTRTUT10.TXT 6/10/97 */
#include
int j, k;
int *ptr;
int main(void)
{
j = 1;
k = 2;
ptr = &k;
printf("\n");
printf("j has the value %d and is stored at %p\n", j, (void *)&j);
printf("k has the value %d and is stored at %p\n", k, (void *)&k);
printf("ptr has the value %p and is stored at %p\n", ptr, (void *)&ptr);
printf("The value of the integer pointed to by ptr is %d\n", *ptr);
return 0;
}
Note: We have yet to discuss those aspects of C which require the use of the (void *) expression used here. For now, include it in your test code. We'll explain the reason behind this expression later.
--------------------------------------------------------------------------------
To review:
A variable is declared by giving it a type and a name (e.g. int k;)
A pointer variable is declared by giving it a type and a name (e.g. int *ptr) where the asterisk tells the compiler that the variable named ptr is a pointer variable and the type tells the compiler what type the pointer is to point to (integer in this case).
Once a variable is declared, we can get its address by preceding its name with the unary & operator, as in &k.
We can "dereference" a pointer, i.e. refer to the value of that which it points to, by using the unary '*' operator as in *ptr.
An "lvalue" of a variable is the value of its address, i.e. where it is stored in memory. The "rvalue" of a variable is the value stored in that variable (at that address).
One of those things beginners in C find difficult is the concept of pointers. The purpose of this tutorial is to provide an introduction to pointers and their use to these beginners.
I have found that often the main reason beginners have a problem with pointers is that they have a weak or minimal feeling for variables, (as they are used in C). Thus we start with a discussion of C variables in general.
A variable in a program is something with a name, the value of which can vary. The way the compiler and linker handles this is that it assigns a specific block of memory within the computer to hold the value of that variable. The size of that block depends on the range over which the variable is allowed to vary. For example, on 32 bit PC's the size of an integer variable is 4 bytes. On older 16 bit PCs integers were 2 bytes. In C the size of a variable type such as an integer need not be the same on all types of machines. Further more there is more than one type of integer variable in C. We have integers, long integers and short integers which you can read up on in any basic text on C. This document assumes the use of a 32 bit system with 4 byte integers.
If you want to know the size of the various types of integers on your system, running the following code will give you that information.
#include
int main()
{
printf("size of a short is %d\n", sizeof(short));
printf("size of a int is %d\n", sizeof(int));
printf("size of a long is %d\n", sizeof(long));
}
When we declare a variable we inform the compiler of two things, the name of the variable and the type of the variable. For example, we declare a variable of type integer with the name k by writing:
int k;
On seeing the "int" part of this statement the compiler sets aside 4 bytes of memory (on a PC) to hold the value of the integer. It also sets up a symbol table. In that table it adds the symbol k and the relative address in memory where those 4 bytes were set aside.
Thus, later if we write:
k = 2;
we expect that, at run time when this statement is executed, the value 2 will be placed in that memory location reserved for the storage of the value of k. In C we refer to a variable such as the integer k as an "object".
In a sense there are two "values" associated with the object k. One is the value of the integer stored there (2 in the above example) and the other the "value" of the memory location, i.e., the address of k. Some texts refer to these two values with the nomenclature rvalue (right value, pronounced "are value") and lvalue (left value, pronounced "el value") respectively.
In some languages, the lvalue is the value permitted on the left side of the assignment operator '=' (i.e. the address where the result of evaluation of the right side ends up). The rvalue is that which is on the right side of the assignment statement, the 2 above. Rvalues cannot be used on the left side of the assignment statement. Thus: 2 = k; is illegal.
Actually, the above definition of "lvalue" is somewhat modified for C. According to K&R II (page 197): [1]
"An object is a named region of storage; an lvalue is an expression referring to an object."
However, at this point, the definition originally cited above is sufficient. As we become more familiar with pointers we will go into more detail on this.
Okay, now consider:
int j, k;
k = 2;
j = 7; <-- line 1
k = j; <-- line 2
In the above, the compiler interprets the j in line 1 as the address of the variable j (its lvalue) and creates code to copy the value 7 to that address. In line 2, however, the j is interpreted as its rvalue (since it is on the right hand side of the assignment operator '='). That is, here the j refers to the value stored at the memory location set aside for j, in this case 7. So, the 7 is copied to the address designated by the lvalue of k.
In all of these examples, we are using 4 byte integers so all copying of rvalues from one storage location to the other is done by copying 4 bytes. Had we been using two byte integers, we would be copying 2 bytes.
Now, let's say that we have a reason for wanting a variable designed to hold an lvalue (an address). The size required to hold such a value depends on the system. On older desk top computers with 64K of memory total, the address of any point in memory can be contained in 2 bytes. Computers with more memory would require more bytes to hold an address. The actual size required is not too important so long as we have a way of informing the compiler that what we want to store is an address.
Such a variable is called a pointer variable (for reasons which hopefully will become clearer a little later). In C when we define a pointer variable we do so by preceding its name with an asterisk. In C we also give our pointer a type which, in this case, refers to the type of data stored at the address we will be storing in our pointer. For example, consider the variable declaration:
int *ptr;
ptr is the name of our variable (just as k was the name of our integer variable). The '*' informs the compiler that we want a pointer variable, i.e. to set aside however many bytes is required to store an address in memory. The int says that we intend to use our pointer variable to store the address of an integer. Such a pointer is said to "point to" an integer. However, note that when we wrote int k; we did not give k a value. If this definition is made outside of any function ANSI compliant compilers will initialize it to zero. Similarly, ptr has no value, that is we haven't stored an address in it in the above declaration. In this case, again if the declaration is outside of any function, it is initialized to a value guaranteed in such a way that it is guaranteed to not point to any C object or function. A pointer initialized in this manner is called a "null" pointer.
The actual bit pattern used for a null pointer may or may not evaluate to zero since it depends on the specific system on which the code is developed. To make the source code compatible between various compilers on various systems, a macro is used to represent a null pointer. That macro goes under the name NULL. Thus, setting the value of a pointer using the NULL macro, as with an assignment statement such as ptr = NULL, guarantees that the pointer has become a null pointer. Similarly, just as one can test for an integer value of zero, as in if(k == 0), we can test for a null pointer using if (ptr == NULL).
But, back to using our new variable ptr. Suppose now that we want to store in ptr the address of our integer variable k. To do this we use the unary & operator and write:
ptr = &k;
What the & operator does is retrieve the lvalue (address) of k, even though k is on the right hand side of the assignment operator '=', and copies that to the contents of our pointer ptr. Now, ptr is said to "point to" k. Bear with us now, there is only one more operator we need to discuss.
The "dereferencing operator" is the asterisk and it is used as follows:
*ptr = 7;
will copy 7 to the address pointed to by ptr. Thus if ptr "points to" (contains the address of) k, the above statement will set the value of k to 7. That is, when we use the '*' this way we are referring to the value of that which ptr is pointing to, not the value of the pointer itself.
Similarly, we could write:
printf("%d\n",*ptr);
to print to the screen the integer value stored at the address pointed to by ptr;.
One way to see how all this stuff fits together would be to run the following program and then review the code and the output carefully.
------------ Program 1.1 ---------------------------------
/* Program 1.1 from PTRTUT10.TXT 6/10/97 */
#include
int j, k;
int *ptr;
int main(void)
{
j = 1;
k = 2;
ptr = &k;
printf("\n");
printf("j has the value %d and is stored at %p\n", j, (void *)&j);
printf("k has the value %d and is stored at %p\n", k, (void *)&k);
printf("ptr has the value %p and is stored at %p\n", ptr, (void *)&ptr);
printf("The value of the integer pointed to by ptr is %d\n", *ptr);
return 0;
}
Note: We have yet to discuss those aspects of C which require the use of the (void *) expression used here. For now, include it in your test code. We'll explain the reason behind this expression later.
--------------------------------------------------------------------------------
To review:
A variable is declared by giving it a type and a name (e.g. int k;)
A pointer variable is declared by giving it a type and a name (e.g. int *ptr) where the asterisk tells the compiler that the variable named ptr is a pointer variable and the type tells the compiler what type the pointer is to point to (integer in this case).
Once a variable is declared, we can get its address by preceding its name with the unary & operator, as in &k.
We can "dereference" a pointer, i.e. refer to the value of that which it points to, by using the unary '*' operator as in *ptr.
An "lvalue" of a variable is the value of its address, i.e. where it is stored in memory. The "rvalue" of a variable is the value stored in that variable (at that address).
c arrays
A TUTORIAL ON POINTERS AND ARRAYS IN C
by Ted Jensen
Version 1.2 (HTML version)
Feb. 2000
This material is hereby placed in the public domain
Available in various formats via
http://pweb.netcom.com/~tjensen/ptr/cpoint.htm
PDF Version now available!
TABLE OF CONTENTS
Preface
Introduction
Chapter 1: What is a Pointer?
Chapter 2: Pointer Types and Arrays.
Chapter 3: Pointers and Strings
Chapter 4: More on Strings
Chapter 5: Pointers and Structures
Chapter 6: More on Strings and Arrays of Strings
Chapter 7: More on Multi-Dimensional Arrays
Chapter 8: Pointers to Arrays
Chapter 9: Pointers and Dynamic Allocation of Memory
Chapter 10: Pointers to Functions
Epilog
by Ted Jensen
Version 1.2 (HTML version)
Feb. 2000
This material is hereby placed in the public domain
Available in various formats via
http://pweb.netcom.com/~tjensen/ptr/cpoint.htm
PDF Version now available!
TABLE OF CONTENTS
Preface
Introduction
Chapter 1: What is a Pointer?
Chapter 2: Pointer Types and Arrays.
Chapter 3: Pointers and Strings
Chapter 4: More on Strings
Chapter 5: Pointers and Structures
Chapter 6: More on Strings and Arrays of Strings
Chapter 7: More on Multi-Dimensional Arrays
Chapter 8: Pointers to Arrays
Chapter 9: Pointers and Dynamic Allocation of Memory
Chapter 10: Pointers to Functions
Epilog
about c Statements
Statements
C has three types of statement.
assignment
=
selection (branching)
if (expression)
else
switch
iteration (looping)
while (expression)
for (expression;expression;expression)
do {block}
Blocks
These statements are grouped into blocks, a block is identified by curly brackets...There are two types of block.
statement blocks
if ( i == j)
{
printf("martin \n");
}
The statement block containing the printf is only executed if the i == j expression evaluates to TRUE.
function blocks
int add( int a, int b) /* Function definition */
{
int c;
c = a + b;
return c;
}
C has three types of statement.
assignment
=
selection (branching)
if (expression)
else
switch
iteration (looping)
while (expression)
for (expression;expression;expression)
do {block}
Blocks
These statements are grouped into blocks, a block is identified by curly brackets...There are two types of block.
statement blocks
if ( i == j)
{
printf("martin \n");
}
The statement block containing the printf is only executed if the i == j expression evaluates to TRUE.
function blocks
int add( int a, int b) /* Function definition */
{
int c;
c = a + b;
return c;
}
about c key wordes
C keywords.
--------------------------------------------------------------------------------
The following list shows all the ANSII defined C keywords. I have included sizeof because it looks like a keyword and it keeps the table below tidy....
auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
--------------------------------------------------------------------------------
C
--------------------------------------------------------------------------------
The following list shows all the ANSII defined C keywords. I have included sizeof because it looks like a keyword and it keeps the table below tidy....
auto break case char const continue default do
double else enum extern float for goto if
int long register return short signed sizeof static
struct switch typedef union unsigned void volatile while
--------------------------------------------------------------------------------
C
c tokens
Compilation of C Programs
C programs can be compiled by C compilers and most C++ compilers. Most UNIX operating systems usually come with the following compilers: cc - compiler for the C language
CC - compiler for the C++ language
In addition, two compilers written by the GNU free software foundation are often installed: gcc - compiler for the C language
g++ - compiler for the C++ language
Further information is available in the UNIX reference page.
Variables
A variable is a named or unnamed place for storing mutable data. Named variables are declared either globally (outside of functions) or local to a function. A named variable is given a type as part of its declaration. For simple types a variable declaration has the following form:
type variable-name;
where
type is the name of a type, either a built-in type such as int or char, or a programmer defined type, and
variable-name is an identifier that names the variable.
For example,
int x;
declares x to be an int (integer) variable. Definitions of variables with more complex types are constructed and interpreted according to C precedence rules.
Unnamed variables can be created at execution time using dynamic memory allocation. Unnamed variables can only be accessed through pointers.
Functions
A function is a named complex syntactic construction. It is defined once, but may be called upon many times to return values and/or perform actions. The actions performed by a function can include modifying variables, processing input, and generating output. Functions can have parameters. Parameters are values that are passed when a function is called. A function definition has the following form:
value-type function-name(parameter-list) {
local-variable-declarations
statements
}
where
value-type is the name of the type of value that the function returns.
function-name is an identifier that names the function.
parameter-list is a sequence of variable declarations, with semicolons omitted, but separated by commas. These declarations give names and types to the parameters that may be used as initialized variables in the statements. They are initialized by the values passed when the function is called.
local-variable-declarations is sequence of declarations for variables that may be used in the statements.
statements is a sequence of statements that perform the desired action and return the desired value.
A function can be defined so that it does not return any value. This is done by replacing value-type with the keyword void. A function can also be defined with no parameters. Then parameter-list should be the keyword void.
For example, the following is a definition of a function named Sum with three integer parameters that returns their sum:
int Sum(int a, int b, int c) {
return a + b + c;
}
Calling Functions
A function call consists of the function name followed by a parenthesized list of expressions that are separated by commas. The number of expressions must match the number of parameters in the definition of the function. The values of these expresions are called the arguments of the function call. The value types of the arguments must match, in order, the parameter types in the function definition. For the function Sum defined above, the argument list for a call must have three integer expressions. For example, the following is a legal call to the function Sum:
Sum(3, 27*11, 2 + 2)
A function call can appear anywhere that a value of its return type can appear. The above call could appear in a complex expression as long as an integer value is appropriate where it appears. For example, the following is a legitimate expression using the function Sum:
Sum(Sum(1, 2, 3), Sum(4, 5, 6), Sum(7, 8, 9))
The value of a function call is determined as follows. First, the argument expressions are evaluated and are used to initialize the parameters. For the first example call above, a is initialized as 3, b as 297, and c as 4. Then the statements in the function body are executed in order. A return statement completes the execution of statements and determines the returned value. The only statement in Sum just returns a + b + c, which is 304.
For the second example call above, another important fact comes into play: each call to a function uses its own variables, which are independent of the variables in other calls to the same function. This means that if a function does not refer to any variables except parameters and local variables then you can understand what its action and returned value are once you know the value of its parameters. The Sum function just returns the sum of its arguments, so the returned value for the second example is ((1 + 2 + 3) + (4 + 5 + 6) + (7 + 8 + 9)), or 45.
Statements
A statement is a syntactic constructions that perform actions. It can alter the value of variables, generate output, or process input. The simplest kind of statement is an expression statement, which is no more than an expression followed by a semicolon. The most common uses of expression statements are function call statements, where the expression is just a function call, and assignment statements, where the expression is an assignment expression. The most commonly used assignment expression has the form
variable = expression
so the assignment statement has the form
variable = expression;
This statement changes the value of the variable on the left side of the equals sign to the value of the expression on the right side.
C is unusual in treating an assignment as both an expression and as a statement. This is done to allow multiple assignments in a single statement, such as
a = b = 5;
By treating b = 5 as an expression with value 5, C makes sense of this statement, assigning the value 5 to both a and b.
C also has structured statements loops and conditional execution of statements. while - pretest loops
for - pretest loops
do-while - posttest loops
if-else - conditional execution
switch - conditionally selecting among several statements
return - return values from and terminate functions
continue - skip remaining statements in a loop
break - exit a loop or switch
While Loops
The while statement is a looping construction which has the following form:
while (condition) {
statements
}
where
condition is an expression that can be true (nonzero) or false (zero). This expression is tested prior to each iteration of the loop. The loop terminates when it is false.
statements is a sequence of statements. If there is only one statement then the braces can be omitted.
For Loops
The for statement is a looping construction which has the following form:
for (initialization; condition; increment) {
statements
}
where
initialization is a statement that is executed once at the beginning of the for loop.
condition is an expression that can be true (nonzero) or false (zero). This expression is tested prior to each iteration of the loop. The loop terminates when it is false.
increment is a statement that is executed after statements.
statements is a sequence of statements. If there is only one statement then the braces may be omitted.
Do-While Loops
The do-while statement is a looping construction which has the following form:
do {
statements
} while (condition);
where
statements is a sequence of statements. If there is only one statement then the braces may be omitted.
condition is an expression that can be true (nonzero) or false (zero). This expression is tested after each iteration of the loop. The loop terminates when it is false.
If-Else Statements
The if statement has one of two forms:
if (condition) {
true-statements
}
or
if (condition) {
true-statements
} else {
false-statements
}
where
condition is an expression that can be true (nonzero) or false (zero).
true-statements and false-statements are sequences of statements. If there is only one statement in a sequence then the surrounding braces may be omitted. For both forms, the true-statements are executed only if condition is true. For the second form the false-statements are executed if condition is false.
Switch Statements
The switch statement allows execution of different statements depending on the value of an expression. It has the following form:
switch (expression) {
case constant-expression-1:
statements-1
.
.
.
case constant-expression-n:
statements-n
default:
default-statements
}
where
expression is an expression of a simple type, such as int, char, or an enum type. It cannot have float or double type.
constant-expression-1 through constant-expression-n are expressions of a type that converts to the type of expression. The compiler must be able to evaluate these expressions to constant values.
statements-1 through statements-n are sequences of statements.
When the switch statement is executed, expression is evaluated. The resulting value is compared to the values of constant-expression-1 through constant-expression-n in order until a matching value is found. If a match is found in constant-expression-i then statements-i through statements-n and default-statements are executed, with switch statement execution terminated if a break statement is encountered. Normally, the last statement in each sequence is a break statement so that only one sequence is executed.
The default clause is optional. If it is present then the default-statements are executed whenever the value of expression does not match any of the constant-expression-i values.
Return Statements
The return statement is used in the definition of a function to set its returned value and to terminate execution of the function. It has two forms. For functions with returned type void use
return;
For functions with non-void returned type use
return expression;
where expression is an expression that yields the desired return value.
Continue Statements
The continue statement is used in loop (for, while, and do-while) statements to terminate an iteration of the loop. After a continue statement is executed in a for loop, execution proceeds to the increment clause and continuation test of the loop. After a continue statement is executed in a while or do-while loop, execution proceeds to the continuation test of the loop. A continue statement is formed with the keyword continue followed by a semicolon.
Break Statements
The break statement is used in loop (for, while, and do-while) statements and switch statements to terminate execution of the statement. After a break statement is executed, execution proceeds to the statement that follows the enclosing loop or switch statement. A break statement is formed with the keyword break followed by a semicolon.
Data Types
All C variables are defined with a specific type. C has the following built-in types: char - characters
int - integers (whole numbers)
float - real numbers
double - higher precision real numbers
In addition, C provides structured types: array - groups of variables of identical types, accessed using integer indices
structs - groups of variables of mixed types, accessed by using named field selectors
unions - variables that can contain values of different types, depending on a field selector
enumerated types - variables that can take on a small number of different named values
New C types can be defined with a typedef construction. This constructuction is identical to a variable declaration except that it is preceeded by the keyword typedef. The name of the new type appears where the variable name would appear in a variable declaration.
For example, the following declaration declares str to be an array of 10 characters.
char str[10];
On the other hand the following declaration declares String to be the name of a new type for arrays containing 10 characters.
typedef char String[10];
Once a type name has been defined with typedef, it can be used to declare variables. For example, after the above typedef, the following declaration declares str to be an array of 10 characters.
String str;
Scoping Rules
FIXME. Scoping rules are used to determine what an identifier refers to in a context.
Comments
Any text that begins with /* and continues up to the first following */, is ignored by C compilers. This can be used to add comments describing function behavior, variable usage, and algorithms. C comments cannot be nested.
Constants
A constant is a named or unnamed non-mutable program value. Named constants are defined by preceding an initialized variable definition with the keyword const. For example, the following defines a double-precision real constant named pi with its usual mathematical value:
const double pi = 3.141592653589793;
Older versions of C compilers did not use a const keyword. These compilers, and modern compilers as well, use the C preprocessor to define named constants. The above definition would be replaced by
#define pi 3.141592653589793
The preprocessor reads this definition as a command to replace the identifier pi by the literal constant wherever it appears in the program. So the compiler never sees the identifier pi - it just sees the literal constant.
There is a problem with using #define: syntax is not checked at the #define; it is only checked where the substitution is made. If there is something wrong with the #define (for example, adding a semicolon at the end), you can get error messages that are difficult to interpret.
Unnamed constants are often called literals. They are usually constructed similar to English or mathematical values, such as the literal constant 3.141592653589793 in the above definitions.
Conversions Between Types
FIXME.
Definitions and Declarations
A definition gives precise meaning to a program identifier. A declaration describes properties of a program identifier, usually so that the compiler can perform type checks. An identifier can only be defined once, but it may be declared more than once.
The difference between definitions and declarations is most significant for functions. The following is a definition of a function named Sum. This function has three integer parameters and it returns their sum.
int Sum(int a, int b, int c) {
return a + b + c;
}
To form a declaration for Sum, you omit the portion in braces, replacing the braces by a semicolon:
int Sum(int a, int b, int c);
Another situation where declarations and definitions are different is in definitions and delarations of array variables. The definition of an array variable must specify the number of entries, as in
char str[81];
This defines an array variable named str that has enough room for 80 characters plus a terminating null character.
In a definition or declaration of a function, you only need to provide a declaration for parameters. For array parameters, this means that you can omit the size specification as in
void CopyString(char dest[], char src[]) {
int i;
i = 0;
do {
dest[i] = src[i];
} while (src[i++] != '\0') {
}
Expressions
An expression is a syntactic construction that has a value. Expressions are formed by combining constant, variable, and function call values using operators. Some C expressions can have side-effects, which are actions that are executed when the expression is evaluated.
Including Declarations from Other Files
FIXME.
The main Function
Every C program must have a function named main. This function is called by the operating system when the program is executed. For a short program, all of the statements to be executed can be put into main. For larger programs, numerous functions are written that are directly or indirectly called by main.
For programs that do not use command-line arguments the header for main should be
int main(void)
For programs that use command-line arguments the header for the main function should be
int main(int argc, char *argv[])
Then argc is the number of words in the command line and argv is an array of strings, one for each word.
The value returned by main function is normally 0. Some programs return a non-zero value to indicate an abnormal condition. For example, C compilers return non-zero values when they attempt to compile a program that contains syntax errors.
Dynamic Allocation for C Variables
The C standard library (stdlib.h) provides three functions for dynamically allocating variables: malloc, calloc, and realloc. All of these functions return pointers to new variables or arrays of variables, unless the system runs out of memory. In that case they return NULL. It is a good habit to check the returned value. If it is NULL then your program should just print an error message and exit.
malloc is used for allocating non-array variables. It has a single argument that specifies the size of the variable. This is usually obtained by calling sizeof(type), where type is the type of the desired variable. calloc is used for allocating array variables. It has two arguments: the number of array elements and the size of an individual element. realloc is usually used for changing the number of entries for dynamically allocated array variables. It has two arguments: a pointer to the array to be reallocated and the total size of the resized array. The total size can be computed as the product of the number of elements times the size of an individual element. realloc copies all of the data from the old array into the new array.
Some compilers will give warnings when you assign the returned value from any of the memory allocation functions to a variable, because they return pointers of a generic type (void *). To quiet these warnings you can coerce the type by preceding the function call by the pointer or array type name enclosed in parentheses.
For example, suppose a stack type is declared as
/* A Stack is a struct that contains a body, its current capacity, and */
/* its current entry count. */
/* */
typedef struct Stack {
Data *body; /* the stack array */
int capacity; /* maximum number of entries in stack */
int count; /* index of top entry in stack */
} Stack;
and that st is a variable of type Stack. Then to create st with an initial capacity of 20 entries you would use the code
st.capacity = 20;
st.body = (Data *)calloc(st.capacity, sizeof(Data));
if (st.body == NULL) {
fprintf(stderr, "Memory allocation failed for stack body.");
exit(1);
}
To double the capacity of the stack you would use the code
st.capacity *= 2;
st.body = (Data *)realloc(st.body, st.capacity*sizeof(Data));
if (st.body == NULL) {
fprintf(stderr, "Memory reallocation failed for stack body.");
exit(1);
}
The C standard library also provides a function free for freeing up dynamically allocated memory. It has a single void * parameter, which should be a pointer from an earlier call to malloc, calloc, or realloc. Care must be taken to only use free once on a chunk of dynamically allocated memory.
Tokens of the C Language
A token is a sequence of characters that is understood as a unit. Tokens are the basic building blocks of a C program. C tokens fall roughly into the six categories listed below. grouping - tokens pairs that group things together
identifiers - tokens that name functions, variables, constants, and types
literals - tokens that specify values
operators - tokens that are used to combine values in expressions
punctuation - tokens that separate or terminate complex constructions
special - tokens with special meaning to the preprocessor or compiler
Grouping Operators
FIXME. grouping - tokens pairs that group things together
Identifiers
An identifier is a consecutive string of letters, digits, and underscore characters, the first of which is a letter or an underscore. Identifiers are tokens of the C language. They are used to name variables, constants, types, functions, and and members of structs and unions. Certain identifiers have predefined meanings and cannot be redefined. These identifiers, called keywords, are listed below. auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Literal Constants
A literal is a token that specifies a value. The syntax of a literal depends on the type of value: integer, real, character, or string.
An integer literal can be written in decimal, octal, or hexadecimal form. A decimal (base 10) literal is any string of digits that does not begin with the digit '0'. This is the most common form for integer literals. An octal (base 8) literal is a string of digits, excluding '8' and '9'. A hexadecimal (base 16) literal begins with the characters '0x' or the characters '0X'. The remaining characters are hexadecimal digits, which include decimal digits and the letters 'a' through 'f' and 'A' through 'F'.
A real literal is written as decimal integer, followed by a decimal point, followed by a fractional part, which is a string of decimal digits. It may optionally be followed by an exponent, which consists of either the letter 'e' or the letter 'E' followed by a decimal integer. This integer is called the exponent. It specifies a power of ten that multiplies the preceding number, as in scientific notation. For example, 1.5e3 represents the number 1.5*1000, or 1500.0. The exponent may be signed.
A string literal is a sequence of characters other than quote marks, or escape sequences, enclosed in double quotes. A character literal is a character other than a quote mark, or an escape sequence, enclosed in single quotes. For both string and character literals, the following escape sequences are used: \n - a newline character
\t - a tab character
\' - a single quote character
\" - a double quote character
\\ - a backslash character
\0 - a null character (string terminator)
A null character is automatically appended to the end of all string literals.
Operators, Precedence, and Associativity
Operators are tokens that are used to combine values in expressions. When evaluating an expression, C uses precedence and associativity rules to determine the order in which operators are applied. In the table below, the C operators are listed in order of precedence with highest precedence at the top. The rows of the table define precedence groups. Two operators in the same group have the same precedence.
Associativity rules are only used to determine the order of evaluation for two operators that are in the same group. Most groups use left to right associativity, which means that in an expression with operators in the same precedence group, the operators are applied in left-to-right order. The order is reversed for right to left associativity. operator group associativity links
() [] -> . left to right selectors
! ~ ++ -- + - (type) * & sizeof right to left unary
* / % left to right multiplicative
+ - left to right additive
<< >> left to right bitwise
< <= > >= left to right comparison
== != left to right comparison
& left to right bitwise
^ left to right bitwise
| left to right bitwise
&& left to right boolean
|| left to right boolean
?: right to left conditional
= += -= *= /= %= &= ^= |= <<= >>= right to left assignment
, left to right comma
Punctuation Tokens
FIXME. punctuation - tokens that separate complex constructions into parts
Special Tokens
FIXME. special - tokens with special meaning to the preprocessor or compiler
Arguments in Function Calls
FIXME.
Selector Operators
FIXME.
Unary Operators
FIXME.
Multiplicative Operators
FIXME.
Additive Operators
FIXME.
Boolean Operators
FIXME.
Bitwise Operators
FIXME.
Equality and Comparison Operators
FIXME.
Conditional Expressions
The conditional expression has one of two values, depending on a boolean condition. It has the following form:
condition ? expression-1 : expression-2
where
condition is an expression that can be true (nonzero) or false (zero).
expression-1 and expression-2 are expressions that convert to a common type.
If condition is true then expression-1 is evaluated and its value becomes the value of the conditional expression. Otherwise, expression-2 is evaluated and its value becomes the value of the conditional expression.
Assignment Operators
FIXME.
The Comma Operator
FIXME.
C programs can be compiled by C compilers and most C++ compilers. Most UNIX operating systems usually come with the following compilers: cc - compiler for the C language
CC - compiler for the C++ language
In addition, two compilers written by the GNU free software foundation are often installed: gcc - compiler for the C language
g++ - compiler for the C++ language
Further information is available in the UNIX reference page.
Variables
A variable is a named or unnamed place for storing mutable data. Named variables are declared either globally (outside of functions) or local to a function. A named variable is given a type as part of its declaration. For simple types a variable declaration has the following form:
type variable-name;
where
type is the name of a type, either a built-in type such as int or char, or a programmer defined type, and
variable-name is an identifier that names the variable.
For example,
int x;
declares x to be an int (integer) variable. Definitions of variables with more complex types are constructed and interpreted according to C precedence rules.
Unnamed variables can be created at execution time using dynamic memory allocation. Unnamed variables can only be accessed through pointers.
Functions
A function is a named complex syntactic construction. It is defined once, but may be called upon many times to return values and/or perform actions. The actions performed by a function can include modifying variables, processing input, and generating output. Functions can have parameters. Parameters are values that are passed when a function is called. A function definition has the following form:
value-type function-name(parameter-list) {
local-variable-declarations
statements
}
where
value-type is the name of the type of value that the function returns.
function-name is an identifier that names the function.
parameter-list is a sequence of variable declarations, with semicolons omitted, but separated by commas. These declarations give names and types to the parameters that may be used as initialized variables in the statements. They are initialized by the values passed when the function is called.
local-variable-declarations is sequence of declarations for variables that may be used in the statements.
statements is a sequence of statements that perform the desired action and return the desired value.
A function can be defined so that it does not return any value. This is done by replacing value-type with the keyword void. A function can also be defined with no parameters. Then parameter-list should be the keyword void.
For example, the following is a definition of a function named Sum with three integer parameters that returns their sum:
int Sum(int a, int b, int c) {
return a + b + c;
}
Calling Functions
A function call consists of the function name followed by a parenthesized list of expressions that are separated by commas. The number of expressions must match the number of parameters in the definition of the function. The values of these expresions are called the arguments of the function call. The value types of the arguments must match, in order, the parameter types in the function definition. For the function Sum defined above, the argument list for a call must have three integer expressions. For example, the following is a legal call to the function Sum:
Sum(3, 27*11, 2 + 2)
A function call can appear anywhere that a value of its return type can appear. The above call could appear in a complex expression as long as an integer value is appropriate where it appears. For example, the following is a legitimate expression using the function Sum:
Sum(Sum(1, 2, 3), Sum(4, 5, 6), Sum(7, 8, 9))
The value of a function call is determined as follows. First, the argument expressions are evaluated and are used to initialize the parameters. For the first example call above, a is initialized as 3, b as 297, and c as 4. Then the statements in the function body are executed in order. A return statement completes the execution of statements and determines the returned value. The only statement in Sum just returns a + b + c, which is 304.
For the second example call above, another important fact comes into play: each call to a function uses its own variables, which are independent of the variables in other calls to the same function. This means that if a function does not refer to any variables except parameters and local variables then you can understand what its action and returned value are once you know the value of its parameters. The Sum function just returns the sum of its arguments, so the returned value for the second example is ((1 + 2 + 3) + (4 + 5 + 6) + (7 + 8 + 9)), or 45.
Statements
A statement is a syntactic constructions that perform actions. It can alter the value of variables, generate output, or process input. The simplest kind of statement is an expression statement, which is no more than an expression followed by a semicolon. The most common uses of expression statements are function call statements, where the expression is just a function call, and assignment statements, where the expression is an assignment expression. The most commonly used assignment expression has the form
variable = expression
so the assignment statement has the form
variable = expression;
This statement changes the value of the variable on the left side of the equals sign to the value of the expression on the right side.
C is unusual in treating an assignment as both an expression and as a statement. This is done to allow multiple assignments in a single statement, such as
a = b = 5;
By treating b = 5 as an expression with value 5, C makes sense of this statement, assigning the value 5 to both a and b.
C also has structured statements loops and conditional execution of statements. while - pretest loops
for - pretest loops
do-while - posttest loops
if-else - conditional execution
switch - conditionally selecting among several statements
return - return values from and terminate functions
continue - skip remaining statements in a loop
break - exit a loop or switch
While Loops
The while statement is a looping construction which has the following form:
while (condition) {
statements
}
where
condition is an expression that can be true (nonzero) or false (zero). This expression is tested prior to each iteration of the loop. The loop terminates when it is false.
statements is a sequence of statements. If there is only one statement then the braces can be omitted.
For Loops
The for statement is a looping construction which has the following form:
for (initialization; condition; increment) {
statements
}
where
initialization is a statement that is executed once at the beginning of the for loop.
condition is an expression that can be true (nonzero) or false (zero). This expression is tested prior to each iteration of the loop. The loop terminates when it is false.
increment is a statement that is executed after statements.
statements is a sequence of statements. If there is only one statement then the braces may be omitted.
Do-While Loops
The do-while statement is a looping construction which has the following form:
do {
statements
} while (condition);
where
statements is a sequence of statements. If there is only one statement then the braces may be omitted.
condition is an expression that can be true (nonzero) or false (zero). This expression is tested after each iteration of the loop. The loop terminates when it is false.
If-Else Statements
The if statement has one of two forms:
if (condition) {
true-statements
}
or
if (condition) {
true-statements
} else {
false-statements
}
where
condition is an expression that can be true (nonzero) or false (zero).
true-statements and false-statements are sequences of statements. If there is only one statement in a sequence then the surrounding braces may be omitted. For both forms, the true-statements are executed only if condition is true. For the second form the false-statements are executed if condition is false.
Switch Statements
The switch statement allows execution of different statements depending on the value of an expression. It has the following form:
switch (expression) {
case constant-expression-1:
statements-1
.
.
.
case constant-expression-n:
statements-n
default:
default-statements
}
where
expression is an expression of a simple type, such as int, char, or an enum type. It cannot have float or double type.
constant-expression-1 through constant-expression-n are expressions of a type that converts to the type of expression. The compiler must be able to evaluate these expressions to constant values.
statements-1 through statements-n are sequences of statements.
When the switch statement is executed, expression is evaluated. The resulting value is compared to the values of constant-expression-1 through constant-expression-n in order until a matching value is found. If a match is found in constant-expression-i then statements-i through statements-n and default-statements are executed, with switch statement execution terminated if a break statement is encountered. Normally, the last statement in each sequence is a break statement so that only one sequence is executed.
The default clause is optional. If it is present then the default-statements are executed whenever the value of expression does not match any of the constant-expression-i values.
Return Statements
The return statement is used in the definition of a function to set its returned value and to terminate execution of the function. It has two forms. For functions with returned type void use
return;
For functions with non-void returned type use
return expression;
where expression is an expression that yields the desired return value.
Continue Statements
The continue statement is used in loop (for, while, and do-while) statements to terminate an iteration of the loop. After a continue statement is executed in a for loop, execution proceeds to the increment clause and continuation test of the loop. After a continue statement is executed in a while or do-while loop, execution proceeds to the continuation test of the loop. A continue statement is formed with the keyword continue followed by a semicolon.
Break Statements
The break statement is used in loop (for, while, and do-while) statements and switch statements to terminate execution of the statement. After a break statement is executed, execution proceeds to the statement that follows the enclosing loop or switch statement. A break statement is formed with the keyword break followed by a semicolon.
Data Types
All C variables are defined with a specific type. C has the following built-in types: char - characters
int - integers (whole numbers)
float - real numbers
double - higher precision real numbers
In addition, C provides structured types: array - groups of variables of identical types, accessed using integer indices
structs - groups of variables of mixed types, accessed by using named field selectors
unions - variables that can contain values of different types, depending on a field selector
enumerated types - variables that can take on a small number of different named values
New C types can be defined with a typedef construction. This constructuction is identical to a variable declaration except that it is preceeded by the keyword typedef. The name of the new type appears where the variable name would appear in a variable declaration.
For example, the following declaration declares str to be an array of 10 characters.
char str[10];
On the other hand the following declaration declares String to be the name of a new type for arrays containing 10 characters.
typedef char String[10];
Once a type name has been defined with typedef, it can be used to declare variables. For example, after the above typedef, the following declaration declares str to be an array of 10 characters.
String str;
Scoping Rules
FIXME. Scoping rules are used to determine what an identifier refers to in a context.
Comments
Any text that begins with /* and continues up to the first following */, is ignored by C compilers. This can be used to add comments describing function behavior, variable usage, and algorithms. C comments cannot be nested.
Constants
A constant is a named or unnamed non-mutable program value. Named constants are defined by preceding an initialized variable definition with the keyword const. For example, the following defines a double-precision real constant named pi with its usual mathematical value:
const double pi = 3.141592653589793;
Older versions of C compilers did not use a const keyword. These compilers, and modern compilers as well, use the C preprocessor to define named constants. The above definition would be replaced by
#define pi 3.141592653589793
The preprocessor reads this definition as a command to replace the identifier pi by the literal constant wherever it appears in the program. So the compiler never sees the identifier pi - it just sees the literal constant.
There is a problem with using #define: syntax is not checked at the #define; it is only checked where the substitution is made. If there is something wrong with the #define (for example, adding a semicolon at the end), you can get error messages that are difficult to interpret.
Unnamed constants are often called literals. They are usually constructed similar to English or mathematical values, such as the literal constant 3.141592653589793 in the above definitions.
Conversions Between Types
FIXME.
Definitions and Declarations
A definition gives precise meaning to a program identifier. A declaration describes properties of a program identifier, usually so that the compiler can perform type checks. An identifier can only be defined once, but it may be declared more than once.
The difference between definitions and declarations is most significant for functions. The following is a definition of a function named Sum. This function has three integer parameters and it returns their sum.
int Sum(int a, int b, int c) {
return a + b + c;
}
To form a declaration for Sum, you omit the portion in braces, replacing the braces by a semicolon:
int Sum(int a, int b, int c);
Another situation where declarations and definitions are different is in definitions and delarations of array variables. The definition of an array variable must specify the number of entries, as in
char str[81];
This defines an array variable named str that has enough room for 80 characters plus a terminating null character.
In a definition or declaration of a function, you only need to provide a declaration for parameters. For array parameters, this means that you can omit the size specification as in
void CopyString(char dest[], char src[]) {
int i;
i = 0;
do {
dest[i] = src[i];
} while (src[i++] != '\0') {
}
Expressions
An expression is a syntactic construction that has a value. Expressions are formed by combining constant, variable, and function call values using operators. Some C expressions can have side-effects, which are actions that are executed when the expression is evaluated.
Including Declarations from Other Files
FIXME.
The main Function
Every C program must have a function named main. This function is called by the operating system when the program is executed. For a short program, all of the statements to be executed can be put into main. For larger programs, numerous functions are written that are directly or indirectly called by main.
For programs that do not use command-line arguments the header for main should be
int main(void)
For programs that use command-line arguments the header for the main function should be
int main(int argc, char *argv[])
Then argc is the number of words in the command line and argv is an array of strings, one for each word.
The value returned by main function is normally 0. Some programs return a non-zero value to indicate an abnormal condition. For example, C compilers return non-zero values when they attempt to compile a program that contains syntax errors.
Dynamic Allocation for C Variables
The C standard library (stdlib.h) provides three functions for dynamically allocating variables: malloc, calloc, and realloc. All of these functions return pointers to new variables or arrays of variables, unless the system runs out of memory. In that case they return NULL. It is a good habit to check the returned value. If it is NULL then your program should just print an error message and exit.
malloc is used for allocating non-array variables. It has a single argument that specifies the size of the variable. This is usually obtained by calling sizeof(type), where type is the type of the desired variable. calloc is used for allocating array variables. It has two arguments: the number of array elements and the size of an individual element. realloc is usually used for changing the number of entries for dynamically allocated array variables. It has two arguments: a pointer to the array to be reallocated and the total size of the resized array. The total size can be computed as the product of the number of elements times the size of an individual element. realloc copies all of the data from the old array into the new array.
Some compilers will give warnings when you assign the returned value from any of the memory allocation functions to a variable, because they return pointers of a generic type (void *). To quiet these warnings you can coerce the type by preceding the function call by the pointer or array type name enclosed in parentheses.
For example, suppose a stack type is declared as
/* A Stack is a struct that contains a body, its current capacity, and */
/* its current entry count. */
/* */
typedef struct Stack {
Data *body; /* the stack array */
int capacity; /* maximum number of entries in stack */
int count; /* index of top entry in stack */
} Stack;
and that st is a variable of type Stack. Then to create st with an initial capacity of 20 entries you would use the code
st.capacity = 20;
st.body = (Data *)calloc(st.capacity, sizeof(Data));
if (st.body == NULL) {
fprintf(stderr, "Memory allocation failed for stack body.");
exit(1);
}
To double the capacity of the stack you would use the code
st.capacity *= 2;
st.body = (Data *)realloc(st.body, st.capacity*sizeof(Data));
if (st.body == NULL) {
fprintf(stderr, "Memory reallocation failed for stack body.");
exit(1);
}
The C standard library also provides a function free for freeing up dynamically allocated memory. It has a single void * parameter, which should be a pointer from an earlier call to malloc, calloc, or realloc. Care must be taken to only use free once on a chunk of dynamically allocated memory.
Tokens of the C Language
A token is a sequence of characters that is understood as a unit. Tokens are the basic building blocks of a C program. C tokens fall roughly into the six categories listed below. grouping - tokens pairs that group things together
identifiers - tokens that name functions, variables, constants, and types
literals - tokens that specify values
operators - tokens that are used to combine values in expressions
punctuation - tokens that separate or terminate complex constructions
special - tokens with special meaning to the preprocessor or compiler
Grouping Operators
FIXME. grouping - tokens pairs that group things together
Identifiers
An identifier is a consecutive string of letters, digits, and underscore characters, the first of which is a letter or an underscore. Identifiers are tokens of the C language. They are used to name variables, constants, types, functions, and and members of structs and unions. Certain identifiers have predefined meanings and cannot be redefined. These identifiers, called keywords, are listed below. auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
Literal Constants
A literal is a token that specifies a value. The syntax of a literal depends on the type of value: integer, real, character, or string.
An integer literal can be written in decimal, octal, or hexadecimal form. A decimal (base 10) literal is any string of digits that does not begin with the digit '0'. This is the most common form for integer literals. An octal (base 8) literal is a string of digits, excluding '8' and '9'. A hexadecimal (base 16) literal begins with the characters '0x' or the characters '0X'. The remaining characters are hexadecimal digits, which include decimal digits and the letters 'a' through 'f' and 'A' through 'F'.
A real literal is written as decimal integer, followed by a decimal point, followed by a fractional part, which is a string of decimal digits. It may optionally be followed by an exponent, which consists of either the letter 'e' or the letter 'E' followed by a decimal integer. This integer is called the exponent. It specifies a power of ten that multiplies the preceding number, as in scientific notation. For example, 1.5e3 represents the number 1.5*1000, or 1500.0. The exponent may be signed.
A string literal is a sequence of characters other than quote marks, or escape sequences, enclosed in double quotes. A character literal is a character other than a quote mark, or an escape sequence, enclosed in single quotes. For both string and character literals, the following escape sequences are used: \n - a newline character
\t - a tab character
\' - a single quote character
\" - a double quote character
\\ - a backslash character
\0 - a null character (string terminator)
A null character is automatically appended to the end of all string literals.
Operators, Precedence, and Associativity
Operators are tokens that are used to combine values in expressions. When evaluating an expression, C uses precedence and associativity rules to determine the order in which operators are applied. In the table below, the C operators are listed in order of precedence with highest precedence at the top. The rows of the table define precedence groups. Two operators in the same group have the same precedence.
Associativity rules are only used to determine the order of evaluation for two operators that are in the same group. Most groups use left to right associativity, which means that in an expression with operators in the same precedence group, the operators are applied in left-to-right order. The order is reversed for right to left associativity. operator group associativity links
() [] -> . left to right selectors
! ~ ++ -- + - (type) * & sizeof right to left unary
* / % left to right multiplicative
+ - left to right additive
<< >> left to right bitwise
< <= > >= left to right comparison
== != left to right comparison
& left to right bitwise
^ left to right bitwise
| left to right bitwise
&& left to right boolean
|| left to right boolean
?: right to left conditional
= += -= *= /= %= &= ^= |= <<= >>= right to left assignment
, left to right comma
Punctuation Tokens
FIXME. punctuation - tokens that separate complex constructions into parts
Special Tokens
FIXME. special - tokens with special meaning to the preprocessor or compiler
Arguments in Function Calls
FIXME.
Selector Operators
FIXME.
Unary Operators
FIXME.
Multiplicative Operators
FIXME.
Additive Operators
FIXME.
Boolean Operators
FIXME.
Bitwise Operators
FIXME.
Equality and Comparison Operators
FIXME.
Conditional Expressions
The conditional expression has one of two values, depending on a boolean condition. It has the following form:
condition ? expression-1 : expression-2
where
condition is an expression that can be true (nonzero) or false (zero).
expression-1 and expression-2 are expressions that convert to a common type.
If condition is true then expression-1 is evaluated and its value becomes the value of the conditional expression. Otherwise, expression-2 is evaluated and its value becomes the value of the conditional expression.
Assignment Operators
FIXME.
The Comma Operator
FIXME.
about computer
Computer
From Wikipedia, the free encyclopedia
Jump to: navigation, search
For the IEEE magazine see Computer (magazine).
The NASA Columbia Supercomputer.A computer is a machine for manipulating data according to a list of instructions.
Computers take numerous physical forms. Early electronic computers were the size of a large room, consuming as much power as several hundred modern personal computers. [1] Today, computers can be made small enough to fit into a wrist watch and be powered from a watch battery. Society has come to recognize personal computers and their portable equivalent, the laptop computer, as icons of the information age; they are what most people think of as "a computer". However, the most common form of computer in use today is by far the embedded computer. Embedded computers are small, simple devices that are often used to control other devices—for example, they may be found in machines ranging from fighter aircraft to industrial robots, digital cameras, and even children's toys.
A computer in a wristwatch.The ability to store and execute programs makes computers extremely versatile and distinguishes them from calculators. The Church–Turing thesis is a mathematical statement of this versatility: Any computer with a certain minimum capability is, in principle, capable of performing the same tasks that any other computer can perform. Therefore, computers with capability and complexity ranging from that of a personal digital assistant to a supercomputer are all able to perform the same computational tasks as long as time and storage capacity are not considerations.
Contents [hide]
1 History of computing
2 Stored program architecture
2.1 Programs
2.2 Example
3 How computers work
3.1 Control unit
3.2 Arithmetic/logic unit (ALU)
3.3 Memory
3.4 Input/output (I/O)
3.5 Multitasking
3.6 Multiprocessing
3.7 Networking and the Internet
4 Further topics
4.1 Hardware
4.2 Software
4.3 Programming languages
4.4 Professions and organizations
5 See also
6 Notes
7 References
History of computing
Main article: History of computing
The Jacquard loom was one of the first programmable devices.It is difficult to define any one device as the earliest computer. The very definition of a computer has changed and it is therefore impossible to identify the first computer. Many devices once called "computers" would no longer qualify as such by today's standards.
Originally, the term "computer" referred to a person who performed numerical calculations (a human computer), often with the aid of a mechanical calculating device. Examples of early mechanical computing devices included the abacus, the slide rule and arguably the astrolabe and the Antikythera mechanism (which dates from about 150-100 BC). The end of the Middle Ages saw a re-invigoration of European mathematics and engineering, and Wilhelm Schickard's 1623 device was the first of a number of mechanical calculators constructed by European engineers.
However, none of those devices fit the modern definition of a computer because they could not be programmed. In 1801, Joseph Marie Jacquard made an improvement to the textile loom that used a series of punched paper cards as a template to allow his loom to weave intricate patterns automatically. The resulting Jacquard loom was an important step in the development of computers because the use of punched cards to define woven patterns can be viewed as an early, albeit limited, form of programmability.
In 1837, Charles Babbage was the first to conceptualize and design a fully programmable mechanical computer that he called "The Analytical Engine".[2] Due to limited finance, and an inability to resist tinkering with the design, Babbage never actually built his Analytical Engine.
Large-scale automated data processing of punched cards was performed for the US Census in 1890 by tabulating machines designed by Herman Hollerith and manufactured by the Computing Tabulating Recording Corporation, which later became IBM. By the end of the 19th century a number of technologies that would later prove useful in the realization of practical computers had begun to appear: the punched card, boolean algebra, the vacuum tube (thermionic valve) and the teleprinter.
During the first half of the 20th century, many scientific computing needs were met by increasingly sophisticated analog computers, which used a direct mechanical or electrical model of the problem as a basis for computation. However, these were not programmable and generally lacked the versatility and accuracy of modern digital computers.
Defining characteristics of five first operative digital computers Computer Shown working Binary Electronic Programmable Turing complete
Zuse Z3 May 1941 Yes No By punched film stock Yes (1998)
Atanasoff-Berry Computer Summer 1941 Yes Yes No No
Colossus December 1943 / January 1944 Yes Yes Partially, by rewiring No
Harvard Mark I - IBM ASCC 1944 No No By punched paper tape No
ENIAC 1944 No Yes Partially, by rewiring Yes
1948 No Yes By Function Table ROM Yes
A succession of steadily more powerful and flexible computing devices were constructed in the 1930s and 1940s, gradually adding the key features that are seen in modern computers. The use of digital electronics (largely invented by Claude Shannon in 1937) and more flexible programmability were vitally important steps, but defining one point along this road as "the first digital electronic computer" is difficult (Shannon 1940). Notable achievements include:
EDSAC was one of the first computers to implement the stored program (von Neumann) architecture.Konrad Zuse's electromechanical "Z machines". The Z3 (1941) was the first working machine featuring binary arithmetic, including floating point arithmetic and a measure of programmability. In 1998 the Z3 was proved to be Turing complete, therefore being the world's first operational computer.
The Atanasoff-Berry Computer (1941) which used vacuum tube based computation, binary numbers, and regenerative capacitor memory.
The secret British Colossus computer (1944), which had limited programmability but demonstrated that a device using thousands of tubes could be reasonably reliable and electronically reprogrammable. It was used for breaking German wartime codes.
The Harvard Mark I (1944), a large-scale electromechanical computer with limited programmability.
The US Army's Ballistics Research Laboratory ENIAC (1946), which used decimal arithmetic and was the first general purpose electronic computer, although it initially had an inflexible architecture which essentially required rewiring to change its programming.
Several developers of ENIAC, recognizing its flaws, came up with a far more flexible and elegant design, which came to be known as the stored program architecture or von Neumann architecture. This design was first formally described by John von Neumann in the paper "First Draft of a Report on the EDVAC", published in 1945. A number of projects to develop computers based on the stored program architecture commenced around this time, the first of these being completed in Great Britain. The first to be demonstrated working was the Manchester Small-Scale Experimental Machine (SSEM) or "Baby". However, the EDSAC, completed a year after SSEM, was perhaps the first practical implementation of the stored program design. Shortly thereafter, the machine originally described by von Neumann's paper—EDVAC—was completed but didn't see full-time use for an additional two years.
Nearly all modern computers implement some form of the stored program architecture, making it the single trait by which the word "computer" is now defined. By this standard, many earlier devices would no longer be called computers by today's definition, but are usually referred to as such in their historical context. While the technologies used in computers have changed dramatically since the first electronic, general-purpose computers of the 1940s, most still use the von Neumann architecture. The design made the universal computer a practical reality.
Microprocessors are miniaturized devices that often implement stored program CPUs.Vacuum tube-based computers were in use throughout the 1950s, but were largely replaced in the 1960s by transistor-based devices, which were smaller, faster, cheaper, used less power and were more reliable. These factors allowed computers to be produced on an unprecedented commercial scale. By the 1970s, the adoption of integrated circuit technology and the subsequent creation of microprocessors such as the Intel 4004 caused another leap in size, speed, cost and reliability. By the 1980s, computers had become sufficiently small and cheap to replace simple mechanical controls in domestic appliances such as washing machines. Around the same time, computers became widely accessible for personal use by individuals in the form of home computers and the now ubiquitous personal computer. In conjunction with the widespread growth of the Internet since the 1990s, personal computers are becoming as common as the television and the telephone and almost all modern electronic devices contain a computer of some kind.
Stored program architecture
Main articles: Computer program and Computer programming
The defining feature of modern computers which distinguishes them from all other machines is that they can be programmed. That is to say that a list of instructions (the program) can be given to the computer and it will store them and carry them out at some time in the future.
In most cases, computer instructions are simple: add one number to another, move some data from one location to another, send a message to some external device, etc. These instructions are read from the computer's memory and are generally carried out (executed) in the order they were given. However, there are usually specialized instructions to tell the computer to jump ahead or backwards to some other place in the program and to carry on executing from there. These are called "jump" instructions (or branches). Furthermore, jump instructions may be made to happen conditionally so that different sequences of instructions may be used depending on the result of some previous calculation or some external event. Many computers directly support subroutines by providing a type of jump that "remembers" the location it jumped from and another instruction to return to that point.
Program execution might be likened to reading a book. While a person will normally read each word and line in sequence, they may at times jump back to an earlier place in the text or skip sections that are not of interest. Similarly, a computer may sometimes go back and repeat the instructions in some section of the program over and over again until some internal condition is met. This is called the flow of control within the program and it is what allows the computer to perform tasks repeatedly without human intervention.
Comparatively, a person using a pocket calculator can perform a basic arithmetic operation such as adding two numbers with just a few button presses. But to add together all of the numbers from 1 to 1,000 would take thousands of button presses and a lot of time—with a near certainty of making a mistake. On the other hand, a computer may be programmed to do this with just a few simple instructions. For example:
mov #0,sum ; set sum to 0
mov #1,num ; set num to 1
loop: add num,sum ; add num to sum
add #1,num ; add 1 to num
cmp num,#1000 ; compare num to 1000
ble loop ; if num <= 1000, go back to 'loop'
halt ; end of program. stop running
Once told to run this program, the computer will perform the repetitive addition task without further human intervention. It will almost never make a mistake and a modern PC can complete the task in about a millionth of a second.[3]
However, computers cannot "think" for themselves in the sense that they only solve problems in exactly the way they are programmed to. An intelligent human faced with the above addition task might soon realize that instead of actually adding up all the numbers one can simply use the equation
and arrive at the correct answer (500,500) with little work. [4] In other words, a computer programmed to add up the numbers one by one as in the example above would do exactly that without regard to efficiency or alternative solutions.
Programs
A 1970s punched card containing one line from a FORTRAN program. The card reads: "Z(1) = Y + W(1)" and is labelled "PROJ039" for identification purposes.In practical terms, a computer program might include anywhere from a dozen instructions to many millions of instructions for something like a word processor or a web browser. A typical modern computer can execute billions of instructions every second and nearly never make a mistake over years of operation.
Large computer programs may take teams of computer programmers years to write and the probability of the entire program having been written completely in the manner intended is unlikely. Errors in computer programs are called bugs. Sometimes bugs are benign and do not affect the usefulness of the program, in other cases they might cause the program to completely fail (crash), in yet other cases there may be subtle problems. Sometimes otherwise benign bugs may be used for malicious intent, creating a security exploit. Bugs are usually not the fault of the computer. Since computers merely execute the instructions they are given, bugs are nearly always the result of programmer error or an oversight made in the program's design. [5]
In most computers, individual instructions are stored as machine code with each instruction being given a unique number (its operation code or opcode for short). The command to add two numbers together would have one opcode, the command to multiply them would have a different opcode and so on. The simplest computers are able to perform any of a handful of different instructions, the more complex computers have several hundred to choose from—each with a unique numerical code. Since the computer's memory is able to store numbers, it can also store the instruction codes. This leads to the important fact that entire programs (which are just lists of instructions) can be represented as lists of numbers and can themselves be manipulated inside the computer just as if they were numeric data. The fundamental concept of storing programs in the computer's memory alongside the data they operate on is the crux of the von Neumann, or stored program, architecture. In some cases, a computer might store some or all of its program in memory that is kept separate from the data it operates on. This is called the Harvard architecture after the Harvard Mark I computer. Modern von Neumann computers display some traits of the Harvard architecture in their designs, such as in CPU caches.
While it is possible to write computer programs as long lists of numbers (machine language) and this technique was used with many early computers,[6] it is extremely tedious to do so in practice, especially for complicated programs. Instead, each basic instruction can be given a short name that is indicative of its function and easy to remember—a mnemonic such as ADD, SUB, MULT or JUMP. These mnemonics are collectively known as a computer's assembly language. Converting programs written in assembly language into something the computer can actually understand (machine language) is usually done by a computer program called an assembler. Machine languages and the assembly languages that represent them (collectively termed low-level programming languages) tend to be unique to a particular type of computer. This means that an ARM architecture computer (such as may be found in a PDA or a hand-held videogame) cannot understand the machine language of an Intel Pentium or the AMD Athlon 64 computer that might be in a PC.[7]
Though considerably easier than in machine language, writing long programs in assembly language is often difficult and error prone. Therefore, most complicated programs are written in more abstract high-level programming languages that are able to express the needs of the computer programmer more conveniently (and thereby help reduce programmer error). High level languages are usually "compiled" into machine language (or sometimes into assembly language and then into machine language) using another computer program called a compiler.[8] Since high level languages are more abstract than assembly language, it is possible to use different compilers to translate the same high level language program into the machine language of many different types of computer. This is part of the means by which software like video games may be made available for different computer architectures such as personal computers and various video game consoles.
The task of developing large software systems is an immense intellectual effort. It has proven, historically, to be very difficult to produce software with an acceptably high reliability, on a predictable schedule and budget. The academic and professional discipline of software engineering concentrates specifically on this problem.
Example
A traffic light showing red.Suppose a computer is being employed to drive a traffic light. A simple stored program might say:
Turn off all of the lights
Turn on the red light
Wait for sixty seconds
Turn off the red light
Turn on the green light
Wait for sixty seconds
Turn off the green light
Turn on the yellow light
Wait for two seconds
Turn off the yellow light
Jump to instruction number (2)
With this set of instructions, the computer would cycle the light continually through red, green, yellow and back to red again until told to stop running the program.
However, suppose there is a simple on/off switch connected to the computer that is intended be used to make the light flash red while some maintenance operation is being performed. The program might then instruct the computer to:
Turn off all of the lights
Turn on the red light
Wait for sixty seconds
Turn off the red light
Turn on the green light
Wait for sixty seconds
Turn off the green light
Turn on the yellow light
Wait for two seconds
Turn off the yellow light
If the maintenance switch is NOT turned on then jump to instruction number 2
Turn on the red light
Wait for one second
Turn off the red light
Wait for one second
Jump to instruction number 11
In this manner, the computer is either running the instructions from number (2) to (11) over and over or it's running the instructions from (11) down to (16) over and over, depending on the position of the switch.[9]
How computers work
Main articles: Central processing unit and Microprocessor
A general purpose computer has four main sections: the arithmetic and logic unit (ALU), the control unit, the memory, and the input and output devices (collectively termed I/O). These parts are interconnected by busses, often made of groups of wires.
The control unit, ALU, registers, and basic I/O (and often other hardware closely linked with these) are collectively known as a central processing unit (CPU). Early CPUs were comprised of many separate components but since the mid-1970s CPUs have typically been constructed on a single integrated circuit called a microprocessor.
Control unit
Main articles: CPU design and Control unit
The control unit (often called a control system or central controller) directs the various components of a computer. It reads and interprets (decodes) instructions in the program one by one. The control system decodes each instruction and turns it into a series of control signals that operate the other parts of the computer.[10] Control systems in advanced computers may change the order of some instructions so as to improve performance.
A key component common to all CPUs is the program counter, a special memory cell (a register) that keeps track of which location in memory the next instruction is to be read from.[11]
Diagram showing how a particular MIPS architecture instruction would be decoded by the control system.The control system's function is as follows—note that this is a simplified description and some of these steps may be performed concurrently or in a different order depending on the type of CPU:
Read the code for the next instruction from the cell indicated by the program counter.
Decode the numerical code for the instruction into a set of commands or signals for each of the other systems.
Increment the program counter so it points to the next instruction.
Read whatever data the instruction requires from cells in memory (or perhaps from an input device). The location of this required data is typically stored within the instruction code.
Provide the necessary data to an ALU or register.
If the instruction requires an ALU or specialized hardware to complete, instruct the hardware to perform the requested operation.
Write the result from the ALU back to a memory location or to a register or perhaps an output device.
Jump back to step (1).
Since the program counter is (conceptually) just another set of memory cells, it can be changed by calculations done in the ALU. Adding 100 to the program counter would cause the next instruction to be read from a place 100 locations further down the program. Instructions that modify the program counter are often known as "jumps" and allow for loops (instructions that are repeated by the computer) and often conditional instruction execution (both examples of control flow).
It is noticeable that the sequence of operations that the control unit goes through to process an instruction is in itself like a short computer program - and indeed, in some more complex CPU designs, there is another yet smaller computer called a microsequencer that runs a microcode program that causes all of these events to happen.
Arithmetic/logic unit (ALU)
Main article: Arithmetic logic unit
The ALU is capable of performing two classes of operations: arithmetic and logic.
The set of arithmetic operations that a particular ALU supports may be limited to adding and subtracting or might include multiplying or dividing, trigonometry functions (sine, cosine, etc) and square roots. Some can only operate on whole numbers (integers) whilst others use floating point to represent real numbers—albeit with limited precision. However, any computer that is capable of performing just the simplest operations can be programmed to break down the more complex operations into simple steps that it can perform. Therefore, any computer can be programmed to perform any arithmetic operation—although it will take more time to do so if its ALU does not directly support the operation. An ALU may also compare numbers and return boolean truth values (true or false) depending on whether one is equal to, greater than or less than the other ("is 64 greater than 65?").
Logic operations involve boolean logic: AND, OR, XOR and NOT. These can be useful both for creating complicated conditional statements and processing boolean logic.
Superscalar computers contain multiple ALUs so that they can process several instructions at the same time. Graphics processors and computers with SIMD and MIMD features often provide ALUs that can perform arithmetic on vectors and matrices.
Memory
Main article: Computer storage
Magnetic core memory was popular main memory for computers through the 1960s until it was completely replaced by semiconductor memory.A computer's memory can be viewed as a list of cells into which numbers can be placed or read. Each cell has a numbered "address" and can store a single number. The computer can be instructed to "put the number 123 into the cell numbered 1357" or to "add the number that is in cell 1357 to the number that is in cell 2468 and put the answer into cell 1595". The information stored in memory may represent practically anything. Letters, numbers, even computer instructions can be placed into memory with equal ease. Since the CPU does not differentiate between different types of information, it is up to the software to give significance to what the memory sees as nothing but a series of numbers.
In almost all modern computers, each memory cell is set up to store binary numbers in groups of eight bits (called a byte). Each byte is able to represent 256 different numbers; either from 0 to 255 or -128 to +127. To store larger numbers, several consecutive bytes may be used (typically, two, four or eight). When negative numbers are required, they are usually stored in two's complement notation. Other arrangements are possible, but are usually not seen outside of specialized applications or historical contexts. A computer can store any kind of information in memory as long as it can be somehow represented in numerical form. Modern computers have billions or even trillions of bytes of memory.
The CPU contains a special set of memory cells called registers that can be read and written to much more rapidly than the main memory area. There are typically between two and one hundred registers depending on the type of CPU. Registers are used for the most frequently needed data items to avoid having to access main memory every time data is needed. Since data is constantly being worked on, reducing the need to access main memory (which is often slow compared to the ALU and control units) greatly increases the computer's speed.
Computer main memory comes in two principal varieties: random access memory or RAM and read-only memory or ROM. RAM can be read and written to anytime the CPU commands it, but ROM is pre-loaded with data and software that never changes, so the CPU can only read from it. ROM is typically used to store the computer's initial start-up instructions. In general, the contents of RAM is erased when the power to the computer is turned off while ROM retains its data indefinitely. In a PC, the ROM contains a specialized program called the BIOS that orchestrates loading the computer's operating system from the hard disk drive into RAM whenever the computer is turned on or reset. In embedded computers, which frequently do not have disk drives, all of the software required to perform the task may be stored in ROM. Software that is stored in ROM is often called firmware because it is notionally more like hardware than software. Flash memory blurs the distinction between ROM and RAM by retaining data when turned off but being rewritable like RAM. However, flash memory is typically much slower than conventional ROM and RAM so its use is restricted to applications where high speeds are not required. [12]
In more sophisticated computers there may be one or more RAM cache memories which are slower than registers but faster than main memory. Generally computers with this sort of cache are designed to move frequently needed data into the cache automatically, often without the need for any intervention on the programmer's part.
Input/output (I/O)
Main article: Input/output
Hard disks are common I/O devices used with computers.I/O is the means by which a computer receives information from the outside world and sends results back. Devices that provide input or output to the computer are called peripherals. On a typical personal computer, peripherals include inputs like the keyboard and mouse, and outputs such as the display and printer. Hard disks, floppy disks and optical discs serve as both inputs and outputs. Computer networking is another form of I/O.
Practically any device that can be made to interface digitally may be used as I/O. The computer in the Engine Control Unit of a modern automobile might read the position of the pedals and steering wheel, the output of the oxygen sensor and devices that monitor the speed of each wheel. The output devices include the various lights and gauges that the driver sees as well as the engine controls such as the spark ignition circuits and fuel injection systems. In a digital wristwatch, the computer reads the buttons and causes numbers and symbols to be shown on the liquid crystal display.
Often, I/O devices are complex computers in their own right with their own CPU and memory. A graphics processing unit might contain fifty or more tiny computers that perform the calculations necessary to display 3D graphics. Modern desktop computers contain many smaller computers that assist the main CPU in performing I/O.
Multitasking
Main article: Computer multitasking
While a computer may be viewed as running one gigantic program stored in its main memory, in some systems it is necessary to give the appearance of running several programs simultaneously. This is achieved by having the computer switch rapidly between running each program in turn. One means by which this is done is with a special signal called an interrupt which can periodically cause the computer to stop executing instructions where it was and do something else instead. By remembering where it was executing prior to the interrupt, the computer can return to that task later. If several programs are running "at the same time", then the interrupt generator might be causing several hundred interrupts per second, causing a program switch each time. Since modern computers typically execute instructions several orders of magnitude faster than human perception, it may appear that many programs are running at the same time even though only one is ever executing in any given instant. This method of multitasking is sometimes termed "time-sharing" since each program is allocated a "slice" of time in turn.
Before the era of cheap computers, the principle use for multitasking was to allow many people to share the same computer.
Seemingly, multitasking would cause a computer that is switching between several programs to run more slowly - in direct proportion to the number of programs it is running. However, most programs spend much of their time waiting for slow input/output devices to complete their tasks. If a program is waiting for the user to click on the mouse or press a key on the keyboard, then it will not take a "time slice" until the event it is waiting for has occurred. This frees up time for other programs to execute so that many programs may be run at the same time without unacceptable speed loss.
Multiprocessing
Main article: Multiprocessing
Cray designed many supercomputers that used multiprocessing heavily.Some computers may divide their work between one or more separate CPUs, creating a multiprocessing configuration. Traditionally, this technique was utilized only in large and powerful computers such as supercomputers, mainframe computers and servers. However, multiprocessor and multi-core (multiple CPUs on a single integrated circuit) personal and laptop computers have become widely available and are beginning to see increased usage in lower-end markets as a result.
Supercomputers in particular often have highly unique architectures that differ significantly from the basic stored-program architecture and from general purpose computers.[13] They often feature thousands of CPUs, customized high-speed interconnects, and specialized computing hardware. Such designs tend to be useful only for specialized tasks due to the large scale of program organization required to successfully utilize most of a the available resources at once. Supercomputers usually see usage in large-scale simulation, graphics rendering, and cryptography applications, as well as with other so-called "embarrassingly parallel" tasks.
Networking and the Internet
Main articles: Computer networking and Internet
Visualization of a portion of the routes on the Internet.Computers have been used to coordinate information in multiple locations since the 1950s, with the US military's SAGE system the first large-scale example of such a system, which led to a number of special-purpose commercial systems like Sabre.
In the 1970s, computer engineers at research institutions throughout the US began to link their computers together using telecommunications technology. This effort was funded by ARPA (now DARPA), and the computer network that it produced was called the ARPANET. The technologies that made the Arpanet possible spread and evolved. In time, the network spread beyond academic and military institutions and became known as the Internet. The emergence of networking involved a redefinition of the nature and boundaries of the computer. Computer operating systems and applications were modified to include the ability to define and access the resources of other computers on the network, such as peripheral devices, stored information, and the like, as extensions of the resources of an individual computer. Initially these facilities were available primarily to people working in high-tech environments, but in the 1990s the spread of applications like e-mail and the World Wide Web, combined with the development of cheap, fast networking technologies like Ethernet and ADSL saw computer networking become almost ubiquitous. In fact, the number of computers that are networked is growing phenomenally. A very large proportion of personal computers regularly connect to the Internet to communicate and receive information. "Wireless" networking, often utilizing mobile phone networks, has meant networking is becoming increasingly ubiquitous even in mobile computing environments.
Further topics
Hardware
The term hardware covers all of those parts of a computer that are tangible objects. Circuits, displays, power supplies, cables, keyboards, printers and mice are all hardware.
History of computing hardware First Generation (Mechanical/Electromechanical) Calculators Antikythera mechanism, Difference Engine, Norden bombsight
Programmable Devices Jacquard loom, Analytical Engine, Harvard Mark I, Z3
Second Generation (Vacuum Tubes) Calculators Atanasoff-Berry Computer
Programmable Devices ENIAC, EDSAC, EDVAC, UNIVAC I
Third Generation (Discrete transistors and SSI, MSI, LSI Integrated circuits) Mainframes System/360, BUNCH
Minicomputer PDP-8, PDP-11, System/32, System/36
Fourth Generation (VLSI integrated circuits) Minicomputer VAX, AS/400
4-bit microcomputer Intel 4004, Intel 4040
8-bit microcomputer Intel 8008, Intel 8080, Motorola 6800, Motorola 6809, MOS Technology 6502, Zilog Z80
16-bit microcomputer 8088, Zilog Z8000, WDC 65816/65802
32-bit microcomputer 80386, Pentium, 68000, ARM architecture
64-bit microcomputer [14] x86-64, PowerPC, MIPS, SPARC
Embedded computer 8048, 8051
Personal computer Desktop computer, Home computer, Laptop computer, Personal digital assistant (PDA), Portable computer, Tablet computer, Wearable computer
Server class computer
Theoretical/experimental Quantum computer
Chemical computer
DNA computing
Optical computer
Other Hardware Topics Peripheral device (Input/output) Input Mouse, Keyboard, Joystick, Image scanner
Output Monitor, Printer
Both Floppy disk drive, Hard disk, Optical disc drive, Teleprinter
Computer busses Short range RS-232, SCSI, PCI, USB
Long range (Computer networking) Ethernet, ATM, FDDI
Software
Software refers to parts of the computer that have no material form; programs, data, protocols, etc are all software. When software is stored in hardware that cannot easily be modified (such as BIOS ROM in an IBM PC compatible), it is sometimes termed firmware to indicate that it falls into an area of uncertainty between hardware and software.
Computer software Operating system Unix/BSD UNIX System V, AIX, HP-UX, Solaris (SunOS), FreeBSD, NetBSD, IRIX
GNU/Linux List of Linux distributions, Comparison of Linux distributions
Microsoft Windows Windows 9x, Windows NT, Windows CE
DOS QDOS, PC-DOS, MS-DOS, FreeDOS
Mac OS Mac OS classic, Mac OS X
Embedded and real-time List of embedded operating systems
Experimental Amoeba, Oberon/Bluebottle, Plan 9 from Bell Labs
Library Multimedia DirectX, OpenGL, OpenAL
Programming library C standard library, Standard template library
Data Protocol TCP/IP, Kermit, FTP, HTTP, SMTP
File format HTML, XML, JPEG, MPEG, PNG
User interface Graphical user interface (WIMP) Microsoft Windows, GNOME, QNX Photon, CDE, GEM
Text user interface Command line interface, shells
Other
Application Office suite Word processing, Desktop publishing, Presentation program, Database management system, Scheduling & Time management, Spreadsheet, Accounting software
Internet Access Browser, E-mail client, Web server, Mail transfer agent, Instant messaging
Design and manufacturing Computer-aided design, Computer-aided manufacturing, Plant management, Robotic manufacturing, Supply chain management
Graphics Raster graphics editor, Vector graphics editor, 3D modeler, Animation editor, 3D computer graphics, Video editing, Image processing
Audio Digital audio editor, Audio playback, Mixing, Audio synthesis, Computer music
Software Engineering Compiler, Assembler, Interpreter, Debugger, Text Editor, Integrated development environment, Performance analysis, Revision control, Software configuration management
Educational Edutainment, Educational game, Serious game, Flight simulator
Games Strategy, Arcade, Puzzle, Simulation, First-person shooter, Platform, Massively multiplayer, Interactive fiction
Misc Artificial intelligence, Antivirus software, Malware scanner, Installer/Package management systems, File manager
Programming languages
Programming languages provide various ways of specifying programs for computers to run. Unlike natural languages, programming languages are designed to permit no ambiguity and to be concise. They are purely written languages and are often difficult to read aloud. They are generally either translated into machine language by a compiler or an assembler before being run, or translated directly at run time by an interpreter. Sometimes programs are executed by a hybrid method of the two techniques. There are thousands of different programming languages—some intended to be general purpose, others useful only for highly specialized applications.
Programming Languages Lists of programming languages Timeline of programming languages, Categorical list of programming languages, Generational list of programming languages, Alphabetical list of programming languages, Non-English-based programming languages
Commonly used Assembly languages ARM, MIPS, x86
Commonly used High level languages BASIC, C, C++, C#, COBOL, Fortran, Java, Lisp, Pascal
Commonly used Scripting languages JavaScript, Python, Ruby, PHP, Perl
Professions and organizations
As the use of computers has spread throughout society, there are an increasing number of careers involving computers. Following the theme of hardware, software and firmware, the brains of people who work in the industry are sometimes known irreverently as wetware or "meatware".
Computer-related professions Hardware-related Electrical engineering, Electronics engineering, Computer engineering, Telecommunications engineering, Optical engineering, Nanoscale engineering
Software-related Human-computer interaction, Information technology, Software engineering, Scientific computing, Web design, Desktop publishing, Sound recording and reproduction
The need for computers to work well together and to be able to exchange information has spawned the need for many standards organizations, clubs and societies of both a formal and informal nature.
Organizations Standards groups ANSI, IEC, IEEE, IETF, ISO, W3C
Professional Societies ACM, ACM Special Interest Groups, IET, IFIP
Free/Open source software groups Free Software Foundation, Mozilla Foundation, Apache Software Foundation
See also
Look up Computer in
Wiktionary, the free dictionary.Wikiquote has a collection of quotations related to:
ComputersWikimedia Commons has media related to:
ComputerComputability theory
Computer science
Computing
Computers in fiction
Computer security and Computer insecurity
List of computer term etymologies
Virtualization
Notes
^ In 1946, ENIAC consumed an estimated 174 kW. By comparison, a typical personal computer may use around 400 W; over four hundred times less. (Kempf 1961)
^ The Analytical Engine should not be confused with Babbage's difference engine which was a non-programmable mechanical calculator.
^ This program was designed for the PDP-11 minicomputer and shows some typical things a computer can do. All the text after the semicolons are comments for the benefit of human readers. These have no significance to the computer and are ignored. (Digital Equipment Corporation 1972)
^ Attempts are often made to create programs that can overcome this fundamental limitation of computers. Software that mimics learning and adaptation is part of artificial intelligence.
^ It is not universally true that bugs are solely due to programmer oversight. Computer hardware may fail or may itself have a fundamental problem that produces unexpected results in certain situations. For instance, the Pentium FDIV bug caused some Intel microprocessors in the early 1990s to produce inaccurate results for certain floating point division operations. This was caused by a flaw in the microprocessor design and resulted in a partial recall of the affected devices.
^ Even some later computers were commonly programmed directly in machine code. Some minicomputers like the DEC PDP-8 could be programmed directly from a panel of switches. However, this method was usually used only as part of the booting process. Most modern computers boot entirely automatically by reading a boot program from some non-volatile memory.
^ However, there is sometimes some form of machine language compatibility between different computers. An x86-64 compatible microprocessor like the AMD Athlon 64 is able to run most of the same programs that an Intel Core 2 microprocessor can, as well as programs designed for earlier microprocessors like the Intel Pentiums and Intel 80486. This contrasts with very early commercial computers, which were often one-of-a-kind and totally incompatible with other computers.
^ High level languages are also often interpreted rather than compiled. Interpreted languages are translated into machine code on the fly by another program called an interpreter.
^ Although this is a simple program, it contains a software bug. If the traffic signal is showing red when someone switches the "flash red" switch, it will cycle through green once more before starting to flash red as instructed. This bug is quite easy to fix by changing the program to repeatedly test the switch throughout each "wait" period—but writing large programs that have no bugs is exceedingly difficult.
^ The control unit's rule in interpreting instructions has varied somewhat in the past. While the control unit is solely responsible for instruction interpretation in most modern computers, this is not always the case. Many computers include some instructions that may only be partially interpreted by the control system and partially interpreted by another device. This is especially the case with specialized computing hardware that may be partially self-contained. For example, EDVAC, the first modern stored program computer to be designed, used a central control unit that only interpreted four instructions. All of the arithmetic-related instructions were passed on to its arithmetic unit and further decoded there.
^ Instructions often occupy more than one memory address, so the program counters usually increases by the number of memory locations required to store one instruction.
^ Flash memory also may only be rewritten a limited number of times before wearing out, making it less useful for heavy random access usage. (Verma 1988)
^ However, it is also very common to construct supercomputers out of many pieces of cheap commodity hardware; usually individual computers connected by networks. These so-called computer clusters can often provide supercomputer performance at a much lower cost than customized designs. While custom architectures are still used for most of the most powerful supercomputers, there has been a proliferation of cluster computers in recent years. (TOP500 2006)
^ Most major 64-bit instruction set architectures are extensions of earlier designs. All of the architectures listed in this table existed in 32-bit forms before their 64-bit incarnations were introduced.
References
a Kempf, Karl (1961). "Historical Monograph: Electronic Computers Within the Ordnance Corps". Aberdeen Proving Ground (United States Army).
a Phillips, Tony (2000). The Antikythera Mechanism I. American Mathematical Society. Retrieved on 2006-04-05.
a Shannon, Claude Elwood (1940). "A symbolic analysis of relay and switching circuits". Massachusetts Institute of Technology.
a Digital Equipment Corporation (1972). PDP-11/40 Processor Handbook (PDF), Maynard, MA: Digital Equipment Corporation.
a Verma, G.; Mielke, N. (1988). "Reliability performance of ETOX based flash memories". IEEE International Reliability Physics Symposium.
a Meuer, Hans; Strohmaier, Erich; Simon, Horst; Dongarra, Jack (2006-11-13). Architectures Share Over Time. TOP500. Retrieved on 2006-11-27.
Stokes, Jon (2007). Inside the Machine: An Illustrated Introduction to Microprocessors and Computer Architecture. San Francisco: No Starch Press. ISBN 978-1-59327-104-6.
Retrieved from "http://en.wikipedia.org/wiki/Computer"
Categories: Semi-protected | Computing
From Wikipedia, the free encyclopedia
Jump to: navigation, search
For the IEEE magazine see Computer (magazine).
The NASA Columbia Supercomputer.A computer is a machine for manipulating data according to a list of instructions.
Computers take numerous physical forms. Early electronic computers were the size of a large room, consuming as much power as several hundred modern personal computers. [1] Today, computers can be made small enough to fit into a wrist watch and be powered from a watch battery. Society has come to recognize personal computers and their portable equivalent, the laptop computer, as icons of the information age; they are what most people think of as "a computer". However, the most common form of computer in use today is by far the embedded computer. Embedded computers are small, simple devices that are often used to control other devices—for example, they may be found in machines ranging from fighter aircraft to industrial robots, digital cameras, and even children's toys.
A computer in a wristwatch.The ability to store and execute programs makes computers extremely versatile and distinguishes them from calculators. The Church–Turing thesis is a mathematical statement of this versatility: Any computer with a certain minimum capability is, in principle, capable of performing the same tasks that any other computer can perform. Therefore, computers with capability and complexity ranging from that of a personal digital assistant to a supercomputer are all able to perform the same computational tasks as long as time and storage capacity are not considerations.
Contents [hide]
1 History of computing
2 Stored program architecture
2.1 Programs
2.2 Example
3 How computers work
3.1 Control unit
3.2 Arithmetic/logic unit (ALU)
3.3 Memory
3.4 Input/output (I/O)
3.5 Multitasking
3.6 Multiprocessing
3.7 Networking and the Internet
4 Further topics
4.1 Hardware
4.2 Software
4.3 Programming languages
4.4 Professions and organizations
5 See also
6 Notes
7 References
History of computing
Main article: History of computing
The Jacquard loom was one of the first programmable devices.It is difficult to define any one device as the earliest computer. The very definition of a computer has changed and it is therefore impossible to identify the first computer. Many devices once called "computers" would no longer qualify as such by today's standards.
Originally, the term "computer" referred to a person who performed numerical calculations (a human computer), often with the aid of a mechanical calculating device. Examples of early mechanical computing devices included the abacus, the slide rule and arguably the astrolabe and the Antikythera mechanism (which dates from about 150-100 BC). The end of the Middle Ages saw a re-invigoration of European mathematics and engineering, and Wilhelm Schickard's 1623 device was the first of a number of mechanical calculators constructed by European engineers.
However, none of those devices fit the modern definition of a computer because they could not be programmed. In 1801, Joseph Marie Jacquard made an improvement to the textile loom that used a series of punched paper cards as a template to allow his loom to weave intricate patterns automatically. The resulting Jacquard loom was an important step in the development of computers because the use of punched cards to define woven patterns can be viewed as an early, albeit limited, form of programmability.
In 1837, Charles Babbage was the first to conceptualize and design a fully programmable mechanical computer that he called "The Analytical Engine".[2] Due to limited finance, and an inability to resist tinkering with the design, Babbage never actually built his Analytical Engine.
Large-scale automated data processing of punched cards was performed for the US Census in 1890 by tabulating machines designed by Herman Hollerith and manufactured by the Computing Tabulating Recording Corporation, which later became IBM. By the end of the 19th century a number of technologies that would later prove useful in the realization of practical computers had begun to appear: the punched card, boolean algebra, the vacuum tube (thermionic valve) and the teleprinter.
During the first half of the 20th century, many scientific computing needs were met by increasingly sophisticated analog computers, which used a direct mechanical or electrical model of the problem as a basis for computation. However, these were not programmable and generally lacked the versatility and accuracy of modern digital computers.
Defining characteristics of five first operative digital computers Computer Shown working Binary Electronic Programmable Turing complete
Zuse Z3 May 1941 Yes No By punched film stock Yes (1998)
Atanasoff-Berry Computer Summer 1941 Yes Yes No No
Colossus December 1943 / January 1944 Yes Yes Partially, by rewiring No
Harvard Mark I - IBM ASCC 1944 No No By punched paper tape No
ENIAC 1944 No Yes Partially, by rewiring Yes
1948 No Yes By Function Table ROM Yes
A succession of steadily more powerful and flexible computing devices were constructed in the 1930s and 1940s, gradually adding the key features that are seen in modern computers. The use of digital electronics (largely invented by Claude Shannon in 1937) and more flexible programmability were vitally important steps, but defining one point along this road as "the first digital electronic computer" is difficult (Shannon 1940). Notable achievements include:
EDSAC was one of the first computers to implement the stored program (von Neumann) architecture.Konrad Zuse's electromechanical "Z machines". The Z3 (1941) was the first working machine featuring binary arithmetic, including floating point arithmetic and a measure of programmability. In 1998 the Z3 was proved to be Turing complete, therefore being the world's first operational computer.
The Atanasoff-Berry Computer (1941) which used vacuum tube based computation, binary numbers, and regenerative capacitor memory.
The secret British Colossus computer (1944), which had limited programmability but demonstrated that a device using thousands of tubes could be reasonably reliable and electronically reprogrammable. It was used for breaking German wartime codes.
The Harvard Mark I (1944), a large-scale electromechanical computer with limited programmability.
The US Army's Ballistics Research Laboratory ENIAC (1946), which used decimal arithmetic and was the first general purpose electronic computer, although it initially had an inflexible architecture which essentially required rewiring to change its programming.
Several developers of ENIAC, recognizing its flaws, came up with a far more flexible and elegant design, which came to be known as the stored program architecture or von Neumann architecture. This design was first formally described by John von Neumann in the paper "First Draft of a Report on the EDVAC", published in 1945. A number of projects to develop computers based on the stored program architecture commenced around this time, the first of these being completed in Great Britain. The first to be demonstrated working was the Manchester Small-Scale Experimental Machine (SSEM) or "Baby". However, the EDSAC, completed a year after SSEM, was perhaps the first practical implementation of the stored program design. Shortly thereafter, the machine originally described by von Neumann's paper—EDVAC—was completed but didn't see full-time use for an additional two years.
Nearly all modern computers implement some form of the stored program architecture, making it the single trait by which the word "computer" is now defined. By this standard, many earlier devices would no longer be called computers by today's definition, but are usually referred to as such in their historical context. While the technologies used in computers have changed dramatically since the first electronic, general-purpose computers of the 1940s, most still use the von Neumann architecture. The design made the universal computer a practical reality.
Microprocessors are miniaturized devices that often implement stored program CPUs.Vacuum tube-based computers were in use throughout the 1950s, but were largely replaced in the 1960s by transistor-based devices, which were smaller, faster, cheaper, used less power and were more reliable. These factors allowed computers to be produced on an unprecedented commercial scale. By the 1970s, the adoption of integrated circuit technology and the subsequent creation of microprocessors such as the Intel 4004 caused another leap in size, speed, cost and reliability. By the 1980s, computers had become sufficiently small and cheap to replace simple mechanical controls in domestic appliances such as washing machines. Around the same time, computers became widely accessible for personal use by individuals in the form of home computers and the now ubiquitous personal computer. In conjunction with the widespread growth of the Internet since the 1990s, personal computers are becoming as common as the television and the telephone and almost all modern electronic devices contain a computer of some kind.
Stored program architecture
Main articles: Computer program and Computer programming
The defining feature of modern computers which distinguishes them from all other machines is that they can be programmed. That is to say that a list of instructions (the program) can be given to the computer and it will store them and carry them out at some time in the future.
In most cases, computer instructions are simple: add one number to another, move some data from one location to another, send a message to some external device, etc. These instructions are read from the computer's memory and are generally carried out (executed) in the order they were given. However, there are usually specialized instructions to tell the computer to jump ahead or backwards to some other place in the program and to carry on executing from there. These are called "jump" instructions (or branches). Furthermore, jump instructions may be made to happen conditionally so that different sequences of instructions may be used depending on the result of some previous calculation or some external event. Many computers directly support subroutines by providing a type of jump that "remembers" the location it jumped from and another instruction to return to that point.
Program execution might be likened to reading a book. While a person will normally read each word and line in sequence, they may at times jump back to an earlier place in the text or skip sections that are not of interest. Similarly, a computer may sometimes go back and repeat the instructions in some section of the program over and over again until some internal condition is met. This is called the flow of control within the program and it is what allows the computer to perform tasks repeatedly without human intervention.
Comparatively, a person using a pocket calculator can perform a basic arithmetic operation such as adding two numbers with just a few button presses. But to add together all of the numbers from 1 to 1,000 would take thousands of button presses and a lot of time—with a near certainty of making a mistake. On the other hand, a computer may be programmed to do this with just a few simple instructions. For example:
mov #0,sum ; set sum to 0
mov #1,num ; set num to 1
loop: add num,sum ; add num to sum
add #1,num ; add 1 to num
cmp num,#1000 ; compare num to 1000
ble loop ; if num <= 1000, go back to 'loop'
halt ; end of program. stop running
Once told to run this program, the computer will perform the repetitive addition task without further human intervention. It will almost never make a mistake and a modern PC can complete the task in about a millionth of a second.[3]
However, computers cannot "think" for themselves in the sense that they only solve problems in exactly the way they are programmed to. An intelligent human faced with the above addition task might soon realize that instead of actually adding up all the numbers one can simply use the equation
and arrive at the correct answer (500,500) with little work. [4] In other words, a computer programmed to add up the numbers one by one as in the example above would do exactly that without regard to efficiency or alternative solutions.
Programs
A 1970s punched card containing one line from a FORTRAN program. The card reads: "Z(1) = Y + W(1)" and is labelled "PROJ039" for identification purposes.In practical terms, a computer program might include anywhere from a dozen instructions to many millions of instructions for something like a word processor or a web browser. A typical modern computer can execute billions of instructions every second and nearly never make a mistake over years of operation.
Large computer programs may take teams of computer programmers years to write and the probability of the entire program having been written completely in the manner intended is unlikely. Errors in computer programs are called bugs. Sometimes bugs are benign and do not affect the usefulness of the program, in other cases they might cause the program to completely fail (crash), in yet other cases there may be subtle problems. Sometimes otherwise benign bugs may be used for malicious intent, creating a security exploit. Bugs are usually not the fault of the computer. Since computers merely execute the instructions they are given, bugs are nearly always the result of programmer error or an oversight made in the program's design. [5]
In most computers, individual instructions are stored as machine code with each instruction being given a unique number (its operation code or opcode for short). The command to add two numbers together would have one opcode, the command to multiply them would have a different opcode and so on. The simplest computers are able to perform any of a handful of different instructions, the more complex computers have several hundred to choose from—each with a unique numerical code. Since the computer's memory is able to store numbers, it can also store the instruction codes. This leads to the important fact that entire programs (which are just lists of instructions) can be represented as lists of numbers and can themselves be manipulated inside the computer just as if they were numeric data. The fundamental concept of storing programs in the computer's memory alongside the data they operate on is the crux of the von Neumann, or stored program, architecture. In some cases, a computer might store some or all of its program in memory that is kept separate from the data it operates on. This is called the Harvard architecture after the Harvard Mark I computer. Modern von Neumann computers display some traits of the Harvard architecture in their designs, such as in CPU caches.
While it is possible to write computer programs as long lists of numbers (machine language) and this technique was used with many early computers,[6] it is extremely tedious to do so in practice, especially for complicated programs. Instead, each basic instruction can be given a short name that is indicative of its function and easy to remember—a mnemonic such as ADD, SUB, MULT or JUMP. These mnemonics are collectively known as a computer's assembly language. Converting programs written in assembly language into something the computer can actually understand (machine language) is usually done by a computer program called an assembler. Machine languages and the assembly languages that represent them (collectively termed low-level programming languages) tend to be unique to a particular type of computer. This means that an ARM architecture computer (such as may be found in a PDA or a hand-held videogame) cannot understand the machine language of an Intel Pentium or the AMD Athlon 64 computer that might be in a PC.[7]
Though considerably easier than in machine language, writing long programs in assembly language is often difficult and error prone. Therefore, most complicated programs are written in more abstract high-level programming languages that are able to express the needs of the computer programmer more conveniently (and thereby help reduce programmer error). High level languages are usually "compiled" into machine language (or sometimes into assembly language and then into machine language) using another computer program called a compiler.[8] Since high level languages are more abstract than assembly language, it is possible to use different compilers to translate the same high level language program into the machine language of many different types of computer. This is part of the means by which software like video games may be made available for different computer architectures such as personal computers and various video game consoles.
The task of developing large software systems is an immense intellectual effort. It has proven, historically, to be very difficult to produce software with an acceptably high reliability, on a predictable schedule and budget. The academic and professional discipline of software engineering concentrates specifically on this problem.
Example
A traffic light showing red.Suppose a computer is being employed to drive a traffic light. A simple stored program might say:
Turn off all of the lights
Turn on the red light
Wait for sixty seconds
Turn off the red light
Turn on the green light
Wait for sixty seconds
Turn off the green light
Turn on the yellow light
Wait for two seconds
Turn off the yellow light
Jump to instruction number (2)
With this set of instructions, the computer would cycle the light continually through red, green, yellow and back to red again until told to stop running the program.
However, suppose there is a simple on/off switch connected to the computer that is intended be used to make the light flash red while some maintenance operation is being performed. The program might then instruct the computer to:
Turn off all of the lights
Turn on the red light
Wait for sixty seconds
Turn off the red light
Turn on the green light
Wait for sixty seconds
Turn off the green light
Turn on the yellow light
Wait for two seconds
Turn off the yellow light
If the maintenance switch is NOT turned on then jump to instruction number 2
Turn on the red light
Wait for one second
Turn off the red light
Wait for one second
Jump to instruction number 11
In this manner, the computer is either running the instructions from number (2) to (11) over and over or it's running the instructions from (11) down to (16) over and over, depending on the position of the switch.[9]
How computers work
Main articles: Central processing unit and Microprocessor
A general purpose computer has four main sections: the arithmetic and logic unit (ALU), the control unit, the memory, and the input and output devices (collectively termed I/O). These parts are interconnected by busses, often made of groups of wires.
The control unit, ALU, registers, and basic I/O (and often other hardware closely linked with these) are collectively known as a central processing unit (CPU). Early CPUs were comprised of many separate components but since the mid-1970s CPUs have typically been constructed on a single integrated circuit called a microprocessor.
Control unit
Main articles: CPU design and Control unit
The control unit (often called a control system or central controller) directs the various components of a computer. It reads and interprets (decodes) instructions in the program one by one. The control system decodes each instruction and turns it into a series of control signals that operate the other parts of the computer.[10] Control systems in advanced computers may change the order of some instructions so as to improve performance.
A key component common to all CPUs is the program counter, a special memory cell (a register) that keeps track of which location in memory the next instruction is to be read from.[11]
Diagram showing how a particular MIPS architecture instruction would be decoded by the control system.The control system's function is as follows—note that this is a simplified description and some of these steps may be performed concurrently or in a different order depending on the type of CPU:
Read the code for the next instruction from the cell indicated by the program counter.
Decode the numerical code for the instruction into a set of commands or signals for each of the other systems.
Increment the program counter so it points to the next instruction.
Read whatever data the instruction requires from cells in memory (or perhaps from an input device). The location of this required data is typically stored within the instruction code.
Provide the necessary data to an ALU or register.
If the instruction requires an ALU or specialized hardware to complete, instruct the hardware to perform the requested operation.
Write the result from the ALU back to a memory location or to a register or perhaps an output device.
Jump back to step (1).
Since the program counter is (conceptually) just another set of memory cells, it can be changed by calculations done in the ALU. Adding 100 to the program counter would cause the next instruction to be read from a place 100 locations further down the program. Instructions that modify the program counter are often known as "jumps" and allow for loops (instructions that are repeated by the computer) and often conditional instruction execution (both examples of control flow).
It is noticeable that the sequence of operations that the control unit goes through to process an instruction is in itself like a short computer program - and indeed, in some more complex CPU designs, there is another yet smaller computer called a microsequencer that runs a microcode program that causes all of these events to happen.
Arithmetic/logic unit (ALU)
Main article: Arithmetic logic unit
The ALU is capable of performing two classes of operations: arithmetic and logic.
The set of arithmetic operations that a particular ALU supports may be limited to adding and subtracting or might include multiplying or dividing, trigonometry functions (sine, cosine, etc) and square roots. Some can only operate on whole numbers (integers) whilst others use floating point to represent real numbers—albeit with limited precision. However, any computer that is capable of performing just the simplest operations can be programmed to break down the more complex operations into simple steps that it can perform. Therefore, any computer can be programmed to perform any arithmetic operation—although it will take more time to do so if its ALU does not directly support the operation. An ALU may also compare numbers and return boolean truth values (true or false) depending on whether one is equal to, greater than or less than the other ("is 64 greater than 65?").
Logic operations involve boolean logic: AND, OR, XOR and NOT. These can be useful both for creating complicated conditional statements and processing boolean logic.
Superscalar computers contain multiple ALUs so that they can process several instructions at the same time. Graphics processors and computers with SIMD and MIMD features often provide ALUs that can perform arithmetic on vectors and matrices.
Memory
Main article: Computer storage
Magnetic core memory was popular main memory for computers through the 1960s until it was completely replaced by semiconductor memory.A computer's memory can be viewed as a list of cells into which numbers can be placed or read. Each cell has a numbered "address" and can store a single number. The computer can be instructed to "put the number 123 into the cell numbered 1357" or to "add the number that is in cell 1357 to the number that is in cell 2468 and put the answer into cell 1595". The information stored in memory may represent practically anything. Letters, numbers, even computer instructions can be placed into memory with equal ease. Since the CPU does not differentiate between different types of information, it is up to the software to give significance to what the memory sees as nothing but a series of numbers.
In almost all modern computers, each memory cell is set up to store binary numbers in groups of eight bits (called a byte). Each byte is able to represent 256 different numbers; either from 0 to 255 or -128 to +127. To store larger numbers, several consecutive bytes may be used (typically, two, four or eight). When negative numbers are required, they are usually stored in two's complement notation. Other arrangements are possible, but are usually not seen outside of specialized applications or historical contexts. A computer can store any kind of information in memory as long as it can be somehow represented in numerical form. Modern computers have billions or even trillions of bytes of memory.
The CPU contains a special set of memory cells called registers that can be read and written to much more rapidly than the main memory area. There are typically between two and one hundred registers depending on the type of CPU. Registers are used for the most frequently needed data items to avoid having to access main memory every time data is needed. Since data is constantly being worked on, reducing the need to access main memory (which is often slow compared to the ALU and control units) greatly increases the computer's speed.
Computer main memory comes in two principal varieties: random access memory or RAM and read-only memory or ROM. RAM can be read and written to anytime the CPU commands it, but ROM is pre-loaded with data and software that never changes, so the CPU can only read from it. ROM is typically used to store the computer's initial start-up instructions. In general, the contents of RAM is erased when the power to the computer is turned off while ROM retains its data indefinitely. In a PC, the ROM contains a specialized program called the BIOS that orchestrates loading the computer's operating system from the hard disk drive into RAM whenever the computer is turned on or reset. In embedded computers, which frequently do not have disk drives, all of the software required to perform the task may be stored in ROM. Software that is stored in ROM is often called firmware because it is notionally more like hardware than software. Flash memory blurs the distinction between ROM and RAM by retaining data when turned off but being rewritable like RAM. However, flash memory is typically much slower than conventional ROM and RAM so its use is restricted to applications where high speeds are not required. [12]
In more sophisticated computers there may be one or more RAM cache memories which are slower than registers but faster than main memory. Generally computers with this sort of cache are designed to move frequently needed data into the cache automatically, often without the need for any intervention on the programmer's part.
Input/output (I/O)
Main article: Input/output
Hard disks are common I/O devices used with computers.I/O is the means by which a computer receives information from the outside world and sends results back. Devices that provide input or output to the computer are called peripherals. On a typical personal computer, peripherals include inputs like the keyboard and mouse, and outputs such as the display and printer. Hard disks, floppy disks and optical discs serve as both inputs and outputs. Computer networking is another form of I/O.
Practically any device that can be made to interface digitally may be used as I/O. The computer in the Engine Control Unit of a modern automobile might read the position of the pedals and steering wheel, the output of the oxygen sensor and devices that monitor the speed of each wheel. The output devices include the various lights and gauges that the driver sees as well as the engine controls such as the spark ignition circuits and fuel injection systems. In a digital wristwatch, the computer reads the buttons and causes numbers and symbols to be shown on the liquid crystal display.
Often, I/O devices are complex computers in their own right with their own CPU and memory. A graphics processing unit might contain fifty or more tiny computers that perform the calculations necessary to display 3D graphics. Modern desktop computers contain many smaller computers that assist the main CPU in performing I/O.
Multitasking
Main article: Computer multitasking
While a computer may be viewed as running one gigantic program stored in its main memory, in some systems it is necessary to give the appearance of running several programs simultaneously. This is achieved by having the computer switch rapidly between running each program in turn. One means by which this is done is with a special signal called an interrupt which can periodically cause the computer to stop executing instructions where it was and do something else instead. By remembering where it was executing prior to the interrupt, the computer can return to that task later. If several programs are running "at the same time", then the interrupt generator might be causing several hundred interrupts per second, causing a program switch each time. Since modern computers typically execute instructions several orders of magnitude faster than human perception, it may appear that many programs are running at the same time even though only one is ever executing in any given instant. This method of multitasking is sometimes termed "time-sharing" since each program is allocated a "slice" of time in turn.
Before the era of cheap computers, the principle use for multitasking was to allow many people to share the same computer.
Seemingly, multitasking would cause a computer that is switching between several programs to run more slowly - in direct proportion to the number of programs it is running. However, most programs spend much of their time waiting for slow input/output devices to complete their tasks. If a program is waiting for the user to click on the mouse or press a key on the keyboard, then it will not take a "time slice" until the event it is waiting for has occurred. This frees up time for other programs to execute so that many programs may be run at the same time without unacceptable speed loss.
Multiprocessing
Main article: Multiprocessing
Cray designed many supercomputers that used multiprocessing heavily.Some computers may divide their work between one or more separate CPUs, creating a multiprocessing configuration. Traditionally, this technique was utilized only in large and powerful computers such as supercomputers, mainframe computers and servers. However, multiprocessor and multi-core (multiple CPUs on a single integrated circuit) personal and laptop computers have become widely available and are beginning to see increased usage in lower-end markets as a result.
Supercomputers in particular often have highly unique architectures that differ significantly from the basic stored-program architecture and from general purpose computers.[13] They often feature thousands of CPUs, customized high-speed interconnects, and specialized computing hardware. Such designs tend to be useful only for specialized tasks due to the large scale of program organization required to successfully utilize most of a the available resources at once. Supercomputers usually see usage in large-scale simulation, graphics rendering, and cryptography applications, as well as with other so-called "embarrassingly parallel" tasks.
Networking and the Internet
Main articles: Computer networking and Internet
Visualization of a portion of the routes on the Internet.Computers have been used to coordinate information in multiple locations since the 1950s, with the US military's SAGE system the first large-scale example of such a system, which led to a number of special-purpose commercial systems like Sabre.
In the 1970s, computer engineers at research institutions throughout the US began to link their computers together using telecommunications technology. This effort was funded by ARPA (now DARPA), and the computer network that it produced was called the ARPANET. The technologies that made the Arpanet possible spread and evolved. In time, the network spread beyond academic and military institutions and became known as the Internet. The emergence of networking involved a redefinition of the nature and boundaries of the computer. Computer operating systems and applications were modified to include the ability to define and access the resources of other computers on the network, such as peripheral devices, stored information, and the like, as extensions of the resources of an individual computer. Initially these facilities were available primarily to people working in high-tech environments, but in the 1990s the spread of applications like e-mail and the World Wide Web, combined with the development of cheap, fast networking technologies like Ethernet and ADSL saw computer networking become almost ubiquitous. In fact, the number of computers that are networked is growing phenomenally. A very large proportion of personal computers regularly connect to the Internet to communicate and receive information. "Wireless" networking, often utilizing mobile phone networks, has meant networking is becoming increasingly ubiquitous even in mobile computing environments.
Further topics
Hardware
The term hardware covers all of those parts of a computer that are tangible objects. Circuits, displays, power supplies, cables, keyboards, printers and mice are all hardware.
History of computing hardware First Generation (Mechanical/Electromechanical) Calculators Antikythera mechanism, Difference Engine, Norden bombsight
Programmable Devices Jacquard loom, Analytical Engine, Harvard Mark I, Z3
Second Generation (Vacuum Tubes) Calculators Atanasoff-Berry Computer
Programmable Devices ENIAC, EDSAC, EDVAC, UNIVAC I
Third Generation (Discrete transistors and SSI, MSI, LSI Integrated circuits) Mainframes System/360, BUNCH
Minicomputer PDP-8, PDP-11, System/32, System/36
Fourth Generation (VLSI integrated circuits) Minicomputer VAX, AS/400
4-bit microcomputer Intel 4004, Intel 4040
8-bit microcomputer Intel 8008, Intel 8080, Motorola 6800, Motorola 6809, MOS Technology 6502, Zilog Z80
16-bit microcomputer 8088, Zilog Z8000, WDC 65816/65802
32-bit microcomputer 80386, Pentium, 68000, ARM architecture
64-bit microcomputer [14] x86-64, PowerPC, MIPS, SPARC
Embedded computer 8048, 8051
Personal computer Desktop computer, Home computer, Laptop computer, Personal digital assistant (PDA), Portable computer, Tablet computer, Wearable computer
Server class computer
Theoretical/experimental Quantum computer
Chemical computer
DNA computing
Optical computer
Other Hardware Topics Peripheral device (Input/output) Input Mouse, Keyboard, Joystick, Image scanner
Output Monitor, Printer
Both Floppy disk drive, Hard disk, Optical disc drive, Teleprinter
Computer busses Short range RS-232, SCSI, PCI, USB
Long range (Computer networking) Ethernet, ATM, FDDI
Software
Software refers to parts of the computer that have no material form; programs, data, protocols, etc are all software. When software is stored in hardware that cannot easily be modified (such as BIOS ROM in an IBM PC compatible), it is sometimes termed firmware to indicate that it falls into an area of uncertainty between hardware and software.
Computer software Operating system Unix/BSD UNIX System V, AIX, HP-UX, Solaris (SunOS), FreeBSD, NetBSD, IRIX
GNU/Linux List of Linux distributions, Comparison of Linux distributions
Microsoft Windows Windows 9x, Windows NT, Windows CE
DOS QDOS, PC-DOS, MS-DOS, FreeDOS
Mac OS Mac OS classic, Mac OS X
Embedded and real-time List of embedded operating systems
Experimental Amoeba, Oberon/Bluebottle, Plan 9 from Bell Labs
Library Multimedia DirectX, OpenGL, OpenAL
Programming library C standard library, Standard template library
Data Protocol TCP/IP, Kermit, FTP, HTTP, SMTP
File format HTML, XML, JPEG, MPEG, PNG
User interface Graphical user interface (WIMP) Microsoft Windows, GNOME, QNX Photon, CDE, GEM
Text user interface Command line interface, shells
Other
Application Office suite Word processing, Desktop publishing, Presentation program, Database management system, Scheduling & Time management, Spreadsheet, Accounting software
Internet Access Browser, E-mail client, Web server, Mail transfer agent, Instant messaging
Design and manufacturing Computer-aided design, Computer-aided manufacturing, Plant management, Robotic manufacturing, Supply chain management
Graphics Raster graphics editor, Vector graphics editor, 3D modeler, Animation editor, 3D computer graphics, Video editing, Image processing
Audio Digital audio editor, Audio playback, Mixing, Audio synthesis, Computer music
Software Engineering Compiler, Assembler, Interpreter, Debugger, Text Editor, Integrated development environment, Performance analysis, Revision control, Software configuration management
Educational Edutainment, Educational game, Serious game, Flight simulator
Games Strategy, Arcade, Puzzle, Simulation, First-person shooter, Platform, Massively multiplayer, Interactive fiction
Misc Artificial intelligence, Antivirus software, Malware scanner, Installer/Package management systems, File manager
Programming languages
Programming languages provide various ways of specifying programs for computers to run. Unlike natural languages, programming languages are designed to permit no ambiguity and to be concise. They are purely written languages and are often difficult to read aloud. They are generally either translated into machine language by a compiler or an assembler before being run, or translated directly at run time by an interpreter. Sometimes programs are executed by a hybrid method of the two techniques. There are thousands of different programming languages—some intended to be general purpose, others useful only for highly specialized applications.
Programming Languages Lists of programming languages Timeline of programming languages, Categorical list of programming languages, Generational list of programming languages, Alphabetical list of programming languages, Non-English-based programming languages
Commonly used Assembly languages ARM, MIPS, x86
Commonly used High level languages BASIC, C, C++, C#, COBOL, Fortran, Java, Lisp, Pascal
Commonly used Scripting languages JavaScript, Python, Ruby, PHP, Perl
Professions and organizations
As the use of computers has spread throughout society, there are an increasing number of careers involving computers. Following the theme of hardware, software and firmware, the brains of people who work in the industry are sometimes known irreverently as wetware or "meatware".
Computer-related professions Hardware-related Electrical engineering, Electronics engineering, Computer engineering, Telecommunications engineering, Optical engineering, Nanoscale engineering
Software-related Human-computer interaction, Information technology, Software engineering, Scientific computing, Web design, Desktop publishing, Sound recording and reproduction
The need for computers to work well together and to be able to exchange information has spawned the need for many standards organizations, clubs and societies of both a formal and informal nature.
Organizations Standards groups ANSI, IEC, IEEE, IETF, ISO, W3C
Professional Societies ACM, ACM Special Interest Groups, IET, IFIP
Free/Open source software groups Free Software Foundation, Mozilla Foundation, Apache Software Foundation
See also
Look up Computer in
Wiktionary, the free dictionary.Wikiquote has a collection of quotations related to:
ComputersWikimedia Commons has media related to:
ComputerComputability theory
Computer science
Computing
Computers in fiction
Computer security and Computer insecurity
List of computer term etymologies
Virtualization
Notes
^ In 1946, ENIAC consumed an estimated 174 kW. By comparison, a typical personal computer may use around 400 W; over four hundred times less. (Kempf 1961)
^ The Analytical Engine should not be confused with Babbage's difference engine which was a non-programmable mechanical calculator.
^ This program was designed for the PDP-11 minicomputer and shows some typical things a computer can do. All the text after the semicolons are comments for the benefit of human readers. These have no significance to the computer and are ignored. (Digital Equipment Corporation 1972)
^ Attempts are often made to create programs that can overcome this fundamental limitation of computers. Software that mimics learning and adaptation is part of artificial intelligence.
^ It is not universally true that bugs are solely due to programmer oversight. Computer hardware may fail or may itself have a fundamental problem that produces unexpected results in certain situations. For instance, the Pentium FDIV bug caused some Intel microprocessors in the early 1990s to produce inaccurate results for certain floating point division operations. This was caused by a flaw in the microprocessor design and resulted in a partial recall of the affected devices.
^ Even some later computers were commonly programmed directly in machine code. Some minicomputers like the DEC PDP-8 could be programmed directly from a panel of switches. However, this method was usually used only as part of the booting process. Most modern computers boot entirely automatically by reading a boot program from some non-volatile memory.
^ However, there is sometimes some form of machine language compatibility between different computers. An x86-64 compatible microprocessor like the AMD Athlon 64 is able to run most of the same programs that an Intel Core 2 microprocessor can, as well as programs designed for earlier microprocessors like the Intel Pentiums and Intel 80486. This contrasts with very early commercial computers, which were often one-of-a-kind and totally incompatible with other computers.
^ High level languages are also often interpreted rather than compiled. Interpreted languages are translated into machine code on the fly by another program called an interpreter.
^ Although this is a simple program, it contains a software bug. If the traffic signal is showing red when someone switches the "flash red" switch, it will cycle through green once more before starting to flash red as instructed. This bug is quite easy to fix by changing the program to repeatedly test the switch throughout each "wait" period—but writing large programs that have no bugs is exceedingly difficult.
^ The control unit's rule in interpreting instructions has varied somewhat in the past. While the control unit is solely responsible for instruction interpretation in most modern computers, this is not always the case. Many computers include some instructions that may only be partially interpreted by the control system and partially interpreted by another device. This is especially the case with specialized computing hardware that may be partially self-contained. For example, EDVAC, the first modern stored program computer to be designed, used a central control unit that only interpreted four instructions. All of the arithmetic-related instructions were passed on to its arithmetic unit and further decoded there.
^ Instructions often occupy more than one memory address, so the program counters usually increases by the number of memory locations required to store one instruction.
^ Flash memory also may only be rewritten a limited number of times before wearing out, making it less useful for heavy random access usage. (Verma 1988)
^ However, it is also very common to construct supercomputers out of many pieces of cheap commodity hardware; usually individual computers connected by networks. These so-called computer clusters can often provide supercomputer performance at a much lower cost than customized designs. While custom architectures are still used for most of the most powerful supercomputers, there has been a proliferation of cluster computers in recent years. (TOP500 2006)
^ Most major 64-bit instruction set architectures are extensions of earlier designs. All of the architectures listed in this table existed in 32-bit forms before their 64-bit incarnations were introduced.
References
a Kempf, Karl (1961). "Historical Monograph: Electronic Computers Within the Ordnance Corps". Aberdeen Proving Ground (United States Army).
a Phillips, Tony (2000). The Antikythera Mechanism I. American Mathematical Society. Retrieved on 2006-04-05.
a Shannon, Claude Elwood (1940). "A symbolic analysis of relay and switching circuits". Massachusetts Institute of Technology.
a Digital Equipment Corporation (1972). PDP-11/40 Processor Handbook (PDF), Maynard, MA: Digital Equipment Corporation.
a Verma, G.; Mielke, N. (1988). "Reliability performance of ETOX based flash memories". IEEE International Reliability Physics Symposium.
a Meuer, Hans; Strohmaier, Erich; Simon, Horst; Dongarra, Jack (2006-11-13). Architectures Share Over Time. TOP500. Retrieved on 2006-11-27.
Stokes, Jon (2007). Inside the Machine: An Illustrated Introduction to Microprocessors and Computer Architecture. San Francisco: No Starch Press. ISBN 978-1-59327-104-6.
Retrieved from "http://en.wikipedia.org/wiki/Computer"
Categories: Semi-protected | Computing
Subscribe to:
Posts (Atom)





















