C Program for Factorial using Recursive Function


#include<stdio.h>
#include<conio.h>
long int factorial(int n);
void main()
{
int n;
clrscr();
printf("Enter the number:\n\n");
scanf("%d",&n);
printf("Factorial of %d is %ld",n,factorial(n));
getch();
}
long int factorial(int n)
{
if(n<=1)
{
return(01);
}
else
{
n=n*factorial(n-1);
return(n);
}
}

Output:- 

Enter the number
5
Factorial of 5 is 120

0 comments :

C Program for Base Conversion from Binary to Decimal


#include<stdio.h>
#include<conio.h>
int power (int);
void main()
{
long int n;
int x,s=0,i=0,flag=1;
clrscr();
printf("Input a Binary Number\n\n");
scanf("%ld",&n);
while(flag==1)
{
x=n%10;
s=s+x*power(i);
i=i+1;
n=n/10;
if(n==0)
flag=0;
}
printf("\nDecimal Equivalent = %d",s);
getch();
}
power(int i)
{
int j,p=1;
for(j=1;j<=i;j++)
p = p*2;
return(p);
}

0 comments :

C program for fibonacci series


#include<stdio.h>
#include<conio.h>
void main()
{
 int n;
 long int i;
 long int fibo(int n);
 clrscr();
 printf("Enter the limit:\n");
 scanf("%d",&n);
   i=fibo(n);
 printf("\nThe %dth Fibonacci number is %ld",n,i);
 getch();
}

long int fibo(int n)
{
 int old_no,currnt_no,sum,i;
   i=1;
   old_no=0;
   currnt_no=1;
   while(i<=n)
   {
      sum=old_no+currnt_no;
      old_no=currnt_no;
      currnt_no=sum;
      i++;
      printf("\n%d",sum);
   }
 return(sum);
}

Output:-

Enter the limit:

5

1
2
3
5
8
The 5th Fibonacci number is 8

0 comments :

C program for printing Pascal's Triangle


#include <stdio.h>
#include <conio.h>
void main()
{
int p[10][10];
int i,j,k;
clrscr();
printf("\nPascal's Triangle\n");
for(i=0;i<10;i++)
{
j=1;
p[i][0]=1;
p[i][i]=1;
while(j<i)
{
p[i][j]=p[i-1][j-1]+p[i-1][j];
j++;
}
}
for(i=0;i<10;i++)
{
j=10;
while(j>i)
{
printf("  ");
j--;
}
for(k=0;k<=i;k++)
{
printf("%4d",p[i][k]);
}
printf("\n\n");
}
getch();
}
Output:-

Pascal's Triangle
                    1                                                       
                  1   1                                                     
                1   2   1                                                   
             1   3   3   1                                                 
          1   4   6   4   1                                               
        1   5  10  10   5   1
      1   6  15  20  15   6   1                                           
    1   7  21  35  35  21   7   1                                         
  1   8  28  56  70  56  28   8   1                                       
1   9  36  84 126 126  84  36   9   1                                     

0 comments :

Eclipse shortcut keys



An integrated development environment (IDE) is a software application that provides comprehensive facilities to computer programmers for software development. An IDE normally consists of a source code editor, build automation tools and a debugger.
IDEs are designed to maximize programmer productivity by providing tight-knit components with similar user interfaces

Editors are an integral part of a programmer’s life. If you have good proficiency in using an editor thats a great advantage. For java developers there is huge list and some opular are Eclipse , Netbeans, MyEclipse. 
I use Eclipse as a my IDE. It is the leading development environment for Java

This post gives you information about various shortcut keys in Eclipse

You can use following keys for listing all shortcuts
CTRL + SHIFT + L

1.    Manage Files and Projects

Ctrl+N
Create new project using the Wizard
Ctrl+Alt+n
Create new project, file, class, etc.
Alt+f, then .
Open project, file, etc.
Ctrl+Shift+r
Open Ressource (file, folder or project)
Alt+Enter
Show and access file properties
Ctrl+s
Save current file
Ctrl+Shift+s
Save all files
Ctrl+w
Close current file
Ctrl+Shift+w
Close all files
F5
Refresh content of selected element with local file system

2.    Editor Window
Focus/ cursor must be in Editor Window for these to work.

F12
Jump to Editor Window
Ctrl+Page Down/Ctrl+Page Up
Switch to next editor / switch to previous editor
Ctrl+m
Maximize or un-maximize current Editor Window (also works for other Windows)
Ctrl+e
Show list of open Editors. Use arrow keys and enter to switch
Ctrl+F6/Ctrl+Shift+F6
Show list of open Editors. Similar to ctrl+e but switches immediately upon release of ctrl
Alt+Arrow Left/Alt+Arrow Right
Go to previous / go to next Editor Window
Alt+-
Open Editor Window Option menu
Ctrl+F10
Show view menu (features available on left vertical bar: breakpoints, bookmarks, line numbers, …)
Ctrl+F10, then n
Show or hide line numbers
Ctrl+Shift+q
Show or hide the diff column on the left (indicates changes since last save)

0 comments :

Difference between Spring and Struts framework



Spring is a light weight and open source framework created by Rod Johnson in 2003. Spring is a complete and a modular framework, Spring framework can be used for all layer implementations for a real time application or spring can be used for the development of particular layer of a real time application.

Struts is an open-source web application framework for developing Java EE web applications. It uses and extends the Java Servlet API to encourage developers to adopt a model–view–controller (MVC) architecture. It was originally created by Craig McClanahan and donated to the Apache Foundation in May, 2000.

Listed below is the comparison chart of difference between Spring and Strut Framework

Spring
Struts
Spring is a full-stack application framework that provides an MVC Framework
(Spring MVC) as one of its many modules.
Struts is a web framework which can be used to develop web applications using MVC pattern.

Spring Framework is said to be a non-invasive means it doesn’t force a programmer to extend or implement their class from any predefined class or interface given by Spring API
struts is said to be invasive .In struts we used to extend Action Class.
It forces the programmer that, the programmer class must extend from the base class provided by struts API
Spring implements IOC Design Pattern and addresses AOP Cross cutting concerns.
Struts implement MVC Design Patten
Spring is light weight framework
Struts is heavy weight framework
Spring is loosely coupled
Struts is tightly coupled
Spring is a Layered Architecture
Struts is a not a Layered Architecture
Spring provides easy integration with technologies like JDBC, Hibernate
We have to hard code to use technologies
like hibernate, jdbc, etc.
Spring framework not only allows JSPs but also
other views such as Velocity, Freemaker etc.
Struts allows only JSP as a view component.

Spring MVC provides more handler mappings.
Struts doesn’t have specific handler mappings but uses Action Mappings.
It also provides more model transfer.
It has fewer model transfer.
Spring offers complete Decoupling between layers in MVC.

Struts offers limited Decoupling between layers in MVC.

Spring offers IOC (inversion of control) and AOP (Aspect Oriented Programming).
Struts uses IOC internally but doesn’t provide to the programmer / developer.
Spring clear module division between Model, View and Controller.
Struts mixes Controller and Model.
Spring MVC just provides tags for basic HTML form tags
Struts 2 provides many out-of-box JSF-styled complex and composite tags
Such as: Ajax DOJO tags
Spring has spring webFlow for the same purpose, which is part of spring Framework.
Struts will be Generally used as a Front End Frame work.
Advantages of spring Framework:-
- Transaction management
- support for Messaging
- support and Integration with Other Frame works.
(Eg: Hibernate, Struts, Tapestry.. etc)
Advantages of Struts Framework:-
-Excellent support for Tag Library, which has wide industry acceptance.
-Easy to integrate with other client side technologies.


1 comments :

Difference between JDBC and Hibernate



JDBC stands for Java Database Connectivity allows developers to connect, query and update a database using the Structured Query Language. JDBC API standard provides Java developers to interact with different RDBMS and access table data through Java application without learning RDBMS details and using Database Specific JDBC Drivers.
Hibernate is an Object-Relational Mapping (ORM) solution for JAVA. It is a powerful, high performance object/relational persistence and query service. It allows us to develop persistent classes following object-oriented idiom – including association, inheritance and polymorphism.
Listed below is the comparison chart of difference beetween JDBC and Hibernate 

Hibernate 
JDBC 
Slower than JDBC and not used for Batch Processing.
Faster than Hibernate and used for Batch Processing.
Hibernate is Database Independent
JDBC query must be database specific
Criteria Query take care of Query Tuning.
JDBC you need to tune your queries.
Hibernate Supports two level of cache, you can store data into catch for better performance
in JDBC you need to implement your java cache.
Hibernate supports Query cache and It will provide the statistics about your query and database status.
JDBC Not provides any statistics.
No need to create any connection pool in case of Hibernate. You can use c3p0.
In JDBC you need to write your own connection pool
Hibernate Supports automatic versioning of rows
JDBC Not.
You can load your objects on start up using lazy=false in case of Hibernate.
JDBC Don't have such support.
In the xml file you can see all the relations between tables in case of Hibernate. Easy readability.
JDBC Not.
Hibernate is flexible and powerful ORM solution to map Java classes to database tables. Hibernate itself takes care of this mapping using XML files so developer does not need to write code for this.
With JDBC, developer has to write code to map an object model's data representation to a relational data model and its corresponding database schema.
Hibernate provides transparent persistence and developer does not need to write code explicitly to map database tables tuples to application objects during interaction with RDBMS.  
With JDBC, the automatic mapping of Java objects with database tables and vice versa conversion is to be taken care of by the developer manually with lines of code.  
Hibernate provides a powerful query language Hibernate Query Language (independent from type of database) that is expressed in a familiar SQL like syntax and includes full support for polymorphic queries. Hibernate also supports native SQL statements. It also selects an effective way to perform a database manipulation task for an application.  
JDBC supports only native Structured Query Language (SQL). Developer has to find out the efficient way to access database, i.e. to select effective query from a number of queries to perform same task.  
Hibernate provides this mapping itself. The actual mapping between tables and application objects is done in XML files. If there is change in Database or in any table then the only need to change XML file properties.  
Application using JDBC to handle persistent data (database tables) having database specific code in large amount. The code written to map table data to application objects and vice versa is actually to map table fields to object properties. As table changed or database changed then it’s essential to change object structure as well as to change code written to map table-to-object/object-to-table. 
Hibernate reduces lines of code by maintaining object-table mapping itself and returns result to application in form of Java objects. It relieves programmer from manual handling of persistent data, hence reducing the development time and maintenance cost.  
With JDBC, it is developer’s responsibility to handle JDBC result set and convert it to Java objects through code to use this persistent data in application. So with JDBC, mapping between Java objects and database tables is done manually.  
Hibernate, with Transparent Persistence, cache is set to application work space. Relational tuples are moved to this cache as a result of query. It improves performance if client application reads same data many times for same write. Automatic Transparent Persistence allows the developer to concentrate more on business logic rather than this application code.  
With JDBC, caching is maintained by hand-coding.  
Hibernate enables developer to define version type field to application, due to this defined field Hibernate updates version field of database table every time relational tuple is updated in form of Java class object to that table. So if two users retrieve same tuple and then modify it and one user save this modified tuple to database, version is automatically updated for this tuple by Hibernate. When other user tries to save updated tuple to database then it does not allow saving it because this user does not have updated data.  
In JDBC there is no check that always every user has updated data. This check has to be added by the developer.  

0 comments :