Computer Program
A computer program, or just program, is a sequence of instructions written to perform a specified task with a computer. It is written first in a
programming language, then it may be compiled and then finally the compiled form executed by the computer.
“Hello, World”
“Hello, World” is the name given to a simple
program used to introduce a
programming language. Traditionally this program displays “Hello, World”, but in the case of a device that does not display text, turning on an LED or some alternative is often substituted.
Programming Language
A language designed to communicate instructions to a machine that will be executed. Examples include C, Java, Python. HTML and CSS are NOT programming languages as they only provide structure and form to information and do not describe instructions. Languages vary in
syntax (the form of the language) and
semantics (the meaning). A programming language provides a structured mechanism for defining pieces of data, and the operations or transformations that may be carried out automatically on that data.
Syntax
The form of a program is defined by its syntax. The syntax defines the allowed arrangements of the pieces of a program (letters, numbers, symbols, etc.). For example, the syntax of a US Postal Address can be defined as a Name Part, Street Address, Zip Part. Each of these elements can be further defined. The Zip part can be defined as a Town Name followed by a comma followed by the State Code and a Zip Code. If the order were changed, it would not be a syntactically correct US Postal Address.
Semantics
The meaning of a program is defined by its semantics. A syntactically correct statement may violate the symantics of a language. For example, it is generally required that a variable be defined in a program before it is used. The statement “x=x+1” is syntactically correct, but the semantics are violated if x was not previously defined. The statements “x=0; x=x+1” correct that problem.
Comments
Comments are parts of a program that are intended only for human consumption. They are not passed on to the computer as instructions to execute and serve as
documentation in the program to remind the person writing the program what is happening in a certain area of code or to help somebody understand the code someone else has written.
Primitive
The simplest meaningful element in a program. This means that they have
semantic value, and are different than a “token” which is the minimal element of
syntactic value. These are things such as int (integer values), double/float (decimal values), char (one textual character), etc.
Type
Type is used to define how values and expressions interact within a language. Languages provide the most basic level of types called
primitives, from which all other types are built. For example, in Java, there are primitives called ints that hold integer values and Strings which are a series of chars that hold textual information. In Java, 100 would represent the numerical value one and “100” would represent the textual character value 100. The types of operands in an expression cause different behaviors. For example, in Java, 100 + 100 would result in 200 because there are two numerical values being added together. As expected, “100” + “100” results in “100100”, because two text values are being added (or concatenated) together. 100 + “100” also produces “100100”. It does not make sense to do a mathematical addition of a text value and a numerical one, those types conflict as a text value is not guaranteed to have a text representation. However, a numerical value does have a text represntation so it makes sense to concatenate it to the string. In
Object-Oriented Programming, different classes are treated as different types.
Variable
A variable in a program is a symbolic representation of a value. Much like in math, a variable x can represent any value from a given range. That range is usually limited by the type the variable is defined as. For example, if x is defined as type int in Java then it will be limited to only holding descrete integer values. It cannot hold 2.3 or “car”. If it were defined as a float, however, it could hold 2 or 2.3 or any other number. Variables can also refer to
objects (instances of
classes).
Subroutine
A subroutine is a sequence of program instructions that perform a specific task. This is useful when there are tasks that you want to perform in multiple places within a program, or even in multiple programs. Rather than writing the code in multiple places, you can write a subroutine and then “call” the subroutine where you need it. Subroutines are also called a procedure, function, method, or one of many other names. Subroutines can “return” a piece of information. For example, if you have a subroutine called “square”, to calculate the square of a number, you could give it the number 2 and it would return the value 4.
Object-Oriented Programming (OOP)
Object-Oriented Programming is a programming paradigm that abstracts a situation. It does this by representing things as
objects that have attributes described by
fields and can perform actions (
subroutines) called
methods. And object-oriented program is a collection of objects that interact with each other, rather than strictly a list of tasks.
Object
In programming languages an object is the composition of nouns (
primitives such as numbers or strings and even other objects) and verbs (actions, such as
methods or functions). An object is usually an instance of a
Class, which is a set of rules defining the creation, attributes, and behavior of a type of object.
Class
A Class is a set of rules defining the creation, attributes, and behavior of a type of object. For example, a class called “Car” might define a set of attributes such as “make”, “model”, “year”, “color”, “currentSpeed”, “maxSpeed” and actions such as “start”, “accelerate”, “brake”. An instance of Car called car1 might have make=”Chevy”, model=”Malibu”, and year=1991, while car2 has make=”Ford”, model=”F150”, and year=”1990”. Instances of a Class are distinct, so even though they each contain an identical set of attributes and actions, the values and state are different. That means that you can call accelerate on car1, increasing its “currentSpeed” and car2 will remain unchanged. Classes are instantiated by a special method called a “constructor” that returns an instance of the class.
Field
In
object-oriented programming, a field is a piece of data within a
class and can also be called member
variables. They can be thought of as variables belonging to a class. There are two major types of fields, “regular fields” or “instance variables” and “static fields” or “class variables”. Instance variables belong to each instance of a class. Take the Car Class defined above. Two cars, car1 and car2, each have their own make, model, year, etc. Class variables are the same across all instances of a class. We could expand the Car Class to have a static field called “numberOfWheels” and make that equal to four. Then all cars would have the same value for numberOfWheels.
Method
In object-oriented programming, Methods are
subroutines associated with a class. They define the behavior of a class and have access to the
fields of an object. Take the Car Class defined above. When “accelerate” is called, the action it takes may alter and may depend on the current state of the object as defined by the values in the instances fields. If car1 is an instance of Car and has a currentSpeed of 10, and then accelerate is called, it might increase its speed to 15. Calling accelerate again may raise it to 20. However, if the maxSpeed is 15, the second call to accelerate wouldn’t do anything.
Argument
Also called parameters, arguments are values that are passed in to a
subroutine or
method. Arguments are defined as having a certain
type and given variable names that can be used within that subroutine. Take the Car class defined above. The method accelerate could be defined to have two arguments, “delta” and “time”. The delta could refer to the amount in miles per hour by which you want to accelerate and time could be the amount of time in seconds this acceleration should take. A call to accelerate on car1 in Java might then look like car1.accelerate(5, 10), telling car1 to accelerate by 5 miles per hour over 10 seconds.
Source Code
Source code defines a
computer program in human-readable language. It is generally what a programmer writes to make a program using a
Text Editor or an
IDE. It is then translated into a form that the computer can read to be executed. Source code files may have a file extension specific to the language they wrote it in. For example, Java files end in .java, C files end in .c or .h, and C++ files end in .cpp.
Text Editor
A text editor is a program that is used to edit plain text files, including
source code. Plain text consists of a series of characters, symbols, spaces, newlines, and tabs without text formatting such as bolding, fonts, columnts, etc. Text Editors may have features such as language specific syntax highlighting (where different syntactic elements are highlighted in different colors), formatting help, and various editing features to facilitate the writing of programs, they do not have the advanced features of
IDE’s. Examples are notepad,
Notepad++, and
Sublime Text 2.
IDE
IDE stands for Integrated Development Environment and describes a comprehensive application that facilitates computer programming. It generally includes a
text editor, a tool to help “build” a software project into an executable state, and a
debugger to help the programmer find and fix errors in their program. Other features an IDE may have include tools to build a graphical user interface and a version control system to help programmers keep track of changes made to the software. IDE’s tend to be made for specific programming languages or language families. For example,
Eclipse is mostly used for Java development and
Visual Studio is mostly used for programming in languages from the C-language family.
Library
A library is a collection of behavior implemented in a particular language with a well-defined interface for invoking that behavior with the purpose of allowing the library to be reused by multiple independent programs. This usually means it is a collection of files that a programmer can include with their own and then use. In the case of Java, this means a user could instantiate
objects or call
methods defined by classes in a library. Java provides a standard library that users can use to do things like create a list of objects or print text out to the screen rather than making them create that object or behavior themselves.
Documentation
Documentation is written text that accompanies software that explains how the software works or how to use it. This can come in several different forms. Documentation can be included in the software in the form of
comments. Documentation can also be provided outside of the source code in public documentation that explains a set of rules of how to use it. Java has excellent documentation that you can find here, and this is an example of documentation for the String class. It explains what the methods of the class do, what their arguments are, and what the return values of the method are.
Debug
Debugging a program or segment of code is a methodical process for finding and reducing bugs (defects).
IDE’s generally come with a debugging tool that helps users step through the execution of a program one instruction at a time while monitoring the values of variables and the state of objects to track down errors.