Lecture 1
Lecture 1
Creating a class
A class is declared by using the keyword
class. E.g.
public class Tree
{
//This is our Tree class
//All codes goes here
}
Creating objects
In java an object is created when someone
says new.
At each new , a new object of a class is
created. E.g.
new dog();
new tree();
new student();
Garbage Collection
Garbage Collection is the mechanism provided
by JVM, to clean out the Heap, so that new
objects can be created.
It destroys the objects which are not in use
or eligible for garbage collection.
Any object is said to be eligible for garbage
collection (GC) if there is no Reference
Variable attached to it.
So what is a Reference Variable??????
Non-Primitive Datatype
Non-Primitive (or
Reference) datatype are
defined by programmer.
In this the datatype of the
variable is the Class whose
object it is going to refer.
Test t = new Test();
//where Test is the datatype of
t
Arithmetic operators
+ additive operators/string
concatenator
- subtraction operator
* multiplication operator
/ division operator
% remainder operator
Unary operators
++ increment operator
-- decrement operator
! logical compliment
operator
== Equal to
!= Not equal to
> Greater than
< Less than
>= Greater than or equal to
<= Lesser than or equal to
Conditional Operators
&& Conditional And
|| Conditional Or
?: Ternary Operator
Ternary Operator
The ternary operator or ?, is a shorthand if else
statement. It can be used to evaluate an expression
and return one of two operands depending on the
result of the expression.
boolean b = true;
String s = ( b == true ? "True" : "False" );
Or the above can be written as
boolean b = true;
String s;
if(b == true){
s = "True";
}else{
s = "False";
}