Monday, 5 September 2011

Inheritance in a Company - Manager-Employee Inheritance in java

   
class Employee
{
    protected float salary;
   
    private String bname = "Vee Bank";
       
    public void showBankName()
    {
        System.out.println(bname);
    }
}

class Manager extends Employee
{
    public void setSalary(float salary)
    {
        super.salary = salary;
    }
   
    public float getSalary()
    {
        return super.salary;
       
    }
}


public class CompanyMain
{
    public static void main(String[] args)
    {
            Manager manager = new Manager();
                manager.setSalary(40000);
                manager.showBankName();
                System.out.println("Manager Salary : " + manager.getSalary());
    }
}

Inheritance Demo 2 in java

class A
{
    public void aShow()
    {
        System.out.println("A Show");
    }
}

class B extends A
{
    public void bShow()
    {
        aShow();
        System.out.println("B Show");
    }
}


public class ClassCaller
{
    public static void main(String[] args)
    {
            new B().bShow();
    }
}

Inheritance Demo in java

 class AClass
 {
         public void aCaller()
         {
             System.out.println("Class : " + getClass());
         }
 }

 class BClass
 {
         public void bCaller()
         {
             System.out.println("Class : " + getClass());
         }
 }



public class Demo extends java.lang.Object
{
    public void caller()
    {
        System.out.println("Class : " + getClass());
    }
   
    public static void main(String[] args)
    {
            Demo demo = new Demo();
                demo.caller();
   
                new AClass().aCaller();
                new BClass().bCaller();
               
   
    }
}

2D Array Testing in java

import java.io.BufferedReader;
import java.io.InputStreamReader;


public class TwoDTesting
{
    public static void main(String[] args) throws Exception
    {
            final int ROWS = 2;
            final int COLS = 2;
            int arr[][] = new int[ROWS][COLS];
            int r;
            int c;
            BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
           
           
            System.out.println("Set Values\n");
           
            for(r=0; r<ROWS; r++)
            {
                for(c=0; c<COLS; c++)
                {
                    arr[r][c] = Integer.parseInt(buf.readLine());
                }
               
                System.out.println();
            }
           
        System.out.println("Set Values\n");
           
            for(r=0; r<ROWS; r++)
            {
                for(c=0; c<COLS; c++)
                {
                    System.out.print("\t"+arr[r][c]);
                }
               
               
                System.out.println();
            }
           
           
     }
}

Integer Array Testing in java

import java.io.BufferedReader;
import java.io.InputStreamReader;


public class IntegerArrayTesting
{
    public static void main(String[] args) throws Exception
    {
        int arr[]=new int[3];
        int x;
       
        BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
       
        System.out.println("Enter Values\n");
       
        for(x=0; x<3; x++)
        {
            arr[x] = Integer.parseInt(buffer.readLine());
        }
       
        System.out.println("Display Values\n");
       
        for(x=0; x<3; x++)
        {
            System.out.println(arr[x]);
        }
    }
}

Sunday, 4 September 2011

What is C++



 History
C++ (pronounced "see plus plus") is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell Labs as an enhancement to the C language. Originally named C with Classes, the language was later renamed C++ in 1983.


What is C++
C++ is one of the most popular programming languages with application domains including systems software (such as Microsoft Windows), application software, device drivers, embedded software, high-performance server and client applications, and entertainment software such as video games. Several groups provide both free and proprietary C++ compiler software, including the GNU Project, Microsoft, Intel and Embarcadero Technologies. C++ has greatly influenced many other popular programming languages, most notably C# and Java.


Key Features
·        C++ is an "object oriented" programming language.
·        C++ adds a concept called "operator overloading" not seen in the earlier OOP languages and it makes the creation of libraries much cleaner.
·        C++ maintains aspects of the C programming language, yet has features which simplify memory management.
·        C++ could be considered a superset of C.

What is java

What is java?
Java is a programming language originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simplerobject model.

What is the purpose to develop java?
Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere." Java is currently one of the most popular programming languages in use, particularly for client-server web applications.You can use Java to write computer applications that crunch numbers, process words, play games, store data or do any of the thousands of other things computer software can do.

Comparision with c and c++
Compared to other programming languages, Java is most similar to C. However although Java shares much of C's syntax, it is not C. Knowing how to program in C or, better yet, C++, will certainly help you to learn Java more quickly, but you don't need to know C to learn Java. Unlike C++ Java is not a superset of C. A Java compiler won't compile C code, and most large C programs need to be changed substantially before they can become Java programs.

It should not to be confused with JavaScript.