SoloLearn Java
Concatenation
+(plus) operator between strings adds them together to make a new string
atrribute
An attribute describes the current state of an object. In the real world, each object behaves in its own way.
operand
a value used on either side of an operator
You can add a java DOC style comment by using
/** and */
Class
A class describes what the object will be , but is separate from the object itself. Classes can be described as blueprints, descriptions or definitions for an object.
Method Parameters
A method can have one type of parameter(or parameters) and return another, different type. For example it can take two doubles and return and int.
Advantages of Using Method
CODE REUSE: you can write a method once, and use it multiple times, without having to rewrite the code each time. PARAMETERS: Based on the parameters passed in, methods can perform various actions.
Continue
Causes the loop to skip the remainder of its body and then immediately retest its condition prior to reiterating. it makes the loop skip to its next iteration
Case
Each value in a Switch is called a case . the variable being checked on is checked for each case
Limits on array's?
In java you're not limited to jsut two-dimensional arrays. arrays can be nested withing array to as many levels as your programs need . You just need to declare with 2 dimensions and add as many sets of brackets as you need . ALL array members must be of the same type
Variable Types
Int: for whole numbers double: for floating point numbers with optional decimal points String for texts such as "Hello"
Array
Is a collection of variables of the same type
postfix
Operator appears after the operand int x = 34; int y = x++; // y is 34
prefix
Operator appears before the operand int x = 34; int y = ++x; // y is 35
Switch
Statement that tests a variable for equality against a list of values.
Static
Static Variable and Methods belong to the class instead of a specific instance
Variable
Stores data for processing
2 Dimensional array index's
The array's two indexes are called row index and column index. One for the array and one for the element inside the array
Return
The return keyword can be used in methods to RETURN a VALUE. As the method returns a value, we can assign it to a variable.
Calling a Method
To call a method, type its name and then follow the name with a set of parentheses.
Declare and Array
To declare and Array, you need to define the type of the elements with square brackets example int[ ] arr. this is an array of integers.
[ ] Square Brackets
Used for arrays you meed to declare before the brackets what kind of elements are in the array
Defining an Array capacity
You need to define arrays capacity , or the number of elements it will hold. To do this is the keyword new example int[] arr=new int[5];
Method
a collection of statements that are grouped together to perform an operation(also called a function
OOP (Object Oriented Programming)
a programming style that is intended to make thinking about programming closer to thinking about the real world.
array literal
a single statement that declares a variable and specifies array values as its content. String[ ] myNames={"A","b","c","d"};
for (loop)
allows you to efficiently write a loop that needs to execute a specific number of times
Multidimensional Arrays
are array that contain other arrays. The two-dimensional array is the most basic multidimensional array Example int [ ] [ ] sample={{1,2,3},{4,5,6}};
Method parameters
are declared inside the parentheses that follow the name of the method
; do not's
do not use after method and class declarations that follow with the body defined using the curly braces
Object in OPP
each object has three dimensions: identity, attributes, and behavior. an object is an INSTANCE of a class.
Instance
each object is called and instance of a class
{}
flow control structures code is always enclosed in curly braces
Boolean Type
has only 2 possible values true and False
Index
in and array the elements are ordered and each has a specific and constant position which is called and Index
void
indicates that a method does not return a value Method doesn't return any value
Adding the Elements in an array
int [ ] myArr = {6, 42, 3, 7}; int sum=0; for(int x=0; x<myArr.length; x++) { sum += myArr[x]; } System.out.println(sum);
Find array length
int[ ] intArr = new int[5]; System.out.println(intArr.length);
String
is an object that represents a sequence of characters.
do-while loop
is similar to the while loop but, unlike the while loop, the body of the do-while loop must be executed at least once.
Modulo(or remainder)
math operation performs and integer division of one value by another, the operator for the modulo operation is the percentage(%) character.
enhanced for loop
sometimes called a "for each" loop is used to traverse elements in arrays. The advantages are that it eliminated the possibility of bugs and makes the code easier to read
char
stands for character and holds single character
Loop
statement allows to repeatedly execute a statement or group of statements.
While (loop)
statement repeatedly executes a target statement as long as a given condition is true
break
terminates the loop and transfers execution to the statement immediately following the loop
Method
this defines behavior. a method is a collection of statements that are grouped together to perform an operation.