Tuesday, December 18, 2012

The "New" Keyword in Java

The "New" Keyword is used to allocate Memory dynamically.
example: ClassName obj = new ClassName( );

Focus to "new ClassName()"

Dynamic memory allocation:
There are two types of memory allocations
1. Static memory allocation.
2. Dynamic memory allocation

1. Static memory allocation :
Allocate memory when program compiles. example: declaring Static array. (you can't change array length when program begins runs)
2. Dynamic memory allocation :
Allocate memory, When programmer is ruining

If you want to allocate memory in runtime. you must use the "new" keyword.

ClassName obj = new ClassName( );

ClassName > Object Type
obj > Object Name
new > allocate memory for ClassName( )
ClassName() > run this class


More about this Topic


Link To More
http://stackoverflow.com/questions/2532767/java-dynamic-memory-allocation
http://docs.oracle.com/javase/tutorial/java/javaOO/objectcreation.html

Thanks. hope you got an idea. if anything missing or wrong. please leave a comment.





No comments:

Post a Comment