How Can We Help?
< All Topics
Print

Programming Vocabulary

Object-Oriented Program – code written in terms of objects (real or conceptual) described using data and instructions. 

The various parts and actions of the robot are represented by objects in the Java code.

Java – programming language developed in mid 1990’s that can be written and run in different environments (Mac/Win/Unix) using an object-oriented methodology. 

We write our robotics code in Java on Windows, but run it on the robot’s Linux mini-computer (RoboRIO).

Memory – sets of electronics that use high and low voltage levels to represent addressable pieces of information

Statement  – A line of text that contains an instruction to the computer. In Java, these always end with a semicolon (;)

Comment – A line of text starting with // or enclosed by /* */ that only describes the code to the programmer

Variable – a named or labeled portion of the addressed memory used to store data of various types, including booleans,

whole and rational numbers, characters and strings of characters, as well as more complex objects.

Five Basic Operations  – there are only 5 things a computer can do, everything else is a combination of these five things

Get Data From Memory – this can be from internal memory, the hard drive, a network, an input device, etc…

Store Data in Memory – again, this could be output to a screen, network, or a file, not just internal memory

Operations on Data – Mathematical operations mostly, but there are a few others

Compare Data – This allows the computer to make decisions based on the information in memory

Change Order of Instructions – Skip ahead, go back and repeat or change to another set of instructions.

Assignment – Data is associated with variables by declaring the variable to be equal to the data value.

TypeOfData nameOfVariable = “data value”; // This is an assignment statement

Boolean – a variable type that can be in one of two states, true or false. This is the simplest data in memory.

Boolean trueOrFalse = true; 

// Boolean is the type, trueOrFalse is the variable’s name and true is the data.

Bits/Bytes – Booleans are also called bits and 8 of them make a byte which can represent 256 numbers.

011001002 = (0 x 27) + (1 x 26) + (1 x 25) + (0 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (0 x 20) = 10010

You use base-2 numbers because you have two states for each bit.

Integer – a variable type that holds a single whole number such as (-2, -1, 0, 1, 2, 3, 4, 5…)

int myNumber = 10; // Type is int, variable is myNumber and 10 is the data.

long largerNumber = 987654321; // Long integers store numbers greater than 32767

Floating Point – the variable type of rational numbers (1.01, 0.54, …) called either float or double.

float pi = 3.1416; // Type is float, variable is pi and 3.14… is the data

double PI = 3.141592654; // Type is double, variable is PI, data is more precise.

Character – (char) any of the symbols used in writing which are represented by a number in computer memory

char letter = ‘a’; // Type is char, variable is letter, ‘a’ is data – notice quotes

String – A set of characters in double-quotes that can be arbitrarily long and hold a single word to an entire book.

String word = “bird”; // Type is String, variable is word, “bird” is data

Void – The type of nothingness. Void is just a way of indicating that nothing IS expected.

Null – The value of nothingness. Zero is a number which is a type, so there needs to be a value to represent nothing. Sometimes null is used when the value of another type is unavailable. Null is often problematic!

String nothingString = null; // No string specified, so use null instead.

Array – A variable that addresses several of the same things that are side-by-side in memory. A String is an array. Arrays use an index to access the elements inside by multiplying the index by the size of the type and then adding that to the address of the first element. The first element is at the beginning of the array so its index is 0. Square brackets are used to indicate a variable is an array of something and curly braces are used for elements.

int[] myIntegerArray = {0, 1, 2, 3}; // Array of 4 integers

double[] myRationalArray = new double[10]; // Empty array of 10 null doubles

myRationalArray[0] = 0.01; // Set the first (at index 0) element to 0.01. 

Function – A set of instructions for manipulating and changing the data in variables. Starts with a variable type that will be result of the function’s calculations, followed by the name and input parameters within parentheses. Functions do not have to have a result type and instead can be type void. Curly-braces enclose the function’s instructions.

int myAddingFunction(int secondNumber)

int resultNumber = 10 + secondNumber; 

return resultNumber; // the ‘return type’ is int and so is resultNumber

}

void myFunctionThatDoesNothing() { /* this does nothing and has no result */ }

Parameters – Variables that are supplied in the beginning of a function as input data. Also called ‘arguments’.

Class – a group of variables and functions that together describe a distinctly identifiable concept as an object. A class can have data and functions that are singular or have multiple instances or have some mixture of both. 

class MyRobot { int myVariable; void myFunction() {} } // simple class example

class MyMathClass {

public static String resultMessage;

private int firstNumber = 10;

private int myAddingFunction(int secondNumber)

int resultNumber = firstNumber + secondNumber; 

resultMessage = firstNumber + “ plus ” + secondNumber + “ is ” + resultNumber;

return resultNumber; 

}

public String myMultiplyingFunction(int thirdNumber)

int resultNumber2 = firstNumber * thirdNumber; 

resultMessage = firstNumber +“ times ”+ thirdNumber +“ is ”+ resultNumber2;

return resultMessage; 

}

}

Scope – The context in which a class, function or variable is in existence for use by the program. There are several scopes in a typical program, such as static (global), class (member) and function (local). Curly braces {} are used to define a scope as well as some keywords.

In the MyMathClass example, resultMessage is a static global variable, the firstNumber variable and the functions are class members and the others are local variables that only exist inside the functions.

Visibility – The context in which a class, function or variable is accessible for use such as public or private visibility. Visibility is usually applied to functions and variables in a class as well as to the class itself.

In the MyMathClass example, the multiplying function and resultMessage are public (visible outside of the class) but the other members are private and only visible within the class. This is important when using multiple classes that interchange data and execute each other’s functions.

Static Scope – The scope of the function or variable that makes it always available as part of the class. This is also sometimes referred to as a global scope. The keyword ‘static’ is used to designate variables or functions that you always want available because it is not specific to a particular instance of a class.

public static void main(String[] args) {

MyMathClass.resultMessage = “Hi”; // Can do this b/c resultMessage is public static

}

Notice that the ‘.’ is used when referring to a function or variable within a class.

Main function – The first function that is executed in any Java program. It has to be part of some class as a static function that has a void result type. Sometimes it has parameters, but they are optional. See example above. Any class can have one, but only one is used so you can have multiple ways of running your code if you want.

Member or Class Scope – A variable or function that exists within the class and is only available when there is an allocated instance of the class in memory. In MyMathClass, firstNumber is a member variable and the functions are member functions.

public static void main(String[] args) {

MyMathClass.myMultiplyingFunction(11); //This won’t work…why? Not static.

}

Local Scope – A variable that only exists for the scope of a single function, as opposed to the variables that are created as part of a class instance, or at the global scope, which still exist when the function finishes.

In the above example, myAddingFunction, secondNumber and resultNumber are local to the function and stop existing when it finishes. In myMultiplyingFunction,thirdNumber and resultNumber2 are local variables. MyMathClass.resultMessage is not local and doesn’t stop existing until the entire program ends.

Allocated Instance – A variable referencing a portion of the computer’s memory used to store data in the manner described by the class so that it can be treated separately from other instances of the same class.

public static void main() {

MyMathClass doMath = new MyMathClass(); // allocating an instance

MyMathClass doMoreMath = new MyMathClass(); // a separate instance

MyMathClass.firstNumber = 11; // store #11 in the public member variable

String result = doMath.myMultiplyingFunction(12);

// Called function with number 12 and got the output string in result.

System.out(result); // This would print the result to the screen

}

This – the keyword ‘this’ can be used inside of a member function to refer to the current allocated instance. It is not valid to use it inside a static function because they are not part of a class instance. See next example.

Constructor – Special class member function that is used to create an instance of a class in memory. Constructors never have an output type because the class instance is the output. They are also always the same name as the class. They can have parameters that are used to set the initial data in the class member variables. There is a default constructor with no parameters even if you don’t write one.

class MyMathClass {

private int firstNumber; // given data in the constructor

public MyMathClass(int firstNumber) {

                this.firstNumber = firstNumber; // ‘this’ means the current instance

} // There are two firstNumber variables, use ‘this’ to differentiate

Conditional Statement – Also known as ‘if-statements’ or ‘if-else’ statements. These allow the program to make a decision about whether other statements are executed or not, based on an expression that evaluates as true or false. If the conditional expression is true, the first scope-block will execute. If there is an else section, the second will execute when it is false. Curly braces {} make the scope blocks and new variables inside them are local to that scope. 

if (firstNumber > 10) { 

firstNumber -= 10; 

} else { 

firstNumber += 10; 

}

Loop  – A set of statements that repeat using a condition to decide whether to keep repeating or stop. There are several types of loop possibilities. For-loops and while loops are the main ones.

while (int number < 10) { // loops 10 times

number = number + 1; // each loop increments number by 1

for (int i = 0; i < 10; i = i + 1) { // put the looping logic in one place

int multiples = i * 3; // multiples changes each time in the loop (0,3,…27)

Super Class – A class that has general data and functions that can be inherited by other classes.

Derived Class – also known as a sub-class, it extends the declaration of a super-class and inherits the super class’s public member functions and variables, but not the private ones.

class MoreMath extends MyMathClass { }

Interface – A class-like structure that doesn’t contain any data, only functions without bodies. Classes implement interfaces so that they can be referenced using the interface as the type. The classes must implement the functions!

interface MathFunctions {

int multiply(int firstNum, int secondNum);

}

class EvenMoreMath extends MyMathClass implements MathFunctions {…}

Lambda – a function written without a name, which can be treated like a variable (stored, passed to another function), which is usually written in-line using this format: (parameters) -> { myCode; }

Method Reference – A way of treating a regular function like a Lambda, using the :: operator.

var method_reference = myClassInstance::myFunction;

High Level Function – A function that takes a function as a parameter. Lambdas are not executed until applied by a high-order function.

Table of Contents