Tuesday, April 29, 2014

GL_POINTS In OpenGl


#include <GL/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);

glPointSize(3.0);
glBegin(GL_POINTS);
glColor3f(1.0,1.0,0.0);
glVertex2f(-0.5, -0.5);
glColor3f(1.0,0.0,0.0);
glVertex2f(-0.5, 0.5);
glColor3f(0.0,0.0,1.0);
glVertex2f(0.5, 0.5);
glColor3f(0.0,1.0,0.0);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
}
void init(){}
int main(int argc, char** argv)
{
glutCreateWindow("simple");
glutDisplayFunc(display);
init();
glutMainLoop();
}

Line drawing with mouse click event in OpenGl


#include <GL/glut.h> 
int ww = 600, wh = 400;
int first = 0;
int xi, yi, xf, yf;
void drawLine(int x1, int y1, int x2, int y2)
{
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(5.0);
glBegin(GL_LINES);
glVertex2i(x1, y1);
glVertex2i(x2, y2);
glEnd();
glFlush();
}
void display()
{
glClearColor(1.0, 1.0, 0.0, 1.0);
glColor3f(1.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void mouse(int btn, int state, int x, int y)
{
if(btn==GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
switch(first)
{
case 0:
xi = x;
yi = (wh-y);
first = 1;
break;
case 1:
xf = x;
yf = (wh-y);
drawLine(xi,yi,xf,yf);
first = 0;
break;
}
}
}
void myinit()
{
glViewport(0,0,ww,wh);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)ww,0.0,(GLdouble)wh);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(ww,wh);
glutCreateWindow("demo");
glutDisplayFunc(display);
myinit();
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}

Wednesday, April 16, 2014

Delete collection in mongodb

Update document in mongodb

Basic syntax of update() method is as follows
db.COLLECTION_NAME.update
(SELECTIOIN_CRITERIA, UPDATED_DATA)

Insert And Find In MongoDb

To insert data into MongoDB collection, you need to use MongoDB's insert() or save()method.
Basic syntax of insert() command is as follows:
db.COLLECTION_NAME.insert(document)
To query data from MongoDB collection, you need to use MongoDB's find() method.
Basic syntax of find() method is as follows
db.COLLECTION_NAME.find()
To display the results in a pretty way, you can use pretty() method.
SYNTAX:
db.mycol.find().pretty()
Apart from find() method there is findOne() method, that reruns only one document.

Drop Collections

Basic syntax of drop collection command is as follows
db.COLLECTION_NAME.drop()

Tuesday, April 15, 2014

Create Collections

Basic syntax of createCollection() command is as follows
db.createCollection(name, options)
option is optional

drop database

dropDatabase() command is used to drop a database

Create database

Command use database_name is used to create a database. You can use any name for database_name.
If you want to show the database you must want to insert atleast one document into it.

show dbs

Command show dbs used to show all the databases

MongoDB Statistics

Command db.stats() gives the detais of the particular database

MongoDB Help

You can get mongodb commands and descriptions using db.help()

Getting start with mongoDb


1.
*open a cmd
*change the directotry as mongodb installation didirectory. eg:- C:\mongodb\bin>mongod

2.
*open another cmd
*change the directotry as mongodb installation didirectory. eg:- C:\mongodb\bin>mongo
Then you can work with the 2nd cmd

MongoDb Introduction

*MongoDb is a Nosql database.This is something different from the RDBMS. *Colloction-This is like a table of RDBMS.

Saturday, April 12, 2014

Time converting program in Java


import java.util.*;
public class TimeConvert
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the value of seconds: ");
int sec=s.nextInt();
int hr=sec/3600;
int min=(sec-hr*3600)/60;
sec=sec-(hr*3600+min*60);
System.out.println(hr+"hours"+" "+min+"minites"+" "+sec+"seconds");
}
}

Base Exponent program in Java


public class Rec
{
public static double power(double base, int exponent)
{
if(exponent>0)
{
return (base*power(base,exponent-1));
}
else if(exponent<0 data-blogger-escaped-br=""> {
exponent=-exponent;
return 1/(base*power(base,exponent-1));
}
else
{
return 1;
}
}
public static void main(String args [])
{
System.out.println(power(2,-3));
}
}

Gcd program in java


public class gcd1
{
public static int gcd(int x,int y)
{
if(y==0)
{
return x;
}
else
{
return gcd(y,x%y);
}
}
public static void main (String args [])
{
System.out.println(gcd(10,5));
}
}

Fibonacci program in Java


public class fibnocci
{
static int fib(int n)
{
if((n==1)|| (n==2))
return 1;
else
return fib(n-1)+fib(n-2);
}
public static void main(String [] args)
{
System.out.println("fibnocci(7)= "+ fib(7));
}
}

Base converting program in Java


public class Base
{
public void decTobase(int n,int b)
{
if(n>0)
{
decTobase(n/b,b);
System.out.print(n%b);
}
}
public static void main(String args [])
{
Base a=new Base();
a.decTobase(15,2);
System.out.println();
a.decTobase(65,4);
System.out.println();
a.decTobase(511,8);
System.out.println();
}

Factorial program in Java


public class factorial
{
static int fact(int n)
{
if(n==0 || n==1)
return 1;
else
return n*fact(n-1);
}
public static void main(String [] args)
{
System.out.println("Factorial(4)="+fact(4));
}
}

2D Array In Java


public class TwoDArray
{
public static void main(String args[])
{
int [][] a={{1,2,3},{4,5,6},{7,8,9}};
for(int row=0;row<3 data-blogger-escaped-br="" data-blogger-escaped-row=""> {
for(int col=0;col<3 data-blogger-escaped-br="" data-blogger-escaped-col=""> System.out.print(a[row][col]);
System.out.println();
}
}
}

Array Sums in Java


class RowSum
{
int A[][]={{1,0,0,1},{1,-2,0,1},{-1,2,2,1}};
int B[][]={{1,1,-1,1},{0,1,-1,1},{0,0,1,1}};
int C[][]=new int[3][4];
void printArray()
{
for(int i=0;i<3 data-blogger-escaped-br="" data-blogger-escaped-i=""> {
for(int j=0;j<4 data-blogger-escaped-br="" data-blogger-escaped-j=""> System.out.print(C[i][j]+" ");
System.out.println();
}
}
void Addition()
{
for(int i=0;i<3 data-blogger-escaped-br="" data-blogger-escaped-i=""> {
for(int j=0;j<4 data-blogger-escaped-br="" data-blogger-escaped-j=""> C[i][j]=A[i][j]+B[i][j];
}
}
public static void main(String args[])
{
RowSum m=new RowSum();
m.Addition();
System.out.println("\n Array elements after addition:");
m.printArray();
}
}

Metrix Operation In Java


class MetrixOperation
{
int A[][]={{1,0,0},{1,1,0},{0,1,1}};
int B[][]={{1,1,1},{0,1,0},{0,0,1}};
int C[][]=new int[3][3];
void printArrayA()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
System.out.print(A[i][j]+" ");
System.out.println();
}
}
void printArrayB()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
System.out.print(B[i][j]+" ");
System.out.println();
}
}
void printXORArray()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
System.out.print(C[i][j]+" ");
System.out.println();
}
}
void XOROperation()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
if(A[i][j]==B[i][j])
C[i][j]=0;
else
C[i][j]=1;
}
}
}
public static void main(String args[])
{
MetrixOperation m=new MetrixOperation();
m.XOROperation();
System.out.println("\t"+"Metrix A :");
m.printArrayA();
System.out.println("*******************************");
System.out.println("\t"+"Metrix B :");
m.printArrayB();
System.out.println("*******************************");
System.out.println("\t"+"Metrix A XOR Metrix B:");
m.printXORArray();
}
}

metrix program in Java


class metrix
{
int m[][]={{1,2,13,4,5},{2,3,24,5,6},{3,4,35,6,7},{4,5,46,7,8}};
void printArray()
{
for(int i=0;i<4;i++)
{
for(int j=0;j<5;j++)
System.out.print(m[i][j]+" ");
System.out.println();
}
}
public static void main(String a[])
{
metrix ab=new metrix();
ab.printArray();
}
}

Simple Array Program in Java


import java.util.*;
public class ArrayOrder
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int a []={25,95,65,74,18};
int temp=0;
int sum=0;
double avg=0;
double S=0;
for(int i=0;i for(int j=0;j {
if(a[j]>a[j+1])
{
temp=a[j+1];
a[j+1]=a[j];
a[j]=temp;
}
}
for(int b=0;b {
sum=sum+a[b];
avg=sum/a.length;
System.out.println(a[b]);
S=S+Math.pow((a[b]-avg),2);
}
System.out.println("Meadian is: "+a[a.length/2]);
System.out.println("minimum is: "+a[0]);
System.out.println("Summation is: "+sum);
System.out.println("Average is: "+avg);
System.out.println("sd is:"+Math.sqrt(S/a.length-1));
}
}

Star Printing in Java-06


import java.util.*;
public class Star7
{
public static void main(String args[])
{
for(int row=1;row<=5;row++)
{
for(int s=row;s<=4;s++)
System.out.print(" ");
for(int col=1;col<=2*row-1;col++)
System.out.print("*");
System.out.println();
}
for(int r=1;r<=4;r++)
{
for(int S=1;S<=r;S++)
System.out.print(" ");
for(int c=9-2*r;c>=1;c--)
System.out.print("*");
System.out.println();
}
}
}

Star Printing in Java-05


import java.util.*;
public class Star6
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int s=row;s<=5;s++)
System.out.print(" ");
for(int col=1;col<=2*row-1;col++)
System.out.print("*");
{
System.out.println();
}
}
}
}

Star Printing in Java-04


import java.util.*;
public class Star5
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int s=1;s<=row;s++)
System.out.print(" ");
for(int col=row;col<=6;col++)
System.out.print("*");
{
System.out.println();
}
}
}
}

Star Printing in Java-03


import java.util.*;
public class Star4
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int s=row;s<=6;s++)
System.out.print(" ");
for(int col=1;col<=row;col++)
System.out.print("*");
{
System.out.println();
}
}
}
}

Star printing in Java-02


import java.util.*;
public class Star3
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int col=1;col<=row;col++)
{
System.out.print("*");
}
System.out.println();
}
}
}

Star printing in Java-01


import java.util.*;
public class Star2
{
public static void main(String args[])
{
for(int row=1;row<=6;row++)
{
for(int col=row;col<=6;col++)
{
System.out.print("*");
}
System.out.println();
}
}
}

2D Graphics with Java


import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class drawing2 extends JFrame
{
public drawing2()
{
super(" FAHIM");
setBackground(Color.blue);
setSize(600,600);
setVisible(true);
}
public void paint(Graphics g)
{
Graphics2D g2d=(Graphics2D)g;
Color c1 = new Color(255,175,175);
Color c2 = new Color(255,0,0);
g2d.setPaint(new GradientPaint(5,30,c1,35,100,c2,true));
g2d.setStroke(new BasicStroke(4.0f));
g2d.fill(new Ellipse2D.Double(50,50,50,50));
Color c3 = new Color(0,0,255);
Color c4 = new Color(255,0,0);
g2d.setPaint(new GradientPaint(5,30,c3,35,100,c4,true));
g2d.setStroke(new BasicStroke(4.0f));
g2d.fill(new Ellipse2D.Double(75,75,100,75));
g2d.setPaint(Color.red);
g2d.setStroke(new BasicStroke(6.0f));
g2d.draw(new Line2D.Double(10,75,50,60));
}
public static void main(String args[])
{
drawing2 d=new drawing2();
d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Drawing with Java


import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class drawing extends JFrame
{
public drawing()
{
super(" Graphics 2D Shapes");
setBackground(Color.blue);
setSize(600,500);
setVisible(true);
}
public void paint(Graphics g)
{
//super.paint(g);
Graphics2D g2d=(Graphics2D)g;
//------------------Line---------------------------------------------------//
g2d.setPaint(Color.red);
g2d.setStroke(new BasicStroke(6.0f));
g2d.draw(new Line2D.Double(100,150,500,300));
}
public static void main(String args[])
{
drawing d=new drawing();
d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

Cylinder details


class Cylynder
{
double radius;
double height;
void volume()
{
double vol=Math.PI*radius*radius*height;
System.out.println("volume is: "+vol);
}
void CirfaceArea()
{
double A=(2*Math.PI*radius*radius+2*Math.PI*radius*height);
System.out.println("Cirface Area is: "+A);
}
public static void main(String args[])
{
Cylynder myCylynder=new Cylynder();
myCylynder.height=15;
myCylynder.radius=7;
myCylynder.volume();
myCylynder.CirfaceArea();
}
}

Circle detais with JOptionPane


import javax.swing.JOptionPane;
public class Circle{
private double radius, diameter, circleArea, circumference;
public static final String CN="Circle";
Circle(double radius){
this.radius=radius;
computeDiameter();
computeCircumference();
}
void computeDiameter(){
diameter=2*radius;
}
void computeCicleArea(){
circleArea=Math.PI*radius*radius;
}
void computeCircumference(){
circumference=2*Math.PI*radius;
}
public double getRadius(){
return radius;
}
public double getDiameter(){
return diameter;
}
public double getCircleArea(){
return circleArea;
}
public double getCircumference(){
return circumference;
}
public void setRadius(double newR){
radius= newR;
computeDiameter();
computeCicleArea();
computeCircumference();
}
public String toString(){
return "Circle's radius is "+radius+"\n Circumference is "+circumference + "\n Area is "+circleArea;
}
public static void main(String args[]){
Circle c1=new Circle(7.0);
Circle c2=new Circle(0.0);
JOptionPane.showMessageDialog(null, c2.toString(), "Circle Details", 1);
c2.setRadius(11.3);
String cDetails2=""+c2;
JOptionPane.showMessageDialog(null, c2.toString(), "Circle Details", 1);
JOptionPane.showMessageDialog(null, "=>"+c1, "Circle Details", 1);
}
}

Volume of a box


class Box1
{
double width;
double length;
double height;
double volume;
public Box1(double w,double l,double h)
{
this.width=w;
this.length=l;
this.height=h;
}
void computeVolume()
{
volume=width*length*height;
}
public double getVolume()
{
return volume;
}
public static void main(String args[])
{
Box1 mybox1=new Box1(10.0,20.0,15.0);
Box1 mybox2=new Box1(10.0,20.0,10.0);
mybox1.computeVolume();
mybox2.computeVolume();
System.out.println("volume is: "+mybox1.getVolume());
System.out.println("volume is: "+mybox2.getVolume());
}
}
rgwgrrgf

HelloWorld program


public class HelloWorld
{
public static void main(String args[])
{
System.out.println("HELLO FAHIM");
}
}