Archive

Archive for June, 2010

JavaProgram…. Mail it!!!


e-mail

All the programming freaks, you find this post very interesting. Here is the program to send a mail using javamail API.

The JavaMail API requires JDK/JRE 1.4 or higher. The JavaMail API is a Java optional package, it is not part of the core Java SE but is included in Java EE.

The above java code requires two other jar files, activation.jar and mail.jar which are to be kept inside the dist folder when working with any IDE such as NetBeans, Or else  these files are to be set in the environmental variables path. Here is the javamail API download link.

Here is the Fundamentals of the JavaMail API.

Results announced!! What is the result of Jntu???


Today B.Tech 4-2 results were announced. Nothing strange in my percentage 82, yet I found ironic failures of some of my classmates who are always diligent, hardworking, worthy and talented. I felt very bad after I wrote the failed candidate list for my Head of the Department.

I sometimes think Jntu correction totally different. Ever after writing really worthy matter. What really makes them fail one? I had amusing examples One of my friend who got just 0 and 2 in two subjects but after the re-evaluation in those two subjects he got 40 and 38. Are they literally playing with the lives of graduate students? May be yes!!!. I don’t say always all the time the evaluation is bad but sometimes the evaluation and lecturers evaluating may not meet the specifications.

I yell at the facilities provided by the engineering colleges under Jntu( 287 Engg & Tech as of November,2009 source: http://j.mp/jntucol)  because in more than 90% of the colleges, the facilities provided are too worst and deadly scanty such as labs, equipment, teaching aid and faculty etc., The above also may affect the result and making a student un-employable.

Now I want to end this article asking the below questions..

Jntu is giving permissions to new colleges in A.P every year. Is it really helpful for student community?

Many engineering colleges are being run without adequate facilities. Why cannot government and Jntu take action against them?

Is Jntu examination evaluation really good?

Is Jntu syllabus up to date?

Code fest


Are you a programming geek? Do you constantly feed your brain with codes and love coding competitions? Here is an opportunity from Intel to prove your skills. http://j.mp/intelprog. Rush…. the contest ends on June 21, 2010.

Sorting is easy!!!


One of the most common questions in many interviews is the sorting techniques. There are many sorting techniques, I am going to explain some of them in the coming posts.

We will start off with, the basic and simplest of all the sorting techniques, Bubble sort

Bubble Sort

Method: Bubble sort compares two adjacent elements and swaps if the first element is greater than the second one. After every pass the largest element in that pass bubbles up to the last position.

Example:

suppose the array elements are

5  7  8  3  2

pass1:

5  7 8  3  2  (compare 5 & 7)  (No Exchange)

5  7  8 3  2  (compare 7 & 8 )  (No Exchange)

5  7 8 3 2  (compare 8 & 3)  (Exchange)

5  7 3 8 2 (compare 8 & 2)  (Exchange)

5  7 3  2  8    (End of the pass1, the largest element is in its corresponding position the array)

pass2:

5 7 3 2 8 (compare 5 & 7)  (No Exchange)

5  7 3 2 8 (compare 7 & 3)  (Exchange)

5 3 7 2 8 (compare 7 & 2)  (Exchange)

5  3 2 7 8 (End of the pass2, the largest element in the pass2 is bubbled up to its corresponding position)

pass 3:

5  3 2 7 8 (compare 5 & 3)  (Exchange)

3 5  2 7 8 (compare 5 & 2)  (Exchange)

3  2 5 7 8 (End of the pass3, the largest element in this pass is bubbled up to its corresponding position)

pass 4:

3  2 5 7 8 (compare 3 &2 ) (Exchange)

2 3 5 7 8 (End of the pass4, all elements sorted)

Algorithm

#include<stdio.h>
#include<conio.h>
int main(void)
{
int a[]={1,12,2,11,3},i,j,n=5,temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
for(i=0;i<n;i++)
printf(“%d “,a[i]);
getch();
return 0;
}

compiled on: dev c++,  gcc, Turbo C

Analysis:

Worst Case: O(N2)        Average Case: O(N2)


The Pursuit of Happyness


The Pursuit of Happyness

This is one of the best movies I have ever seen. This movie portraits a man who strives for the happiness despite all  miseries in his life finally he makes it.

The story is very heart touching and fully inspiring, He struggles till the end of the film. He full fills his dream of becoming the stock-broker at the end, in his way he sails through many difficulties, his wife leaves him, the room owner throws his things out, he stays in the railway station bath room too. He gets an internship at Dream Witter but there is no salary and only one out of twenty will be chosen as the stock broker.

Really astounding acting from Will Smith and small boy they have  totally involved in their characters. The last few minutes before the ending is really inspiring. I recommend every one reading this post watch the film at least once.

Program to extract source code from comment lines


#include<stdio.h>
#include<conio.h>
void main()
{
FILE *p;
char ch=’a’,ch1;
int count=1;
clrscr();
p=fopen(“cfile.c”,”r”);//this is the demonstration of comment line
if(p==NULL)
{
printf(“File not found”);
exit(1);
}
while(ch!=EOF)
{
ch=fgetc(p);
if(ch==’\n’)
count++;
else if(ch=='”‘) {
while((ch=fgetc(p))!=’\n’);
count++;
}
else if(ch==’/’)
{
if((ch1=fgetc(p))==’/’)
{
printf(“\nComment no %d:”,count);
while((ch=fgetc(p))!=’\n’&&ch!=EOF)
printf(“%c”,ch);
count++;
printf(“\n”);
continue;
}
else if(ch1==’*’)
{
printf(“\nComment %d :”,count);
while(ch!=EOF)
{
if((ch=fgetc(p))==’*’)
{
ch1=fgetc(p);
if(ch1==’/’)
break;
else
{
printf(“%c%c”,ch,ch1);
continue;
}
}
else if(ch==’\n’)
count++;
printf(“%c”,ch);
}
printf(“\n”);
}
}
}
getch();
}

Compiled on: Turbo C, gcc

Description : Extracts the program source code with out the comment lines in the given source file

program to swap two numbers with out using temporary variable with in one line


#include <stdio.h>
#include <conio.h>
int main(void)
{
int a , b;
printf(“Enter two integers: “);
scanf(“%d%d”,&a,&b);
printf(“Before swapping: a=%d,b=%d\n”,a,b);
a=(a+b)-(b=a); //This is just one line
printf(“After swapping: a=%d,b=%d”,a,b);
getch();
return 0;
}
compiled on :gcc logic :simple and tricky
If you have any doubts please add a comment