The C++ Connection

On why Java and C++ are long lost siblings...


Virtually every trailblazer, outlandish language that gets off the springboard these days is pigeonholed as an Object-Oriented language. And when it comes to Object Orientedness, C++ and Java are invariably the forerunners. There has been a load of hubbub on Java looking, working and feeling like C++. Effectual as the hubbub usually is, we decided to shovel up any blinking similarity that exists between the two (don't tell anyone, but all is what we aimed for :) ). Listed out here are some programs that will clarify that what works in C++, does often hold good for Java as well. At the same time, there is some thorough manicuring done for Java that the cousin missed out on.

This page is currently undergoing metamorphosis. Please bear with the caterpillar till we get you the butterfly. Thank you. See you soon.


Program 1
import java.applet.*;
import java.awt.*;
class yyy
{
}
public class zzz extends Applet
{       yyy a;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new yyy;
                showStatus("after new yyy");
                return true;
        }
}

Program 2
import java.applet.*;
import java.awt.*;
class yyy
{
}
public class zzz extends Applet
{       yyy a;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new yyy();
                showStatus ("after new yyy");
                return true;
        }
}

Program 3
import java.applet.*;
import java.awt.*;
class yyy
{       yyy(int i)
        {       System.out.println("In zzz one");
        }
}
public class zzz extends Applet
{       yyy a;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new yyy();
                return true;
        }
}

Program 4
import java.applet.*;
import java.awt.*;
class xxx
{       xxx()
        {       System.out.println("In xxx void");
        }
        xxx(int i)
        {       System.out.println("In xxx one");
        }
}
class yyy extends xxx
{       yyy()
        {       System.out.println("In yyy void");
        }
        yyy(int i)
        {       System.out.println("In yyy one");
        }
}
public class zzz extends Applet
{       yyy a;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new yyy();
                showStatus("after new yyy");
                return true;
        }
}

Program 5
import java.applet.*;
import java.awt.*;
class xxx
{       xxx()
        {       System.out.println("In xxx void");
        }
        xxx(int i)
        {       System.out.println("In xxx one");
        }
}
class yyy extends xxx
{       yyy()
        {       System.out.println("In yyy void");
        }
        yyy(int i)
        {       System.out.println("In yyy one");
        }
}
public class zzz extends Applet
{       yyy a;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new yyy(10);
                return true;
        }
}

Program 6
import java.applet.*;
import java.awt.*;
class xxx
{        xxx()
        {       System.out.println("In xxx void");
        }
        xxx(int i)
        {       System.out.println("In xxx one");
        }
}
class yyy extends xxx
{        yyy()
        {       System.out.println("In yyy void");
        }
        yyy(int i)
        {       System.out.println("In yyy one");
                super(i);
        }
}
public class zzz extends Applet
{       yyy a;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new yyy(10);
                return true;
        }
}

Program 7
import java.applet.*;
import java.awt.*;
class xxx
{        xxx()
        {       System.out.println("In xxx void");
        }
        xxx(int i)
        {       System.out.println("In xxx one");
        }
}
class yyy extends xxx
{        yyy()
        {       System.out.println("In yyy void");
        }
        yyy(int i)
        {       super(i);
                System.out.println("In yyy one");
        }
}
public class zzz extends Applet
{       yyy a;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new yyy(10);
                return true;
        }
}

Program 8
import java.applet.*;
import java.awt.*;
class yyy
{       void aa()
        {       System.out.println("In abc yyy");
        }
}
class zzz extends yyy
{       void aa()
        {       super.aa();
                System.out.println("In abc zzz");
                super.aa();
        }
}
public class Blink extends Applet
{       zzz a;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new zzz();
                a.aa();
                return true;
        }
}

Program 9
import java.applet.*;
import java.awt.*;
class yyy
{
        static int i = 10;
}
public class zzz extends Applet
{
        public boolean mouseDown(Event e,int x,int y)
        {       System.out.println(yyy.i);
                return true;
        }
}

Program 10
import java.applet.*;
import java.awt.*;
class yyy
{       static int i = 10;
        static void aa()
        {       System.out.println("in abc");
        }
}
public class zzz extends Applet
{       public boolean mouseDown(Event e,int x,int y)
        {       yyy.aa();
                return true;
        }
}

Program 11
import java.applet.*;
import java.awt.*;
class yyy
{       int k=10;
        static int i = 10;
        static void aa()
        {       int j =2;
                System.out.println("in abc" + i + ".." + j +".."+k);
        }
}
public class zzz extends Applet
{       public boolean mouseDown(Event e,int x,int y)
        {       yyy.aa();
                return true;
        }
}

Program 12
import java.applet.*;
import java.awt.*;
class xxx
{
}
class yyy extends xxx
{
}
public class zzz extends Applet
{       xxx a; yyy b;
        public boolean mouseDown(Event e,int x,int y)
        {       a = new yyy();
                b = new xxx();
                return true;
        }
}

Program 13
import java.applet.*;
import java.awt.*;
class xxx
{
}
class yyy extends xxx
{
}
public class zzz extends Applet
{       xxx a; yyy b;
        public boolean mouseDown(Event e,int x,int y)
        {       a = (xxx) new yyy();
                b = (yyy) new xxx();
                return true;
        }
}

Program 14
import java.applet.*;
import java.awt.*;
class xxx
{       void aa()
        {       System.out.println("In abc xxx");
        }
}
class yyy extends xxx
{       void aa()
        {       System.out.println("In abc yyy");
        }
}
public class zzz extends Applet
{       xxx a; yyy b;
        public boolean mouseDown(Event e,int x,int y)
        {       a = (xxx) new yyy();
                b = (yyy) new xxx();
                a.aa();
                b.aa();
                return true;
        }
}

Program 15
import java.applet.*;
import java.awt.*;
class xxx
{
}
class yyy
{
}
public class zzz extends Applet
{        xxx a; yyy b;
        public boolean mouseDown(Event e,int x,int y)
        {       a = (xxx) new yyy();
                b = (yyy) new xxx();
                return true;
        }
}


If all this no-explanation (as of now) babble has left you feeling daffy, scuttle back to the Java Page or just spare a minute for your comments, feedback, suggestions et al to us before you set the alarm for tomorrow...



Vijay Mukhi's Computer Institute
B-13, Everest Building, Tardeo, Bombay 400 034, India.
http://www.neca.com/~vmis
e-mail : vmukhi@giasbm01.vsnl.net.in
1