Foundations Flashcards
Java Keywords
In the Java programming language, a keyword is any one of 52 reserved words that have a predefined meaning in the language; because of this, programmers cannot use keywords as names for variables, methods, classes, or as any other identifier. For example “public” or “class”.
Access Modifier
As the name suggests access modifiers in Java helps to restrict the scope of a class, constructor, variable, method, or data member. There are four types of access modifiers available in java:
Default – No keyword required
Private
Protected
Public
Class
Everything in Java is associated with classes and objects, along with its attributes and methods. For example: in real life, a car is an object. The car has attributes, such as weight and color, and methods, such as drive and brake.
A Class is like an object constructor or a “blueprint” for creating objects.
Method
A collection of statements (one or more) that perform an operation.
Main Method
The starting or entry point to every Java program:
public static void main(String[ ] args) {
}
Code Block
A Code Block is used to define a block of code. It’s mandatory to have one in a method declaration and it’s here where we add statements to perform certain tasks.
A code block occurs with and between the curly braces:
{
}
Statements
Java statements appear inside of methods and classes; they describe all activities of a Java program. Variable declarations and assignments, such as those in the previous section, are statements, as are the basic language structures like conditionals and loops.
Expressions
Expressions describe values; an expression is evaluated to produce a result, to be used as part of another expression or in a statement. Method calls, object allocations, and, of course, mathematical expressions are examples of expressions.
Variables
Variables are a way to store information in our computer. Variables that we define in a program can be accessed by the name we give them. The computer does the hard work of figuring out where they get stored in the computer’s Random Access Memory (RAM).
A variable, as the name suggests, can be changed, in other words, its contents are variable.
Declaration Statment
Used to define a variable by indicating the data type, and the name, and optionally to set the variable to a certain value.
Java Operators
Java Operators or operators perform an operation (hence the name) on a variable or value. Commong examples are:
\+ (Addition) - (subtraction) * (Multiplication) / (Division) % (Remainder) = (Assign value to) == (Equivalence) etc.
Java Packages
A package is a way to organize your Java projects. Think of them as folders.
Casting
Casting means to treat or convert a number from one data type to another. We put the type we want it to be in parenthesis like this (byte) (myMinByteValye/2);
Bonus: Other languages have casting, this is not just a Java thing.
String
A string, is used to store a series of characters. Although it is used like a primitive data type, it is not a primitive data type, it’s actually a class, but because we use it so often, Java gives favoritism to the String class and allows us to use it the same way we use primitive data types.