Você está na página 1de 5

The Heap: where all objects live. Garbage Collector process runs on it.

The Stack: where method invocations and local variables live.


================================================================================
==============================================
CONTROL STATEMENTS: IF, IF ELSE, SWITCH
///////////////If Statements
if (<condition>)
{
//Execute these statements if condtion is True.
}
----------------------------------------------------------------------------------///////////////If-ELSE Statements
if (condition)
{
//Execute these statements if condtion1 is True.
}
elseif
{
//Execute these statements if condtion2 is True.
}
elseif
{
//Execute these statements if condtion3 is True.
}
else
{
//Execute these statements if Default condtion is True.
}
----------------------------------------------------------------------------------SWITCH - SYNTAX
switch (expression)
{
case condtion1:
block_1;
break;
case condtion2:
block_2;
break;
case condtion3:
block_3;
break;
...
default:
block_default;
}
================================================================================
==============================================
Prmitive Data types are those data types which were used in C language. We do no
t have to use the new operators
================================================================================
==============================================
OPERATORS (https://docs.oracle.com/javase/tutorial/java/nutsandbolts/opsummary.h
tml)
Assignment Operators
=
This assigns value to a variable. e.g. x = 5;

Arithmatic Operators
+
*
/
%(remainder)
++ (incr
ement by 1)
-- (decrement by 1)
we also have pre & post increment operator e.g. ++x (pre) & x++ (post).
Relational Operators
>
<
>=
<=
==
!=
they compare two vlaues. Binary operators, and their operands are numeric expres
sions. The results of relational operators can be stored in a BOOLEAN Variable.
e.g.
boolean tooBig = (x>=hiValue);

Logical Operators
&& (AND)
|| (OR)
&
|
^ (XOR)
Returns True or false value based on the state of the variables.
XOR - ((X||Y) && !(X&&Y)). Either X or Y is true provided X & Y are NOT True i.e
. Both X & Y cannot be true (mutually exclusive). One has to be true and other h
as to be false.
The && and || operators use short-circuit evaluation i.e. if the left operand de
termines the outcome, then right operand expression is not evaluated. Note the f
ollowing
- for && Operator, the RHS expression is performed only when the LHS expression
is TRUE.
- for || Operator, the RHS expression is performed only when LHS is false.
This acts bit like an IF Statement.
Unary Operators

++

--

Increment and Decrement Operators: Two forms (prefix & postfix).


variable++ or ++variable.
Operate-Assign Operators (+= , *= etc. )
n +=3;
//this is same as n = n + 3.
age += numYears;

THE CONDITIONAL OPERATOR


(better to use If..personal opinion unle
ss you are using lambda function)
op1 ? op2 : op3
op1 is boolean and determines true or false.
if op1 is true, op2 is the result of the conditional operator.
else, op3 is the result of conditional operator. e.g.
char status;
//'a' for adult and 'm' for minor
int age = 16;
status = age >= 18 ? 'a' : 'm' ;
//so the status result will be s
tatus = m becasue age =16.
OPERATOR PRECEDENCE (http://introcs.cs.princeton.edu/java/11precedence/)
THE CAST OPERATOR
The cast operator only works on the code immidiately to its right.
float f =1.1F;
float g = 7.3F;

int total = (int) (f+g);


We use Cast operator when we are not sure if the results will fit in the new dat
a type.
To convert to a String. Do not use the cast operator.
double d = 12.5;
String s = "" + d;
================================================================================
==============================================
STATIC VS NON-STATIC VARIABLES
Static variables are shared across all the objects of a class. There is only one
copy & could be used anywhere in the application.
Non-Static variables are NOT shared. There is a separate copy for each individua
l live object.
Static variables can NOT be declared within a method.
public class nav {
static int x = 6;
}
//we can then use this Static variable from another class in another tab e.g.
public class kanav{
nav.x = 2;
}
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================

==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================

==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
================================================================================
==============================================
CONTROL FLOW STATEMENTS
Switch Statement: Byte, Short, Char & Int.
For Statement
While Statement
Do While Statement
Method Overloading: Using Same Method Name with different parameters.

Você também pode gostar