18
May - 2012
Friday
SUBSCRIBE TO NEWS
SUBSCRIBE TO COMMENTS

Archive for the ‘Newbie point’ Category

Difference Between C++ and Java

Posted by Alchamist On March - 21 - 2011ADD COMMENTS

Java Vs C++

  • Java does not support pointers.Pointer are inherently tricky to use and troublesome.
  • Java does not support multiple Inheritances because it causes more problem than it solves.Instead Java supports multiple interface inheritance,which allows an objects must implement those method signature from different interfaces with the condition that the inheriting object must implement those inherited methods.The multiple interface inheritance also allows an object to behave polymorphically on those methods.
  • Java does not support destructors but adds a finalize() method.Finalize methods are invoked by the garbage collector prior to reclaiming the memory occupied by the object,which has the finalize() method.
  • Java does not include structures or unions because the traditional data structures are implemented as an object oriented framework.
  • All the code in Java Program is encapsulated within classes therefore Java does not have global variables or functions.
  • c++ requires explicit memory management,while java include automatic garbage collection.

Difference between Static and Dynamic class loading

Posted by Alchamist On March - 21 - 2011ADD COMMENTS

Static class loading:

Classes are statically loaded with Java’s new operator.

Car c= new Car();

A NoClassDefFoundException is thrown if a class is referenced with Java new operator but the runtime system cannot find the referenced class.

Dynamic class loading:
Dynamic loading is a technique for programatically invoking the function of a class loader at runtime. Done by

Class.forName(String className);

The above static method returns the class object associated with the class name.Unlike the static loading the dynamic loading will decide whether to load the class Car or Jeep.Once the class is dynamically loaded the following method reutnrs an instance of the loaded class.It’s just like creating a class object with no arguments.

class.newInstance();

A classNotFoundException is thrown when an application tries to load in a class through its string name using the following methods but no definition for the class with the specified name could be found:

forName() method in class – Class
findSystemClass() method in class – ClassLoader.
loadClass() method in class – ClassLoader.



Difference between Stack vs Heap memory

Posted by Alchamist On March - 20 - 2011ADD COMMENTS

Stack
Stack memory stores variable types in address’ in memory, these variables in programming are called local variables and are often stored for short amounts of time while a function/method block uses them to compute a task.

Once a function/method has completed its cycle the reference to the variable in the stack is removed.
Heap
Heap memory stores all instances or attributes, constructors and methods of a class/object.

Comparison
A Heap reference is also stored in Stack memory until the life cycle of the object has completed. Inside the Heap reference all the contents of the object are stored whereas with a local variable only the variable contents are stored in the stack.

Example:

Stack
var blue
var red
ref 0×456783 (Heap reference)
var tom
ref 0×498702 (Heap reference)
var diane

Heap (0×456783)
name => Susan
age => 26
city => London
height => 5’7
Gender => female

Heap (0×498702)
name => Paul
age => 21
city => Glasgow
height => 6’0
Gender => male