Posts

Showing posts from May, 2011

Exception Handling

Exception,  that means exceptional errors. Actually  exceptions  are used for handling errors in programs that occurs during the program execution. During the program execution if any error occurs and you want to print your own message or the system message about the error then you write the part of the program which generate the error in the  try{}  block and catch the errors using  catch()  block. Exception turns the direction of normal flow of the program control and send to the related  catch()  block. Error that occurs during the program execution generate a specific object which has the information about the errors occurred in the program. import  java.io.*; public class  exceptionHandle{    public static  void  main(String[] args)   throws  Exception{      try {         int  a,b;        Scanne...

Loops

Looping constructs are used when we need to repeat a task a number of times or till some condition is me t. A looping construct should have - an initial condition – which starts the loop - an increment – which advances the loop - a termination condition – which helps come out of the loop The loops used in JAVA language are : 1. do - while 2. while             3. for  

Conditional Statements

There are statements which check for a condition and accordingly the execution flow can be changed. The most common conditional construct is of the format IF (condition)   THEN ----------------------   ELSE -------------------- Here, if the condition* evaluates to be “true”, THEN part is executed (& ELSE part is skipped) & if it evaluates to “false”, ELSE part is executed ( & IF part is skipped). * NOTE - the condition should be a valid expression that can be evaluated to either true or false.

Disadvantages of OOP

OOP is a high level concepts so takes more time to execute as many routines run behind at the  time of execution. Offers less number of functions as compared to low level programming which interacts directly with  hardware. Increased burden on part of OOP developer.  

ADVANTAGES OF OOP

Reduced Maintenance Real-World Modeling Improved Reliability and Flexibility High Code Reusability

OOP Concept

ABSTRACTION:- Abstraction refers to the act of representing essential features without including the background details. • Data abstraction is used as a tool to increase the modularity of a program • It is used to build walls between a program and its data structures DYNAMIC BINDING:- Dynamic Binding means that the code associated with the given function call is not know  until the time of call at runtime. Binding refers to the act of associating an object or a class  with its member .

Switch Statement

Switch Statement JAVA has a built-in multiple-branch selection statement called switch, which successively tests the value of an expression against a list of integer or character constants. When a match is found, the statements associated with that constant are executed.  The general form of the switch statement is: switch (expression) { case constant1 :statement sequence break; case constant2 :statement sequence break; case constant3 :statement sequence break; . . . default statement sequence } SAMPLE PROGRAM:- public class  SwitchExample {    public static  void  main ( String []  args )  throws  Exception {      int  x, y; x = 2 ; y = 4 ;       System.out.println ( "1. Add" ) ;        System.out.println ( "2. Subtract" ) ;        System.out.println ( "3....

ARRAY

ARRAY:- There is one variable capability wherein we can use one variable to store a list of data and manipulate them more efficiently. This type of variable is called an array. OR An array stores multiple data items of the same data type, in a contiguous block of memory, divided in to a number of slots. To declare an array in JAVA int[] ages; int ages[]; ages = new int[100]; OR int ages[] = new int[100]; SAMPLE PROGRAM:- public class Test { public static void main(String[] arg) { String day[] = new String[7]; day[0] = "Mon"; day[1] = "Tue"; day[2] = "Wed"; day[3] = "Thu"; day[4] = "Fri"; day[5] = "Sat"; day[6] = "Sun"; for (int i=0 ; i<7 ; i++) System.out.println(day[i]); } }

JAVA OOPs Concepts

Polymorphism:- Polymorphism allows one interface to be used for set of actions i.e one name may refer to different functionality Polymorphism allows a object to accept different requests of a client Types of Polymorphism 1. compile-time polymorphism 2. runtime polymorphism In compile-time polymorphism, method to be invoked is determined at the compile-time. Compile time polymorphism is supported through the method overloading. Method overloading means having multiple method with the same name but with different signature(number, type, and order of parameters). EXAMPLE OF COMPILE-TIME POLYMORPHISM:- class A { public void fun1(int x) { system.out.println("int"); } public void fun1(int x, int y) { system.out.println("int and int"); } } public class B { public static void main(String[] arg) { A obj = new A(); obj.fun1(2); obj.fun1(2,3); } } In runtime polymorphism, the method to be invoked is determined at runtime. The example of runtime...

JAVA OOPs Concepts

OOP:- Object Oriented Programming is the technique to create programs based on real world Class:- A class defines the Properties and behavior ( Variables and methods) that is shared by all its objects. It is a blue print for the creation of objects Object:- Object is the basic entity of object oriented programming language. Object is a n instance of class. It takes the properties(Variables) and uses the  behavior  (Methods) defined in the class. Encapsulation, Inheritance and Polymorphism are main pillars of OOPs. Encapsulation:- Encapsulation is the process of binding together the methods and data variables as a single entity. This keeps both the data and functionality code safe from outside world. It hides the data within the class as makes it available only through the methods. Java provides different accessibility scopes (Public, Protected, Private, default) to hide the data from outside. EXAMPLE:- class check { private int amo...