Java does not support the concept of Pointers. Pointers are inherently
tricky and troublesome to use.
Java does not support multiple inheritance because it causes more
problem s than it solves. Instead Java supports multiple interface inheritance.
Java does not use structures and unions because the traditional data
structures are implemented as an object oriented framework( Java Collection
Framework ).
All the codes are encapsulated with in a class there fore java does not
have a global variables or functions.
C++ requires explicit memory management, while java includes automatic
garbage collection.
A
java platform is a software only platform. It runs on other hardware based
platforms like Unix, Linux, windows nt ,….etc.
Java
platform has two components :
JVM ( Java
Virtual Machine ) : It is a software that cam be ported onto various hardware
platforms. And converts Byte codes into machine level language.
Freeing up the required memory to make a
program more “ Robust” .
or
Destroy Useless objects.
Garbage collection is an assistance
provided in java and by using this assistance , the chances of failing a java
program with memory problems is very very low.
A class loader
is a component of jvm which checks if we are following all the rules at compile
time or not. There after it converts byte codes and loads the “ .class files “
.
There are two
types of Class loaders:
1.Boot Strap or System Class Loader :
Boot strap is responsible to
load the java API classes written by the sun developers. It is responsible to
load Jdk’s internal classes
Eg
: java.* packages
System Class loader can load a class from local path only.
2. User defined Class Loader:
If we want to load the application from remote machine. If we need to define user defined class
loader.
CONSTRUCTOR :A
Constructor is a set of instructions designed to initialize an instance of a
newly created object.
Two Rules defined
for the Constructors : ·A
constructor should have the same name a Class. ·Constructors
must not return a value.
There are
two types of constructors :
1.Default Constructor:
·Default constructor refers to a constructor that is
automatically created by compiler in the absence of explicit constructors. ·You can also call a constructor without parameters as default
constructor because all of its class instance variables are set to default
values.
2.Parameterized Constructor: ·Parameterized constructors are required to pass parameters on
creation of objects.
·If we define only parameterized constructors, then we cannot
create an object with default constructor. This is because compiler will not
create default constructor. You need to create default constructor explicitly. METHOD :
public void add
(int a, int b) { } A Java
method is a collection of statements that are grouped together to perform an
operation.accessreturn
typenameparametersBody
Example
programs of Constructors :
1)Default Constructor
:
package
org.javanoobs.dconstructor;
publicclass DefaultConstructor {
// This is the
Constructor
public DefaultConstructor()
{
System.out.println(" I am inside
the default constructor !!! ");
}
publicstaticvoid main(String args[])
{
// Object created..
DefaultConstructor
dCon = new DefaultConstructor();
}
}
OUTPUT
:
I am
inside the default constructor !!!
2)Parameterized Constructor :
package
org.javanoobs.pconstructor;
publicclass Test2 {
inta, b; // instance
variables.
staticintc;
// this is the
instance block.
{
System.out.println(" Inside
Instance Block ");
System.out.println(" C = " + c);
System.out.println(" A = " + a);
}
static {
System.out.println("Inside the
static block !!!");
System.out.println(" C = " + c);
}
publicvoid disp() {
int d = 1; // Local varables,
initialize to 0 or 1 or will result in an
// error.
d
+= a + b + c;
System.out.println("d after
addition : " + d);
System.out.println(" Disp method
called...");
}
publicstaticvoid main(String args[])
{
Test2
t; // refference
variable .
t
= new Test2(); // t is the object
.
t.disp();
}
}
package
org.javanoobs.pconstructor;
publicclass
ParameterizedConstructor {
private String name;
public
ParameterizedConstructor(String str) {
this.name = str;
System.out.println("I am Inside
Parametrized Constructor !!!");
System.out.println("The parameter
Value is : " + str);
}
publicstaticvoid main(String args[])
{
ParameterizedConstructor
pCon = new ParameterizedConstructor(" Java Noobs !!! ");
•Heap memory is used
by java runtime to allocate memory to Objects and JRE classes.
•Whenever we create
any object, it’s always created in the Heap space.
•Garbage Collection
runs on the heap memory to free the memory used by objects that doesn’t have
any reference.
•Any object created
in the heap space has global access and can be referenced from anywhere of the application.
Java Stack
Memory:
•Java
Stack memory is used for execution of a thread. They contain method specific
values that are short-lived and references to other objects in the heap that
are getting referred from the method.
•Stack
memory is always referenced in LIFO (Last-In-First-Out) order.
•Whenever
a method is invoked, a new block is created in the stack memory for the method
to hold local primitive values and reference to other objects in the method.
•As
soon as method ends, the block becomes unused and become available for next
method.
•Stack
memory size is very less compared to Heap memory.