Programming terms

From Juneday education
Jump to: navigation, search

About

Here, we've collected a number of programming terms.

ascii

ASCII (American Standard Code for Information Interchange) is a standard for encoding charcaters. When we store the letter "a" in a file it's quite useful if a program reading the file also treats the stored data as an "a". To make sure we store/read data the same was we use an encoding standard.

Note: there are other standards, e g UTF-8

See also our term page for ASCII Table

API

Application programming interface. See: Term page for API.

binary file

A file consisting of all possible characters. Examples of binary files are: ogg and mp3 audio, mp4 video, java bytecode, object file

byte code

Machine code is a format that the computer's CPU can understand directly. Bytecode (byte code) on the other hand is designed to be executed by an interpreter who reads the bytecode and transforms it into instructions that it executes on the CPU. Examples of bytecode are: Java bytecode.

Java bytecode is the code with the instructions for the Java virtual machine. The instructions in the bytecode are interpreted by the JVM during execution. The byte code is stored in the .class files created by the javac compiler. See above for more information on the Java virtual machine.

Wikipedia has more information about Java_bytecode.

CLI - Command-line Interface

The user of a computer needs an interface to interact with the computer. Nowadays most personal computers use a graphical user interface (CUI) but most computers also come with a text-based interface, where commands are entered one line at the time (CLI, command line interface).

The CLI has many names and is also called "command line user interface", "the console", "the terminal" or "the shell". The CLI consists of some kind of program for screen and keyboard interaction (a terminal or a console), and a program which acts on the command lines entered by the users. The latter is called "a command line interpreter" or "a shell". The shell blocks (waits) until the user has entered some text and presses Enter, and then tries to understand the command and execute them and possibly respond with some output.

Some examples of shells are bash (Cygwin, GNU, Unix) and PowerShell (Microsoft). The courses on this wiki are focused around the bash shell.

Read more here: Command-line_interface (wikipedia).

compiler

A program that transforms (or transform) software written in one programming language to another programming language. It will take an entire course to give you enough information about compilers and how to write them but in our courses this will do fine.

Examples of compilers are Java Compiler which translates from Java source code to Java byte code (to be executed by the Virtual Machine) and C Compiler which translates from C source code to machine code.

Expand using link to the right to see an example of compilation of a C program.

C compilation

Let's give an example in C. Here's the source of a file called hello.c:

#include <stdio.h>

int main(void)
{
  printf("Hello world\n");
  
  return 0;
}

Source code can be found at github: hello.c (download with curl: curl -O https://raw.githubusercontent.com/progund/junedaywiki/master/compiler/hello.c).

To compile the file above you type the following:

$ gcc hello.c -o hello

Now we have transformed hello.c (yet kept the original) into a program called hello.

To execute the program (as result from compiling hello.c you can type the following:

$ ./hello
Hello world

If we want to check the file type we can do the following:

$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=59c0391f9cb05af1e15cf6f96db55b6bf141ad8b, not stripped

Note: the printout from file is from the author's laptop running GNU/Linux. The printout may differ on your computer.

Expand using link to the right to see an example of compilation of a Java program.

Java compilation

Let's give an example in Java. Here's the source of a file called Hello.java:

public class Hello {

  public static void main(String[] args) {
    System.out.println("Hello world");
  }

}

Source code can be found at github: Hello.java (download with curl: curl -O https://raw.githubusercontent.com/progund/junedaywiki/master/compiler/Hello.java).

To compile the file above you type the following:

$ javac Hello.java

Now we have transformed Hello.java (yet kept the original) into a file called Hello.class.

To execute the program (as result from compiling Hello.java you can type the following:

$ java Hello 
Hello world

If we want to check the file type we can do the following:

$ file Hello.class 
Hello.class: compiled Java class data, version 52.0 (Java 1.8)

Note: the printout from file is from the author's laptop running GNU/Linux. The printout may differ on your computer.

default (value)

Java

An instance variable (in Java) gets a default value. Default value is a value that is preset. In the following code:

public class Member {
  String name;
  // ....
}

each Member object created has a name (instance) variable which gets assigned to null, since null is the default value for reference variables in Java.

Read more at wikipedia: Default (computer_science)

EOF - End Of File

A code saying that there is no more input. This is useful when reading data from an input source (e g network or file).

GUI - Graphical User Interface

When interacting with the operating system on a computer using the screen, mouse and keyboard, a graphical user interface is used. Typically a graphical user interface consists of windows, menus, buttons, and text input components like textfields and textareas.

Most programs you have used probably have a GUI, perhaps like the browser you are using to view this page. See also CLI - Command line user interface above, for reference.

Read more: Graphical_user_interface (wikipedia) .

HOME directory

Each normal user in a multi-user operating system typically has a specific directory which is their own. In this directory the user can store personal files like documents, media, video, photos etc. This directory is also typically the directory your shell with "start with" if you open up a terminal with a shell.

Having different home directories for each user let's programs store information which is private to the user running the program. Programs typically find the user's home directory using an environment variable called HOME.

Read more: Wikipedia link .

initialize

This is a common word in programming and refers to the first assignment of a variable.

Example of an assignment of an int (primitive type) in Java:

   int count = 0;  // declaration and (first) assignment, i e we initialize count to 0
   count = 13;     // assignment, so this is not an initialization

Example of an assignment of a Person object in Java:

   Person p = new Person("Ross", "Nobles");  // declaration and (first) assignment, i e we initialize p 
   Person q;                                 // declaration of q, a reference variable of type Person 
   q = new Person("Rich", "Fulcher");        // (first) assignment, i e we initialize q to a value

More info at wikipedia: Initialization (programming)

interactive program

An interactive program is a program which starts and waits for user input or actions.

Interpreter

A program that reads files with software written not directly compiled for the computer's CPU. The files read can be text files (e.g shell script) or bytecode compiled files. The interpreter also directly executes the software on the computer's CPU.

Examples of interpreters are: Java Virtual Machine, bash, python.


Java

Java is both a programming language and a software platform. Read more.

Log / Logging

Recording data/events to a log file, rather than printing messages to stdout, is as an example done to make it possible to analyse a program after it has been executed. This is useful to find bugs or to improve performance. A log file can also be a recorded session, i e a chat session.

Example printout from the Apache web server running this site:

129.16.219.142 - - [22/Oct/2017:15:44:25 +0200] "GET /mediawiki/load.php?debug=false&lang=en&modules=startup&only=scripts&skin=vector HTTP/1.1" 304 - "http://wiki.juneday.se/mediawiki/index.php/Main_Page" "Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.84 Safari/537.36"
90.229.156.209 - - [22/Oct/2017:15:44:31 +0200] "GET /mediawiki/index.php/Expressions_and_operators HTTP/1.1" 200 35807 "http://wiki.juneday.se/mediawiki/index.php?search=parameter&title=Special%3ASearch&go=Go" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36"

Read more at wikipedia: Log file

machine code

Machine code is the language that the computer's CPU understands and can execute. The machine code (language) is a set of instructions. The instructions differs from one CPU brand to another so software compiled for one CPU will most likely not be possible to execute on another machine (without recompiling the source code for the target platform).

You can read more here: Wikipedia on machine code.

method

In Java, a method is a named block of code. This is sometimes (mostly in other languages) called a function, a procedure or a subroutine. In Java, there are basically two types of methods; instance methods (which is the default type) which can only be called on an object (via some reference to the object) and static methods (sometimes called class methods) which can be called without any objects. Static methods are declared using the keyword static and can be said to belong to the class and not any instances of the class. Static methods cannot use any instance methods, because they don't have any reference to any specific instance of the class they belong to.

method signature

In Java, the signature of a method consists of the name of the method and the arguments list. The signature is used by Java to resolve which method to run when a method is invoked by some code. Methods can be overloaded which means that methods can be declared with the same name but with different argument lists.

It is not allowed in Java to define two methods with the same name and arguments list but different return type, because it would be impossible for Java to resolve which method is being called. This is one of the reasons why return type is not part of the method signature.

newline

A special character used to signify that the text shall continue at the next line. Programs such as editors automatically inserts a newline when you press enter. In the ascii table newline has number 18 (decimal system). If you want to print a newline using printf in a programming language you normally write "\n".

null

null (or NULL or nil) is a value to indicate that the reference (Java) or pointer (C) does not refer to a valid object (Java) or variable (C).

Read more at wikipedia: Null pointer

object, instance, instance variable, instance metod

An object in Java is sometimes also called an instance (of some class). For instance (no pun intended), the following creates an instance of the class ArrayList (for storing in this case String references) and an instance of the class StringBuilder:

ArrayList<String> shoppingList = new ArrayList<>(); // shoppingList now refers to a new ArrayList<String>
StringBuilder sb = new StringBuilder(); // sb now refers to a new StringBuilder

The class of an object (or instance - they are synonyms) defines what variables every instance of the class (should someone create a new instance) has, as well as what instance methods every instance of the class has (i.e. what every such instance can "do").

An instance variable is a variable that every instance of some class will have its own copy of. An instance method is a method which every instance of a class can be asked to execute. In order to invoke (call) an instance method, we need to have a reference to the instance we want to call the method for.

If we have a reference to an instance of an ArrayList<String>, as shown above, called shoppingList, we can call the instance method add(String) on that instance.

Since we can have many instances of a class, like five different ArrayList<String>, we need to specify which instance we want to add a String to. It would make no sense to say ArrayList.add("apa");, since Java would have no way to understand what instance of ArrayList we want to add the String to!

When we add an element to an ArrayList, the list stores the element in some instance variable (probably an array variable). So every instance of ArrayList will have its own private instance variable to store elements in. And every instance of ArrayList will have its own instance method add (which we use to add elements to the list).

So, if I want to add an item to the shoppingList variable, I need to have a reference to exactly that instance, and via the reference call the instance method add("some string"):

ArrayList<String> shoppingList = new ArrayList<>(); // shoppingList now refers to a new ArrayList<String>
shoppingList.add("Popular Beer"); // add an item to the shopping list

After doing so, the instance referred to by the reference variable shoppingList, will store the String in its private instance variable (which probably is an array).

So, an object of some class created via the operator new, is also known as "an instance of some class". An object of class ArrayList is also called an instance of ArrayList.

An instance variable is a variable declared in the class the object is an instance of. Every instance will have its own copy of the instance variable. That's why we can call the instance method add(String) via a reference to shoppingList and be confident that exactly that instance will store the String in its private instance variable.

The class StringBuilder is like a String, but we can change the contents of a StringBuilder (unlike the contents of a String, because Strings are "immutable"). The two most common ways to change the contents of a StringBuilder is by appending Strings to the end of the StringBuilder using the append(String) method, and to convert the StringBuilder to a normal String using the famous toString() method. Let's see an example of that:

StringBuilder sb = new StringBuilder();
sb.append("This");
sb.append(" ");
sb.append("a");
sb.append(" ");
sb.append("sentence.");
String sentence = sb.toString();

But the instance method append(String) is more clever than what shows above. The method actually both appends a String to the end of the internal string representation, as well as returns a reference to the same instance! This allows us to actually chain calls to add(String) together like this:

String sentence = new StringBuilder()
 .append("This")
 .append(" ")
 .append("a")
 .append(" ")
 .append("sentence.")
 .toString();
// Do something with the String sentence

The point of that is that we can build a string piece-by-piece and when we're finished, convert the whole shebang to a String. This is more efficient than using Strings and the operator + to concatenate Strings to a new, longer String, since using + creates a lot of temporary String instances on the way, which are thrown away once to full expression is evaluated to a new String.

Internally, a StringBuilder stores the text it represents in some kind of private instance variable. When we ask a StringBuilder to convert itself to a String using the toString() it creates a new String using its private instance variable (which may be an array of char or something else, we don't need to know what).

Calling append on a StringBuilder only makes sense if we tell Java what StringBuilder instance we want to append some text to. This is why the append method is an instance method.