Submitted by James Womack
I will post all of the terminology that you will need to know for a test of programming knowledge. Bolded terminology has a 98% chance of being on the test!
Top three scores will get a small pizza courtesy of me.
Lets get started:
Statement: A line of code that performs an expression(s) proceeded by a semi-colon.
Example: System.out.println("Hello World");
Variable: Variables in java hold data, there are many types of data.
How to construct a variable: Access Modifier type name (= type of data);
Example:
int age = 10;
Basic Variable Types:
- int – A numerical type that holds Whole numbers (Integers hint hint) that can range from a value of -2,147,483,648 to 2,147,483,647
- byte – Like int but can only hold one byte of data (values from -128 to 127)
- short – Like int but can only hold 16 bits of data (Values from -32,768 to 32,767)
- double – A double precision floating number (Decimal)
- float – A single precision floating number (Decimal)
- long – Like int but holds 64 bits of data (ask us for max, its VERY big).
- boolean – A true/false bit.
- char – A single character like ‘a’
If, else , if else statements: If a specified condition is meet, then the code block is executed, else the else code block is executed.
How to construct:
if (condition) {
...
} else {
...
}
Example:
if (age >= 18){
System.out.println(“You are an adult“);
} else {
System.out.println(“You are a minor“);
}
Conditional Operators:
- Greater than is >
- Example: 10 > 12 = false.
- Less than is <
- Greater than or equal to is >=
- Example: 12 >= 12 = true.
- Less than or equal to is <=
- Example: 12 <= 13 = false
- Equal to is == (NOT =)
- Not Equal to is !=
- Or is ||
- Explanation: If one side is true, the whole thing is true
- Example: 12 == 11 || 12 < 13 = true
- And is &&
- Explanation: Only true if both sides are true
- Example: 12 == 10 && 12 > 10 = false
- Not (opposite) is !
- Explanation: It gives back the opposite of what is true. (Use with parenthesis)
- Example: !(12 > 10) = false
- Important element of logical comparisons (|| and &&) is that they are evaluated from left to right and will not evaluate the right side if not needed.
For and While loops: Control flow operators that put a program into a loop until certain conditions are met or the break keyword is executed.
How to construct:
for (variable initializer; conditional-operation check; post-loop operation){
…
}
while (condition is true){
…
}
Example:
int factorial = 5;
int product = 5;
for (int i = 0; i < factorial; i++){
product = product * i;
System.out.println("Factorial is at: " + product);
}
int number = 0;
while (number != 10){
System.out.println(“Number is: ” + number);
number++;
}
Functions (Methods): A piece of code that is executed when called. They can take arguments (variables passed onto the method) and return values (data).
How to construct:
access modifier return type name(arguements){
...
return variable(or value); - if not void (No return type)
}
Example:
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
—————————————————————————————————————–
OOP: Object orientated programming, a programming methodology that uses objects (usually classes) to design computer applications and programs.
Key Terminology:
- Lets use this graph for the terms.
- Inheritance: Reuse existing objects to create specialized types or sub-classes. In this graph, Truck, sedan, and SUV are children of car, they contain all methods, and variables of Car and can call upon those methods or variables as long as they aren’t private.
- Encapsulation: The use of access modifiers (public, protected, private) to control access to methods and variables. Think getters and setters.
-
Polymorphism: Creation of methods that take more than one form…
Example:
In car class method Honk says “Honk!!”
but… In Sedan class method Honk is Overloaded (existing method with different arguments or in a inherited class with same arguments and now Honk says “Beep!”.
Classes: Objects that are containers for variables and methods and can be inherited (extended), abstract, and among other things.
How to construct:
access modifier class name {
...
}
Example:
public class Person{
private int age;
private String name;
private String Profession;
public int getAge()
{
return age;
}
}
Constructors and the new keyword: Constructors are functions called when a class is created, they have no return type specified because they return an instance(a created object of the class) of the class. The new keyword calls the constructor (if its public) with any specified arguments and creates the space to hold the new instance.
How to Construct:
access modifier -(usually public)- class name(arguments){
...
}
Example:
public Person(int age, String name){
this.age = age;
this.name = name;
}
this keyword: A keyword that references to the current instance. Usually used to separate argument variables from the ones in the class.
How to construct:
this.name of variable = something;
Example:
this.name = name;
Access Modifiers: Access Modifiers control the encapsulation of the class and its methods and variables. They control what the outside classes can see of a certain class.
Modifiers:
- public: Everyone can see the method or variable or class.
- private: Only the class containing the method, variable or class can see it.
- protected: Only the class and its children(all classes that inherit that class) can see the method, variable or class