Java Programming

Methodologies and Principles of Programming

Object:

Java is nothing but an object-oriented programming language .Object is an instance of a class in java. Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. An object stores its state in fields (variables in some programming languages) and exposes its behavior through methods (functions in some programming languages).

We will see how to create an object in java----

Public class Student Test {

Public static void main (String Args[]) {

Student jack =new Student();

In the above example StudentTest is a class and Jack is an object.

b.

Class:

A class is a template, from which individual objects are created and it describes an object as well as its behaviors.

Public class Student Test {

Public static void main (String Args[]) {

Student jack =new Student();

In the above example StudentTest is a class which has an object jack.

c.

Method:

A method is defined as some executable codes and when called it passes specified no. of arguments.i.e. methods are lines of java codes that are executed when they are called.

Public class Student Test {

Public static void main (String Args[]) {

Student jack =new Student();

Here main() is a method

d.

Method-overloading :

Method over-loading is a parameter-passing concept.When two different methods have rhe same name having different types or numbers of arguments,then they are called method over-loading.

Public void add(int a,int b) {

A+=b;

System.out.println(a);

}

here the method takes two int arguments

again,

Public void add(int a,int b,int c) {

A+=b+c;

System.out.println(a);

}

here the method takes three arguments whereas the name of the method is the same.this is

known as Method Over-loading.

e.

Constructor Method:

constructor methods have the same name of the class they are defined in and they have no return type in their method signatures

Automobile auto1=new Automobile();

Here new is the constructor

Encapsulation: Encapsulation is one of the most beneficiary things in object oriented programming language. With this types can be accessed through their external exposure, values or operations and not by the internals .we can change the way of our classes internally, but as long as we can keep our external operations intact we don not need to go back and fix the program that use it.

f.

Overriding method:

When a method is inherited from the super class to the sub class and works differently in the subclass than it works in the superclass,the method is known as overrode method.

Polymorphism: when we use an instance of a superclass as the instance of a subclass,then it is known as polymorphism.

Public void doSomething (Automobile auto) {…..}

We can pass in a SmallCar object,because it is an automobile,

SmallCar car= new SmallCar();

doSomething(car);

this is polymorphism.

2.

a. BUBBLE SORT

import java.io.*;

public class BubbleSort

{

public static void main(String args[])

{

BubbleSort bb = new BubbleSort();

int a = 10; ;

int[] num = new int[a];

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

int i,sum=0;

int sData=0, index;

String dat;

System.out.println("Enter 10 Data");

try{

for(i=0;i<a;i++)

{

dat = stdin.readLine();

num[i] = Integer.parseInt(dat);

}

}

catch(IOException ioe)

{

System.out.println("NUMBER ERROR");

}

System.out.println("The sorting data:");

bb.bubble_sort(num,a);

}

B. LINEAR INSERTION SORT

import java.io.*;

public class Linearinsertion{

public static void main(String args[])

{

Linearinsertion bb = new Linearinsertion();

int a = 10; ;

int[] num = new int[a];

BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

int i,sum=0;

int sData=0, index;

String dat;

System.out.println("Enter 10 Data");

try{

for(i=0;i<a;i++){

dat = stdin.readLine();

num[i] = Integer.parseInt(dat);

}

}

catch(IOException ioe){

System.out.println("NUMBER ERROR");

}

System.out.println("The sorting data:");

bb.insert_sort(num,a);

}

C. QUICK SORT

public class QuickSort{

public static void main(String a[]){

int i;

int array[] = {12,9,4,99,120,1,3,10,13};

System.out.println("\n\n RoseIndia\n\n");

System.out.println(" Quick Sort\n\n");

System.out.println("Values Before the sort:\n");

for(i = 0; i < array.length; i++)

System.out.print( array[i]+" ");

System.out.println();

quick_srt(array,0,array.length-1);

System.out.print("Values after the sort:\n");

for(i = 0; i <array.length; i++)

System.out.print(array[i]+" ");

System.out.println();

System.out.println("PAUSE");

}

public static void quick_srt(int array[],int low, int n){

int lo = low;

int hi = n;

if (lo >= n) {

return;

}

int mid = array[(lo + hi) / 2];

while (lo < hi) {

while (lo<hi && array[lo] < mid) {

lo++;

}

while (lo<hi && array[hi] > mid) {

hi--;

}

if (lo < hi) {

int T = array[lo];

array[lo] = array[hi];

array[hi] = T;

}

}

if (hi < lo) {

int T = hi;

hi = lo;

lo = T;

}

quick_srt(array, low, lo);

quick_srt(array, lo == low ? lo+1 : lo, n);

}

}

D. SELECTION SORT

public class selectionSort{

public static void main(String a[]){

int i;

int array[] = {12,9,4,99,120,1,3,10};

System.out.println("\n\n RoseIndia\n\n");

System.out.println(" Selection Sort\n\n");

System.out.println("Values Before the sort:\n");

for(i = 0; i < array.length; i++)

System.out.print( array[i]+" ");

System.out.println();

selection_srt(array, array.length);

System.out.print("Values after the sort:\n");

for(i = 0; i <array.length; i++)

System.out.print(array[i]+" ");

System.out.println();

System.out.println("PAUSE");

}

public static void selection_srt(int array[], int n){

for(int x=0; x<n; x++){

int index_of_min = x;

for(int y=x; y<n; y++){

if(array[index_of_min]<array[y]){

index_of_min = y;

}

}

int temp = array[x];

array[x] = array[index_of_min];

array[index_of_min] = temp;

}

}

}

3.

Balance Merge Sort Algorithms:

sort(){

int i, runs;

extern int maxfiles, unit;

extern char FilStat[];

extern struct rec LastRec[];

OpenRead (1);

For (i=2; i<=maxfiles; i++)

if ( i <= maxfiles/2 ) FilStat[i] = ‘-‘;

else OpenWrite ( i );

distribute();

do {

for ( i=1; i<=maxfiles; i++)

if (FilStat[i] = ='0') {

OpenRead (i);

LastRec[i] = ReadFile(i);

}

else OpenWrite(i);

for (runs=1; merge(nexfile()) !='done'; runs++);

} while (runs>1);

return ( unit );

};

Oscillating Merge Sort algorithms:

procedure sort (n, unit, direction : integer);

var i, r : integer;

begin

if n = 0 then

FilStat[unit] :='-‘

else if n = 1 then

ReadoneRun ( unit, direction)

else

for i:=1 to T-2 do begin

r:=n div (t-i-1);

n := n-r;

sort ( r, (unit+i-2) mod T + 2, -direction);

MergeOneRunInto ( unit, -direction)

end

end;

External Quick sort algorithms:

sort ( a, b)

int a, b;

{int i, j, rlow, rupp, wlow, wupp, InBuff;

typekey MaxLower, MinUpper;

struct rec LastRead;

extern struct rec Buff[];

while ( b>a ) {

rupp = wupp = b;

rlow = wolw = a;

InBuff = 0;

MaxLower = MinimumKey;

MinUpper = MaximumKey;

i = a-1;

j = b+1;

while ( rupp >= rlow) {

if ( rlow-wlow < wupp-rupp )

LastRead = ReadDirect ( rlow++ );

else LastRead = ReadDirect ( rupp-- );

if ( InBuff < M ) {

Buff [ InBuff++ ] = LastRead;

intsort ( Buff, 0, InBuff-1 );

}

else {

if ( LastRead.k > Buff[M-1].k) {

if ( LastRead.k > MinUpper ) j= wupp;

else MinUpper = LastRead.k;

WriteDirect ( wupp--, LastRead);

}

else if ( LastRead.k < Buff[0].k ) {

if ( LastRead.k < MaxLower ) I = wlow;

else MaxLower = LastRead.k;

WriteDirect ( wlow++, LastRead);

}

else if ( wlow-a < b-wupp ) {

WriteDirect ( wlow++, Buff[0] );

MaxLower = Buff[0].k;

Buff[0] = LastRead;

Intsort ( Buff, 0, M-1 );

}

else { WriteDirect ( wupp--, Buff[M-1] );

MinUpper = Buff[M-1].k;

Buff [M-1] = LastRead;

intsort ( Buff, 0, M-1 );

}

}

}

while ( InBuff > 0 ) WriteDirect ( wupp--, Buff[--InBuff] );

if ( i-1 < b-j) {

sort (a,1);

a = j;

}

else {

sort (j, b);

b = i;

}

}

return (1);

};

4.

Sequential Order:

Sequential order arranges things or is an arrangement of items in a predicable order; like pages of a book.

In a linked list representation, the data elements are not constrained to be stored in sequential order; rather the individual elements are stored “somewhere” in memory. The order of the elements maintained by explicit links between them.

Uniqueness :

A binary search tree is a structure with tow properties: a shape property and a property that relates the keys of the elements is the structure. We look first at the shape property. Each mode in a single liked list may point to one node. Thus a single linked list is a linear structure: each node in the list (except the last) has a unique successor. In contrast, a binary tree is a structure in which each node is capble of having two child nodes. And these children can also have tow children, and so on, giving the tree its branching structure. The “beginning” of the tree is a unique starting node called the root.

Hierarchical Order:

A one-dimensional super B-tree is a leaf search tree in which the leaves are linked in a list. To be able to perform weak deletions in such a structure we link the leaves in a doubly linked list. To perform a weak deletion of a pont we search for the leaf where the point is stored, remove it from the doubly linked list, delete the leaf and move its brother to the position of the father in the tree.

Please be aware that the free essay that you were just reading was not written by us. This essay, and all of the others available to view on the website, were provided to us by students in exchange for services that we offer. This relationship helps our students to get an even better deal while also contributing to the biggest free essay resource in the UK!