import java.util.HashSet;
import java.util.Set;
/**
* Override_Annotation_Usage_Example, from Effective Java
*/
use of @override annotation in java - why ?
The @override annotation is most useful as a compile-time reminder that the intention of the method is to override a parent method. See this example:
java reflection - what is - 101 tutorial
The name reflection is used to describe code which is able to inspect other code in the same system (or itself).
A simple code example of this in Java (imagine the object in question is foo) :
Method method = foo.getClass().getMethod("doSomething", null);
method.invoke(foo, null);
One very common use case in Java is the usage with annotations. JUnit 4, for example, will use reflection to look through your classes for methods tagged with the @Test annotation, and will then call them when running the unit test.
There are some good reflection examples to get started : at http://java.sun.com/developer/technicalArticles/ALT/Reflection/index.html
Bubble sort working source code - C/C++
Bubble sort working source code - C/C++
#include <stdio.h>
#include <iostream.h>
void bubbleSort(int *array,int length)//Bubble sort function
{
int i,j;
for(i=0;i<length;i++)
{
for(j=0;j<i;j++)
{
if(array[i]>array[j])
{
int temp=array[i]; //swap
array[i]=array[j];
array[j]=temp;
}
}
}
}
void printElements(int *array,int length) //print array elements
{
int i=0;
for(i=0;i<length;i++)
cout<<array[i]<<endl;
}
void main()
{
int a[]={9,6,5,23,2,6,2,7,1,8}; // array to sort
bubbleSort(a,10); //call to bubble sort
printElements(a,10); // print elements
}
C C++ CODE : Shooting method for solving boundary value problem
Working C C++ Source code program for Shooting method for solving boundary value problem
#include<iostream.h>
#include<conio.h>
float f1(float ,float,float);
float f2(float, float ,float);
int main()
{
int i;
C C++ CODE : Simpsons 1/3 rule for integration
Working C C++ Source code program for Simpsons 1/3 rule for integration
/************** SIPMPSONS 1/3 RULE ***********************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
float funct(float a);
int main()
{
char choice='y';
float f,x,h,a,b,sum;
clrscr();
cout<<"a & b ? ";cin>>a>>b;
do
{
sum=0;
x=a;
cout<<"Enter value of h ? ";cin>>h;
while(x<b)
{
sum+=(funct(x)+4*funct(x+h)+funct(x+2*h));
x=x+2*h;
}
cout<<endl<<"The integration is: "<<sum*h/3<<endl;
cout<<endl<<"wanna continue (y/n) ? ";cin>>choice;
}while(choice=='y');
getch();
return 0;
}
float funct(float x)
{
return x*exp(x)-2; // sin takes arguments in radian........
}
C C++ CODE : Trapezoidal rule for integration
Working C C++ Source code program for Trapezoidal rule for integration
/************* TRAPEZOID FULE FOR INTEGRATION *****************/
#include<iostream.h>
#include<conio.h>
#include<math.h>
float funct(float a);
int main()
{
char choice='y';
float f,x,h,a,b,sum;
clrscr();
cout<<"a & b ? ";cin>>a>>b;
do{
sum=0;
x=a;
cout<<"Enter value of h ? ";cin>>h;
while(x<b)
{
sum+=(funct(x)+funct(x+h));
x=x+h;
}
cout<<endl<<"The integration is: "<<sum*h/2<<endl;
cout<<endl<<"wanna continue (y/n) ? ";cin>>choice;
} while(choice=='y');
getch();
return 0;
}
float funct(float x)
{
return x*exp(x)-2; // sin takes arguments in radian........
}
C C++ CODE : Numerical integration for tabular data
Working C C++ Source code program for numerical integration - trapeziode and simpsons 1/3 method
/************************ INTEGRATION FOR TABULAR DATA *****************/
#include<iostream.h>
#include<conio.h>
int main()
{
int n,i;
float x[10],f[10],h,sum=0,a;
clrscr();
cout<<"No of datas ? ";cin>>n;
cout<<"Enter datas : ";
for(i=0;i<n;i++)
cin>>x[i]>>f[i];
for(i=0;i<n;i++)
{
if(i==0||i==n-1)
sum+=f[i];
else
sum+=2*f[i];
}
h=x[1]-x[0];
cout<<"The value using trapezoide: "<<h*sum/2;
a=x[0];
sum=0;
while((a-h)<x[n])
{
sum+=(f[a]+4*f[a+h]+f[a+2*h]);
a+=2*h;
}
cout<<"\nThe value using simpsons 1/3 is : "<<h*sum/3;
getch();
return 0;
}
C C++ code : power method - numerical method to find eigen value and vector
Working C C++ Source code program for finding eigen value and eigen vector by power method
/************* Eigen value and eigen vector by Power method ***********/
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
float a[10][10],x[10],c[10],d=0,temp;
int n,i,j;
C C++ CODE: Gauss Jordon elimination method to solving linear equations
Working C C++ Source code program for Gauss Jordon elimination method to solving linear equations
/*************** Gauss Jordan method ********************/
#include<iostream.h>
#include<conio.h>
int main()
{
int i,j,k,n;
float a[10][10],d;
clrscr();
cout<<"No of equations ? ";cin>>n;
cout<<"Read all coefficients of matrix with b matrix too "<<endl;
for(i=1;i<=n;i++) // read nxn matrix - cofficients
for(j=1;j<=n+1;j++)
cin>>a[i][j];
/************** partial pivoting **************/
for(i=n;i>1;i--)
{
if(a[i-1][1]<a[i][1])
for(j=1;j<=n+1;j++)
{
d=a[i][j];
a[i][j]=a[i-1][j];
a[i-1][j]=d;
}
}
cout<<"pivoted output: "<<endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
/********** reducing to diagonal matrix ***********/
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
if(j!=i)
{
d=a[j][i]/a[i][i];
for(k=1;k<=n+1;k++)
a[j][k]-=a[i][k]*d;
}
}
/************** reducing to unit matrix *************/
for(i=1;i<=n;i++)
{
d=a[i][i];
for(j=1;j<=n+1;j++)
a[i][j]=a[i][j]/d;
}
cout<<"your solutions: "<<endl;
for(i=1;i<=n;i++)
{
for(j=1;j<=n+1;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
getch();
return 0;
}
C C++ CODE : Gauss jordan method for finding inverse matrix
Working C C++ Source code program for Gauss jordan method for finding inverse matrix
/*************** Gauss Jordan method for inverse matrix ********************/
#include<iostream.h>
#include<conio.h>
int main()
{
int i,j,k,n;
float a[10][10]={0},d;
clrscr();
Subscribe to:
Posts
(
Atom
)