Java Fundaments
Java Fundaments
Java compiler:
The compiler converts the Java code into a byte code.
Java is Platform-independent ~
The Byte code(Intermediate level language) is platform independent. This byte
code is then fed into JVM of the respective OS and gets converted into binary
code(Machine level language). Hence, Java is WORA(Write Once Run Anywhere).
VARIABLES:
containers for storing data.
<<DataType variableName = value;>>
OPERATORS:
Operators are used to perform operations on operands.
1.Arithmetic Operators
+ : Addition
- : Subtraction
* : Multiplication
/ : Division
% : Modulo Division(returns remainder)
2.Assignment Operators
= , += , -=, *= , /= , %=
3.Comparison Operators
== : equal to
!= : not equal to
> : greater than
>= : greater than or equal to
< : lesser than
<= : lesser than or equal to
4.Logical Operators
&& : logical AND
|| : logical OR
! : logical NOT
5.Ternary Operator
variableName = condition ? true-statement : false-statement ;
CONDITIONAL STATEMENTS:
1.if statement
if(condition) {
//code to be executed if condition is true;
}
4.switch statement
switch(expression) {
case x:
{
//code
break;
}
case y:
{
//code
break;
}
case z:
{
//code
break;
}
default:
{
//code
}
}
LOOPS:
1.for loop
for(initialisation;condition;alteration) {
//code
}
2.while loop
initialisation;
while(condition) {
//code
alteration;
}
4.for-each loop
used to traverse through a collection of elements.
for(dataType variableName : refVariableName) {
//code
}
USER INPUT:
Scanner:
It is used to get user input.
<<import java.util.Scanner;
/////////////////////////
Scanner refVariableName = new Scanner(System.in);
dataType variableName = refVariableName.methodName();>>
<<System.out.println(args);>>
METHODS:
A method is a block of code used to perform certain actions.
method call:
methodName(arguments);
Local variables:
variables inside a method.