PragmaX Blog

This is the blog exclusively for: P: Prakash, Pramod R: Radhika A: Archana, Amruta G: Geeta M: Mrinmoy, Milind A: Aamod

Monday, September 19, 2005

Platform Independence in Java


this is especially for you, mrinmoy, in java, the code is converted into a byte code, which can be interpreted by all operating systems. and the JVM interprets this byte code. JVM is the same regardless of the operating system where it is installed.

there are 3 layers in any program execution:
1. program
2. byte code
3. OS
OS talks to the byte code which is interpreted by JVM. this byte code is OS independent.

for the same reason, writing decompilers for java is simpler as compared to any other language.

Sunday, September 18, 2005

Tech talks

So we were in Radhika coffe shop, Fegursson college road, and dicussing technical stuff. Some interview like questions
Questions:
  1. What is the size of an empty class?
    Ans. Class size is 1
  2. Class A defines a virtual function foo(). What will be size of this class?
    Ans. Class size is 4 (4 bytes are reserve for the virtual pointer)
  3. Class B inherits Class A? Class A defines a virtual function foo()? What will be size of this inherited Class B?
    Ans. Class size is 4 (4 bytes are reserve for the virtual pointer)
  4. Class B and C inherit A. D inherits B and C. Class A defines a virtual function foo().What is the size of Class D
    Ans. Class size is 8.
------------------------
#include

class A
{
virtual void foo();
};
class B: public A
{
void foo();
virtual void foo2();
};

class C: public A
{
void foo();
virtual void foo2();
};
class D: public B, public C
{
void foo();
virtual void foo2();
};

void main()
{
printf("Size A: %d\n",sizeof(A));
printf("Size B: %d\n",sizeof(B));
printf("Size C: %d\n",sizeof(C));
printf("Size D: %d\n",sizeof(D));
}

--------------------------
Output (Compiled on VC++ [Windows]. Compiler: cl.exe):
Size A: 4
Size B: 4
Size C: 4
Size D: 8