Sunday 27 December 2015

Multidimensional array in java with it's example

A multidimensional array is a series of arrays so that each array contains its own sub-array(s).

An array of more than one dimension is known as multi-dimensional array.

multidimensional arrays are actually arrays of arrays. These, as you might expect, look and act like regular multidimensional arrays.


## Example:


/**
 *
 * @author pradeep
 */


class MultiDimensionalArray{  
public static void main(String args[]){  
  
//declaring and initializing 2D array  
int array[][]={{6,7,8},{4,6,8},{3,6,9}};  
  
//printing 2D array  
for(int i=0;i<3;i++){  
 for(int j=0;j<3;j++){  
   System.out.print("Multi Dimensional Array" +array[i][j]+" ");  
 }  
 System.out.println();  
}  
}
}  




Result Output of this result is:
run:


Multi Dimensional Array6 Multi Dimensional Array7 Multi Dimensional Array8 

Multi Dimensional Array4 Multi Dimensional Array6 Multi Dimensional Array8 

Multi Dimensional Array3 Multi Dimensional Array6 Multi Dimensional Array9 

BUILD SUCCESSFUL (total time: 0 seconds)


single dimensional array in java with it's example

One dimensional array is a list of variables of same type that are accessed by a common name. An individual variable in the array is called  an array element.



## Example :


/**


 *


 * @author pradeep


 */


class ArrayDemo {


    public static void main(String[] args) 
{


        /*int marks[]=new int[5];


        marks[0]=33;


        marks[1]=65;


        marks[2]=69;


        marks[3]=78;


        marks[4]=86;
        * */
        //int marks[]=new int[]{33,65,69,78,86};
        int marks[]={33,65,69,78,86};
        for(int i=0;i<5;i++)
        {
            System.out.println("print marks:"+marks[i]);
        }
    }
    
}

Advantages of array in java

Array is collection of similar kind of data. Array in java is index based , first element of the array is stored at 0 index.










## Benefits (Advantages) of array


Arrays permit efficient (constant time) random access but not efficient insertion and deletion of elements. 

Consequently, arrays are most appropriate for storing a fixed amount of data which will be accessed in an unpredictable fashion. 

  1.  Code Optimization
  2.  Performance increase

Disadvantage of interface in java

Interface
Interface is a mechanism to achieve fully abstraction. It's look looks like as class but not a class. It solve is with a powerful construct called interface.


It can be used to fully abstraction, generic template and multiple inheritance in java. It a blueprint of a class.


Disadvantage of interface-

  1. Interface are slower and more limited than other ones.
  2. Interface should be used multiple number of times otherwise it hardly any use of having them.

Advantage of interface in java

Interface is a mechanism to achieve fully abstraction. It's look looks like as class but not a class. It solve is with a powerful construct called interface.


It can be used to fully abstraction, generic template and multiple inheritance in java. It a blueprint of a class.



** Advantage of interface-



  1. Without bothering about implementation; we can achieve the security of implementation.
  2. Multiple interface can't be allow, however by using interface you can achieve the same.
  3. Interface are mainly used to provide polymorphic behavior.

What is Multiple Inheritance in java with it's example

Multiple inheritance in java if a class implements multiple interface or extends multiple interface that's is called multiple interface.




### Example:




/**
 *
 * @author pradeep
 */

interface Multiinterfaceprint
{  
void printmultiinterface();  
}  
  
interface Multiinterfaceshow
{  
void showmultiinterface();  
}  
  
class multiintr implements Multiinterfaceprint,Multiinterfaceshow
{  
  
public void printmultiinterface(){System.out.println("Hello i m interface");
}  
public void showmultiinterface()
{
System.out.println("Welcome to my city");
}  
  
public static void main(String args[])
{  
multiintr obj = new multiintr();  
               obj.printmultiinterface();  
               obj.showmultiinterface();  
 }  



Output Output  of this program is below  


run:

Hello i m interface
Welcome to my city

BUILD SUCCESSFUL (total time: 0 seconds)

Saturday 26 December 2015

Disadvantage Of Thread in java

A thread is an independent path of execution within a program. Many threads can run concurrently within a program. 


## Note Every thread in Java is created and controlled by the java.lang.Thread class. 


  1. Difficulty of writing codes
  2. Difficulty of debugging
  3. Difficulty of testing.

Advantage Of Thread in java

A thread is an independent path of execution within a program. Many threads can run concurrently within a program. 


Note: Every thread in Java is created and controlled by the java.lang.Thread class. 

  1. You can perform many operations  together so that's why your time not waste.
  2. Threads are independent so it is does't any  affect other thread if exception occur.

What is Multiple Inheritance in java with it's example

In this we can have n numbers of parents and a single class which drives from it.



For Example

 class A
   {
       void display()
         {
         
         }
       class B
            {
                   void display()
                          {
           
                           }
                   class C extends A,B
                       {
                             C C1=new C1();
                             C1.disp();
                          }





Another Example:


/**

 *

 * @author pradeep

 */

public class MultipleInheritance {

    

}

interface A

{

   public void MultipleInheritance();

}

interface B

{

   public void MultipleInheritance();

}

class MeltiDemo implements A, B

{

   public void MultipleInheritance()

   {

       System.out.println(" Multiple inheritance");

   }

}


What is Multi Level inheritance in java with it's example

It is just concept of grand parent class child class inheritance of parent class and parent-class is inheritance of grand-parent-class so in this case grand parent-class is implicitly inheriting the properties and the method of grand-parent along with parent-class that's is called multi level inheritance.



For example:

class A
  {
     System.out.println("Grand-parent-class");
   }
class B extends A
 {
      System.out.println("Parent-class inheritance of grand-parent");
 }
class C extends B
 {
      System.out.println("child-class inheritance of parent-class");
 }




Another example


package com;



/**

 *

 * @author pradeep

 */



class bike{

public bike()

{

System.out.println("Class bike");

}

public void vehicleType()

{

System.out.println("Vehicle Type: bike");

}

}

class hero extends bike{

public hero()

{

System.out.println("Class hero");

}

public void brand()

{

System.out.println("Brand: hero");
}
public void speed()
{
System.out.println("Max: 70Kmph");
}
}
public class honda extends hero{

 public honda()
 {
 System.out.println("honda : 80kmph");
 }
 public void speed()
{
System.out.println("Max: 120Kmph");
}
 public static void main(String args[])
 {
 honda obj=new honda();
 obj.vehicleType();
 obj.brand();
 obj.speed();
 }
}

  

Result: output of this program:

run:

Class bike

Class hero

honda : 80kmph

Vehicle Type: bike

Brand: hero

Max: 120Kmph

BUILD SUCCESSFUL (total time: 1 second)

What is Single Inheritance in java with it's example



In this we can have single base class and n number if drive class.



For Example

class a
 {
    int a;
  void display()
   {
      System.out.println("Display method");
    }
 class b extends a
  {
  }
}

Advantage of Object Oriented Programming

Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects.






* Advantages


  1. Objects are modeled on real world entities.
  2. This enables modeling complex systems of real world into manageable software solutions.
  3. OOPs makes development and maintenance easier where as in Procedure-oriented programming language it is not easy to manage if code grows as project size grows.)
  4. OOPs provides data hiding whereas in Procedure-oriented prgramming language a global data can be accessed from anywhere.

What is Abstraction in java with example

The purpose of abstraction is to hide information that is not relevant or rather show only relevant information and to simplify it by comparing it to something similar in the real world. 

Hiding internal details and showing functionality is known as abstraction. 

For Example

phone call, we don't know the internal processing.

What is polymorphism in java with example

Polymorphism is a feature that allows one interface to be used for a general class of actions.When one task is performed by different ways i.e. known as polymorphism.  

The behavior depends on the types of data used in the operation. It plays an important role in allowing objects having different internal structures to share the same external interface.


In java, we use method overloading and method overriding to achieve polymorphism. 




For Example 

cat speaks meaw, dog barks woof etc


Types of Polymorphism:

  1. Static Polymorphism and 
  2. Dynamic Polymorphism


1. Static Polymorphism (Function Overloading) – Function overloading if we have more than one function having same name with different prototypes (parameters) then it is also called function overloading.


2. Dynamic Polymorphism (Function Overriding) – Function overriding is just easy to say if sub class or child class has the same method or function declared in the parent class that types of method is called function or method overriding.


Declaring a method in subclass (child class) which function is already  declared in  parent class is known as method overriding.




What is class in java

Class



A class is a prototype that defines the variables and the methods common to all objects of a certain kind. 

Member Functions operate upon the member variables of the class. Collection of objects is called class. It is a logical entity.

A class, in the context of Java, are templates that are used to create objects, and to define object data types and methods.


Class declaration

A class is a template for manufacturing objects. You declare a class by specifying the class keyword followed by a non-reserved identifier that names it.


Example:


class identifier
{
   // class body

}


What is object, characteristics and its example in java

Object

Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.

It is a bundle of related variables and functions (also known methods).


Objects share two characteristics: They have State and Behavior.


  1. State: State is a well defined condition of an item. A state captures the relevant aspects of an object
  2. Behavior: Behavior is the observable effects of an operation or event,

Example :

Object: – Car

StateColor, Make

BehaviorClimb Uphill, Accelerate, SlowDown etc







Characteristics of Objects:
  1. Abstraction
  2. Encapsulation
  3. Message passing

Advantages Of Exception Handling in java

Exception handling is a powerful mechanism to handle run time errors. Exception Handling allow us to control normal flow of the program by using Exception handling in program.






## Advantages :


  1. It throws an exception whenever a calling method encounters an error providing that the calling method takes care of that error.
  2. Separating error handing code from "regular" code.
  3. Propagating error up the call Stack.
  4. Grouping error types and error differentiation.
  5. This is done with the help of try-catch blocks.




What is Error in java with example

The state or condition of being wrong in conduct or judgment or error if irrecoverable that's is Error.

Error is wrong or invalid words use in your program or use unknown rules in your program's.



## Types of error:


  1. Syntax error
  2. Run time/Logical error



1. Syntax Error : It is also known as compile time errors. If we are complete our program's after then we are running program's then first of all program's in compiles in this session something show errors like example: Missing of semicolon, Misspell any keyword's, Mismatch any one and close parenthesis.


2. Run Time/Logical Error : Error occur while running of our program's. These error very dangerous very difficulty for programmer to track down.

Example's like as :  

            - Using a null object to reference an object members.
            - Divide an integer by zero and many more



Examples of RuntimeExceptions

  1. OutOfMemoryError
  2. VirtualMachineError
  3. AssertionError...etc