Java

Java is a set of computer software and specifications developed by Sun Microsystems, which was later acquired by the Oracle Corporation, that provides a system for developing application software and deploying it in a cross-platform computing environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones to enterprise servers and supercomputers.

Spring Logo

Spring Framework

The Spring Framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications - on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the "plumbing" of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

Hibernate Logo

Hibernate Framework

Hibernate ORM is an object-relational mapping framework for the Java language. It provides a framework for mapping an object-oriented domain model to a relational database.

Tuesday, June 25, 2013

Important C written Test Programs...


Write a C program to print a message without using semicolon(;)
#include<stdio.h>
#include<stdlib.h>
intmain(void) {
    if(printf("Hello to Ranga")) {
   }
   returnEXIT_SUCCESS;
}
Output: 
Hello to Ranga
Write c program which shutdown the window operating system?
#include<stdio.h>
#include<stdlib.h>
intmain(void) {
system("shutdown -s");
returnEXIT_SUCCESS;
}
Write a c program such that when we will click its .exe file then it will open internet explorer 
#include<stdio.h>
#include<stdlib.h>

intmain(void) {
system("c:\\progra~1\\intern~1\\iexplore.exe");
returnEXIT_SUCCESS;
}
What is the output of the program?
#include<stdio.h>
#include<conio.h>
void main()
{
  clrscr();
printf("%d",printf("%d",printf("10")));
getch();
}

Output: 
1021

What is the output of the following Program?

#include<stdio.h>
void main()
{
char c=0;
for(;c>=0;c++);
printf("%d",c);
}

Output:
-128

What is the output of the following Program?

#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=2;
int c=3,d=4;
clrscr();
if(a,b,c,d)
{
printf("condition is true");
}
else
{
printf("condition is false");
}
getch();
}

Output:
condition is ture

What is the output of the following Program?
 
#include<stdio.h>
#include<conio.h>
void foo();
void main()
{
int i=10;
clrscr();
printf("\n%d",i);
foo();
printf("\n%d",i);
getch();
}
void foo()
{
#undef i
#define i 50
}

Output:

10
10

What is the output of the following Program?

#include<stdio.h>
void main()
{
char c='Z';
printf("\n%c",c);
}

Output:
Z

What is the output of the following Program?

#include<stdio.h>
#include<conio.h>
void main()
{
int i=100;
clrscr();
printf("\n%d",sizeof(sizeof(i)));
getch();
}

Output:
2

What is the output of the following Program?

#include<stdio.h>
#include<conio.h>
void main()
{
int i=5;
clrscr();
printf("%d",main||i);
getch();
}

Output:
1

What is the output of the following Program
#include<stdio.h>
#include<conio.h>
void main()
{
int i=- -5;
clrscr();
printf("%d",i);
getch();
}

Output:
5

Write a program to compare 2 variables without using relational operators.

Concept used:
1: simple if statement, which evaluates true block if the result of the condition becomes non-zero.
2: X-OR Gate & Negation.

#include
void main()
{
int a=12;
int b=14;
if(a/b)
if(!(a^b))
printf("Both are equal");
else
printf("a is big");
else
printf("b is big now!!!!!!!");
}

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char *name ="name";
change(name);
printf("%s",name);
return 0;
}
change(char *name)
{
char *nm="new name";
name=nm;
}
#include <stdio.h>

#define _LINE_ 10
int main(int argc, char *argv[])
{
printf("%d",_LINE_);
return 0;
}

Output:
10

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int i = 0;
if(i++,i) printf("1");
else printf("0");
return 0;
}

Output:
1

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
enum bool{true,false};

if(true==(2==3))
printf("true");
else
printf("false");
return 0;
}

Output:
true

What is the output of the following Program?
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("%d",(float)3/2);
return 0;
}

Output:
0

What is the output of the following Program? 
#include <stdio.h>
int main(int argc, char *argv[])
{
int a[5]={1,2,3,4,5};
int dif;
int *p=a+1;
int *q=a+5;
dif=q-p;
printf("%d",dif);
return 0;
}

Output:
4

What is the output of the following Program?
 
#include <stdio.h>
#define exp 5
int main(int argc, char *argv[])
{
printf("%d",exp++);
return 0;
}

Output:
error: invalid lvalue in increment

What is the output of the following Program?
#include <stdio.h>
int main(int argc, char *argv[])
{
char *str = "Hello, world" ;
printf("%5s", str);
return 0;
}

Output: 
Hello, world

What is the output of the following Program?
 
#include <stdio.h>
void temp();
void temp(void);
int main(int argc, char *argv[])
{
temp();
return 0;
}

void temp()
{
printf("C is exciting!");
}

Output:
C is exciting!

What is the output of the following Program?
 
#include <stdio.h>
void temp(int);
int main(int argc, char *argv[])
{
temp(1);
return 0;
}

void temp(int i)
{
if(i == 10) return;
i++ ;
temp(i);
printf("%d ", i);
}

Output:
10 9 8 7 6 5 4 3 2

What is the output of the following Program?
#include <stdio.h>
int main(int argc, char *argv[])
{
char *str = "Hello, world";
int i = sizeof(str);
for( ; i >= 0 ; i--)
printf("%c " , str[i]);
return 0;
}

Output:
o l l e H

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
FILE *f1;
FILE *f2;
f1=fopen("myfile.txt","w");
f2=fopen("myfile.txt","w");

fputc('A',f1);
fputc('B',f2);

fclose(f1);
fclose(f2);

return 0;
}

Output:
B

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("\n%c",**++argv);
return 0;
}

Output:
f

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int i=3;
while(i--){
int i=100;
i--;
printf("\n%d",i);
}
return 0;
}

Output:
99 99 99

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char s1[]="Hello";
char s2[]="Hello";

if(s1==s2) printf("Same");
else printf("Diff");
return 0;
}

Output:
Diff

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int j=5;
printf("%d",(*&j)++);
return 0;
}

Output:
5

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char c='1';
int j=atoi(c);
printf("%d",j);
return 0;
}


What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int d=5;
printf("%f",d);
return 0;
}

Output:
0.000000

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char *s="\12345s\n";
printf("%s length is %d",s,sizeof(s));
return 0;
}

Output:
S45s
length is 4

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned i=1; /* unsigned char k= -1 => k=255; */
signed j=-1; /* char k= -1 => k=65535 */
/* unsigned or signed int k= -1 =>k=65535 */
if(i<j)
printf("less");
else
if(i>j)
printf("greater");
else
if(i==j)
printf("equal");
return 0;
}

Output:
less

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
float j;
j=1000*1000;
printf("%f",j);
return 0;
}

Output:

1000000.000000

What is the output of the following Program?
 
#include <stdio.h>
int f();
int main(int argc, char *argv[])
{
f(1);
f(1,2);
f(1,2,3);
return 0;
}
f(int i,int j,int k)
{
printf("\n%d %d %d",i,j,k);
}

Output:

1 2009147472 4199312
1 2 4199312
1 2 3

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int i=7;
printf("%d",i++*i++);
return 0;
}

Output:
49

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int count=10,*temp,sum=0;
temp=&count;
*temp=20;
temp=&sum;
*temp=count;
printf("%d %d %d ",count,*temp,sum);

return 0;
}

Output:

20 20 20


What is the output of the following Program?
 
#include <stdio.h>
int main()
{
static i=3;
printf("%d ",i--);
return i>0 ? main():0;
}

Output:
3 2 1

What is the output of the following Program?

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
char *s[]={ "dharma","hewlett-packard","siemens","ibm"};
char **p;
p=s;
printf("%s ",++*p);
printf("%s ",*p++);
printf("%s ",++*p);

return 0;
}

Output:
harma harma ewlett-packard

What a C program thta takes text, convert lower case letters into upper case letters.
 
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int i,len;
char name[100];
printf("Enter Name : ");
gets(name);
len=strlen(name);
printf("Name in Lower Case is %s\n",name);

for(i=0;i<len;i++)
{
if(name[i]>='a' && name[i]<='z')
name[i]=(char)name[i]-32;
}

printf("Name in Upper Case is %s",name);
return 0;
}

Output:

Enter Name : ranga reddy
Name in Lower Case is ranga reddy
Name in Upper Case is RANGA REDDY

What is the output of the following Program?

#include <stdio.h>
int main(int argc, char *argv[])
{
char *p1="name";
char *p2;
p2=(char*)malloc(20);
memset(p2, 0, 20);
while(*p2++ = *p1++);
printf("%s",p2);
return 0;
}

Output:
empty string

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int x=20,y=35;
x=y++ + x++;
y=++y + ++x;
printf("%d %d",x,y);
return 0;
}

Output:

57 94

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int x=5;
printf("%d,%d,%d",x,x<<2,x>>2);
return 0;
}

Output:

5,20,1


What is the output of the following Program?

#include <stdio.h>
#define swap(a,b) a=a+b;b=a-b;a=a-b;
int main(int argc, char *argv[])
{
int x=5, y=10;
swap (x,y);
printf("%d %d\n",x,y);
swap2(x,y);
printf("%d %d",x,y);
return 0;
}

int swap2(int a, int b)
{
int temp;
temp=a;
b=a;
a=temp;
return 0;
}

Output:

10 5
10 5


What is the output of the following Program?

#include <stdio.h>
int main(int argc, char *argv[])
{
char *ptr="Ranga Reddy";
*ptr++;
printf("%s\n",ptr);
ptr++;
printf("%s",ptr);
return 0;
}

Output:
anga Reddy
nga Reddy

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
char s1[]="Ranga";
char s2[]="Reddy";
printf("%s",s1);
return 0;
}

Output:
Ranga

What is the output of the following Program?

#include <stdio.h>
int main(int argc, char *argv[])
{
char *p1;
char *p2;
p1=(char *)malloc(25);
p2=(char *)malloc(25);
strcpy(p1,"Ranga");
strcpy(p2,"Reddy");
strcat(p1,p2);
printf("%s",p1);

return 0;
}

Output:

RangaReddy

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int x=10, y=15;
x = x++;
y = ++y;
printf("%d %d\n",x,y);
return 0;
}

Output:

10 16

What is the output of the following Program? 

#include <stdio.h>
int main(int argc, char *argv[])
{
int a=0;
if(a==0)
printf("Ranga Reddy\n");
printf("Ranga Reddy");
return 0;
}

Output:
Ranga Reddy
Ranga Reddy

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
unsigned int i=10;
while(i>=0)
{
printf("%u",i);
i--;
}

return 0;
}

Output:

Infinite Loop

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int a[5]={1,3,6,7,0};
int *b;
b=&a[2];
printf("%d",b[-1]);

return 0;
}

Output:

3

What is the output of the following Program?
 
#include <stdio.h>
int main(int argc, char *argv[])
{
int n=2,sum=1;
switch(n){
case 2:sum=sum+2;
case 3:sum*=2;
break;
default:sum=0;
}
printf("%d",sum);

return 0;
}

Output:
6

What is the output of the following Program?
 
#include <stdio.h>

int main(int argc, char *argv[])
{
int x=5,*p;
p=&x;
printf("%d",++*p);
return 0;
}

Output:  
 6

Sunday, May 19, 2013

How to Install Sun Java JDK6 On Fedora 17/18

                                        How To Install Sun Java JDK6 On Fedora17/18


installing java on linux


The following are the steps to install a Sun JDK6 in Fedora. 

Step-1: Download the Java Jdk6 from the below link:
Download. 

After downloading you can get the rpm file( for example jdk-6u35-linux-x64-rpm.bin )

Step-2: Open terminal and copy the above file into any location. I am copying the above rpm file into following location
[ranga@ranga java]$ pwd
/home/ranga/install/java


[ranga@ranga java]$ ./jdk-6u35-linux-x64-rpm.bin
bash: ./jdk-6u35-linux-x64-rpm.bin: Permission denied
The above error you can get because of there is no permission to execute the above rpm file.
[ranga@ranga java]# chmod +x jdk-6u35-linux-x64-rpm.bin
Change to root user by using su command
[ranga@ranga java]$ su
Password:
[root@ranga java]# chmod +x jdk-6u35-linux-x64-rpm.bin
[root@ranga java]# ./jdk-6u35-linux-x64-rpm.bin
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
  inflating: jdk-6u35-linux-amd64.rpm 
  inflating: sun-javadb-common-10.6.2-1.1.i386.rpm 
  inflating: sun-javadb-core-10.6.2-1.1.i386.rpm 
  inflating: sun-javadb-client-10.6.2-1.1.i386.rpm 
  inflating: sun-javadb-demo-10.6.2-1.1.i386.rpm 
  inflating: sun-javadb-docs-10.6.2-1.1.i386.rpm 
  inflating: sun-javadb-javadoc-10.6.2-1.1.i386.rpm 
Preparing...                ########################################### [100%]
   1:jdk                    ########################################### [100%]
Unpacking JAR files...
 rt.jar...
 jsse.jar...
 charsets.jar...
 tools.jar...
 localedata.jar...
 plugin.jar...
 javaws.jar...
 deploy.jar...
Installing JavaDB
Preparing...                ########################################### [100%]
   1:sun-javadb-common      ########################################### [ 17%]
   2:sun-javadb-core        ########################################### [ 33%]
   3:sun-javadb-client      ########################################### [ 50%]
   4:sun-javadb-demo        ########################################### [ 67%]
   5:sun-javadb-docs        ########################################### [ 83%]
   6:sun-javadb-javadoc     ########################################### [100%]

Java(TM) SE Development Kit 6 successfully installed.

Product Registration is FREE and includes many benefits:
* Notification of new versions, patches, and updates
* Special offers on Oracle products, services and training
* Access to early releases and documentation

Product and system data will be collected. If your configuration
supports a browser, the JDK Product Registration form will
be presented. If you do not register, none of this information
will be saved. You may also register your JDK later by
opening the register.html file (located in the JDK installation
directory) in a browser.

For more information on what data Registration collects and
how it is managed and used, see:
http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html

Press Enter to continue.....

Done.
[root@ranga java]# 


Now your installation is complete.

Step-3: Now you need to set the environment variables
There are two ways to set environment variables to the user wise.
1. Only particular user by using .bash_profile
2. Set to common to all users by using .profile
I am setting the the path to only particular user by using .bash_profile
Go to your home directory
 

[root@ranga java]$ cd
[root@ranga java]$ pwd
/home/ranga
[root@ranga ~]$ vi .bash_profile 
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

PATH=$PATH:$HOME/.local/bin:$HOME/bin
#export PATH

JAVA_HOME="/usr/java/jdk1.6.0_35"
export JAVA_HOME

export PATH=${JAVA_HOME}/bin:${PATH}
unset USERNAME

[root@ranga~]$. .bash_profile
Now check the JAVA_HOME setted properly or not by using following command.
 

[root@ranga~]$ echo $JAVA_HOME
/usr/java/jdk1.6.0_35
 

Step-4: Removing Open JDK

[root@ranga jdk1.6.0_35]# rpm -qa | grep java 

sun-javadb-core-10.6.2-1.1.i386 
sun-javadb-docs-10.6.2-1.1.i386 
tzdata-java-2013b-2.fc17.noarch 
sun-javadb-client-10.6.2-1.1.i386 
sun-javadb-javadoc-10.6.2-1.1.i386 
sun-javadb-common-10.6.2-1.1.i386 
java-1.7.0-openjdk-1.7.0.19-2.3.9.1.fc17.x86_64 
sun-javadb-demo-10.6.2-1.1.i386 
[root@ranga jdk1.6.0_35]# rpm -e --nodeps java-1.7.0-openjdk-1.7.0.19-2.3.9.1.fc17.x86_64
[root@ranga jdk1.6.0_35]# rpm -qa | grep java
sun-javadb-core-10.6.2-1.1.i386
sun-javadb-docs-10.6.2-1.1.i386
tzdata-java-2013b-2.fc17.noarch
sun-javadb-client-10.6.2-1.1.i386
sun-javadb-javadoc-10.6.2-1.1.i386
sun-javadb-common-10.6.2-1.1.i386
sun-javadb-demo-10.6.2-1.1.i386

Final step is reboot your system. 

[root@ranga jdk1.6.0_35]# reboot
After rebooting check once again which java installed.
[ranga@ranga ~]$ which java
/usr/java/jdk1.6.0_35/bin/java
[ranga@ranga ~]$ java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01, mixed mode)

Wednesday, May 1, 2013

Username is not in the sudoers file. This incident will be reported


If you are not on the "sudoers" list yet, Fedora/Ubuntu will tell you. You will see output like this:



Only the users listed in /etc/sudoers have the permission to use the command "sudo".

To give the sudo permission to a user we need to add the user to the file /etc/sudoers file.






Open the terminal and give the read and write permision to the sudoers file

chmod u+rw /etc/sudoers




Add the line




Here ranga is  the username

under the User privilege specification section.
Save the file and exit, now the sudo command should work for the user which was added in the file.