Archive for December, 2011

Exception handling in Java

Posted: December 17, 2011 by Shashwat Pradhan in Uncategorized

With the previous posts of java , everyone must now be familiar with the basic syntax of java . Basically java is similar in few ways to c++ but you cannot use pointers here :-/ (Java handles memory allocation and de-allocation itself) .  The control statements are syntactically same as C (although Java has a few more features) .

Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution.

Exception handling is a very important yet often neglected aspect of writing robust software. When an error occurs in a Java program it usually results in an exception being thrown. How you throw, catch and handle these exception matters. There are several different ways to do so. Not all are equally efficient and fail safe.

During the program execution if any error occurs and you want to print your own message or the system message about the error then you write the part of the program which generate the error in the try{} block and catch the errors using catch() block. Exception turns the direction of normal flow of the program control and send to the related catch() block. Error that occurs during the program execution generate a specific object which has the information about the errors occurred in the program.A finally{} block can also be used which will execute regardless .

Example :

import java.io.*;   // Java package including all classes

public class exceptionhandle{
public static void main(String[] a)
{
try{
int d,b,c;
d = Integer.parseInt(a[0]);
b = Integer.parseInt(a[1]);
c=d/b;
System.out.println(“Quotient is :” +c);
}
catch (ArithmeticException e){
System.out.println(“Denominator can’t be zero!!!”);
}
finally
{ System.out.println(“End of program”);}
}
}

Output:
D:\java>javac exceptionhandle.java

D:\java>java exceptionhandle 5 2
Quotient is :2
End of program

D:\java>java exceptionhandle 3 0
Denominator can’t be zero!!!
End of program

10 reasons why Linux will triumph over Windows

Posted: December 11, 2011 by Mayur More in FOSS

Windows 7 may be generating some positive buzz,  In fact, it’s only a matter of time before Linux takes its rightful spot at the top of the OS heap.

I have an announcement. The error of Microsoft’s ways is finally catching up and will cause the once-invincible juggernaut to kneel before that which is Linux. How is this? Microsoft started a tiny snowball when it released Windows Me. That snowball did nothing but gain momentum. There have been ups and downs along the way (XP being an up, for sure). But for the most part, the court of public opinion has steady lost faith in what once was considered the heart of personal computing.

If you don’t believe me, read on.

Note: This article is also available as a PDF download

1: Inconsistent Windows releases

One of the things you can always count on from Microsoft is that you can’t count on its new operating systems to be reliable. Let’s take a look at the individual releases:

  • Windows 95: Revolutionized personal computing.
  • Windows 98: Attempted to improve on Windows 95; failed miserably.
  • Windows Me: A joke, plain and simple.
  • Windows NT: Attempted to bring enterprise-level seriousness to the operating system; would have succeeded had it not taken Steven Hawking-like intelligence to get it working.
  • Windows XP: Brought life back to the failing Windows operating system. It hadn’t been since Windows 95 that the operating system was this simple.
  • Windows Vista: See Windows Me.

With this in mind, what do we expect from Windows 7? Myself, not much.

2: Consistent Linux releases

Converse to number 1, you have the far more consistent releases of the various Linux distributions. Yes, there have been a few dips along the way (Fedora 9 being one of them). But for the most part, the climb for Linux has been steadily upward. Nearly every Linux distribution has improved with age. And this improvement isn’t limited to the kernel. Look at how desktops, end-user software, servers, security, admin tools, etc., have all improved over time. Once could easily argue that KDE 4 is an example of a sharp decrease in improvement. However, if you look at how quickly KDE 4 has improved from 4.0 to 4.3 you can see nothing but gains. This holds true with applications and systems across the board with Linux.

3. Continuing Windows price hikes

Recently, I have had a number of long-time Microsoft administrators asking my advice on solid replacements for Exchange. The reason? Microsoft changed its licensing for Exchange to a per-user seat. Now anyone who logs on to an Exchange server must have a license. You have 100 employees (including administrators) who need to log on to Exchange? Pony up! This gets serious when your company starts having to cough up the money for 500+ Exchange licenses. The very idea that Microsoft would make such a bold change to licenses is made even more ridiculous considering the current state of the economy. Companies worldwide are having to scale back. And like Exxon Mobile celebrating record profits amid the catastrophe known as Hurricane Katrina, Microsoft creating such a cost barrier while the globe is facing serious recession is irresponsible and reprehensible.

4. Stable Linux “prices”

Converse to number 3, the prices of open source software licenses have remained the same — $0.00. When those administrators come to me asking for open source replacements for Exchange I point them to eGroupware and Open-X-Change. Both are outstanding groupware tools that offer an even larger feature set than their Microsoft equivalent. Both are reliable, scalable, secure, and free. The only cost you will have with either is the hardware they are installed upon. And with both packages, there is no limit to the amount of users that can be set up. One user, 1,000 users — it’s all good with open source software.

5: Windows hardware incompatibility

Microsoft Vista was a nightmare when it came to hardware compatibility. Not only was Vista incompatible with numerous peripherals, it took supercomputer-level iron to run the operating system! Sure this was a boon to Intel, which stood to make a pretty shiny penny. Intel knew a good amount of the public would be shelling out for new hardware, and the new hardware would cost more because it had to be faster to run Vista in all its Aero glory. But even hardware that would run nearly any other OS with lightening-fast speed was brought to a slow, grinding halt with Vista.

6: Linux hardware compatibility

Converse to number 5, Linux continues to advance in the category of hardware compatibility. Take Xorg, for example. Recent developments with the star of Linux’ graphical desktops have the X Windows server running sans xorg.conf. This was done primarily because the system had grown so good at detecting hardware. And so long as there wasn’t a cheap KVM between your monitor and your PC, Xorg would easily find the mode for your display and run X properly. With new distributions (such as Fedora 10), X configuration is becoming a thing of the past. Most other pieces of hardware are finding the same level of recognition.

7: Windows promises

I wanted to save this for last, but seeing as how it is number 7… We’ve all heard the pundits proclaiming Windows 7 will be the resurrection of the Microsoft operating system. But I recall this same proclamation with nearly every release from Redmond. Windows Vista was going to revolutionize the way the user interfaced with the computer. Vista was going to be the operating system you would never notice. Instead, Vista refused to NOT let you notice. And Windows Me was going to take Windows 98 and make it far more simple for the average user. What did it really do? Remove nearly every actual functioning system in the operating system, leaving little more than a browser and an e-mail client.

Everyone is always fond of saying the next Windows release will redefine the personal computer. But the public has finally reached such a point of apathy for Microsoft’s up and coming, the majority doesn’t even realize something new is coming out. The media can continue to push Windows 7, but the public will continue using XP until Microsoft pries it from its cold, dead fingers.How many dates Microsoft announces vs. how many dates change will probably be a 1:1 ratio.

8: Linux transparency

Converse to 7… The next release of any Linux distribution is never shrouded in mystery. Because of the nature of open source, the release candidates are always available to the public (and not on a limited basis), and the timeline is always made available. Any user can know exactly when a feature-freeze happens for a release of any distribution. And all Linux distributions work under the “full disclosure” model. Because of this, there is little false advertising going on with Linux. And unlike with Microsoft, you will never hear of a distribution claiming that its next release will revolutionize computing. If you go to the Fedora Project Wiki, you can view all the proposed and accepted features that will be included in the next release. You can also view the completed release schedule, where you will see that Fedora 11 has set an alpha release of 02/03/09, a beta release of 03/24/09, and a final release of 05/26/09. These dates are fairly firm and almost always on target.

9: Feature comparison

Let’s compare the feature lists of Windows 7 and Fedora 11.

  • Windows 7: OS X-like Doc, Multi-touch screen, mapping application similar to Google Earth, Hyper-Visor virtualization, location-aware apps, User Access Control improvements, Sidebar removal.
  • Fedora 11: 20-second boot time, btrfs file system, Better C++ support, Cups PolicyKit integration, DNS Security (DNS SECurity), ext4 default file system, Fingerprint reader integration, IBUS input method replaces SCIM (to overcome limitations), GNOME 2.26, KDE 4.2, Windows cross-compiler inclusion.

If you look at those features in and of themselves, you could easily argue that either one could be the more impressive list (depends upon your bias). But understand that the Fedora 11 features are added on an already outstanding operating system, whereas the Windows 7 features are being added to a lesser operating system. And what Microsoft is proclaiming to be the biggest improvement (multi-touch) doesn’t actually improve the operating system and also requires, surprise, new hardware! To get the most out of Fedora 11, you’ll be good to go with what you already have.

10: Hardware requirements

Vista-lite? Out of the mouths of Microsoft comes the proclamation that Windows 7 will run on any hardware that would run Vista and even slightly less powerful hardware. Slightly less powerful? What exactly does that mean? Well for one, Windows 7 will have no luck in the netbook market. And since XP is dying, the netbook market will be owned by Linux. Netbooks are not gaining enough power to run anything from Windows but the watered-down version of XP. Netbooks are not going anywhere, and consumers (both home and corporate) have their limits on how many hardware upgrades they will make to fulfill an operating systems’ needs. As of Fedora 10, the minimum system requirements look like something out of the mid ’90s.

Your take

In your opinion, has the court of public opinion already condemned Microsoft to failure or will Windows 7 pull Microsoft out of the muck and mire created by Vista? Will Linux continue its climb above Microsoft?

Truth Happens

Posted: December 11, 2011 by Vaibhav in Uncategorized

An excellent video based on  LINUX and Free Open Source Software…

Visit this page to get the latest articles and videos on open source, intellectual property, transparency, and more. See how openness and collaboration are transforming how we learn, share, and play.

truthhappens.redhat.com

Direct link for the video in other formats:

Adding 2 numbers in java

Posted: December 11, 2011 by Shashwat Pradhan in Uncategorized
Tags: , , , , , ,

Hope everyone managed to install the  JDK (if not please follow the previous post) and get started with java . Here we are going to implement a simple program to add 2 numbers , accepting values from the user . Enjoy !!

public class AddNumbers{

public static void main(String[] args) {
System.out.println(“Addition of two numbers!!!”);
int a = Integer.parseInt(args[0]);//To scan the number
int b = Integer.parseInt(args[1]);
int sum = a + b;
System.out.println(“Sum: ” + sum);
}
}

Output of the program(in cmd):

C:\java>javac AddNumbers.java

C:\java>java AddNumbers 9 22

Addition of two numbers!!!

Sum: 31

Simple Hello World program in JAVA

Posted: December 5, 2011 by Shashwat Pradhan in Uncategorized
Tags: , , , ,

public class HelloWorld
{
public static void main(String[] args)
{
System.out.println(“Hello, World!”);
}
}

Here you can follow the instructions to install the SE 6 SDK (JDK)  and get started with Java :

http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html

MaGiC sQuArE……

Posted: December 3, 2011 by AnKz . . in Catchy codes

Though a simple logic code …….

Yet Work the simples to be A Maestro…..

#include<stdio.h>
int main()
{
int n;
printf(“\n Enter value for n in Magic square matrix [n*n]\n n ought to be an odd no….. “);
scanf(“%d”,&n);

if(n%2==0)
{
printf(“The program had asked for an odd value, Engineer……”);
return 0;
}

int a=0,b=n/2,i,j,a1,b1,sum=0;
int sq[n][n];

for(i=0;i<n;i++)
for(j=0;j<n;j++)
sq[i][j]=0;   //The complete matrix is made a zero matrix

sq[a][b]=1;        //1st element of matrix should be in the 1st tow mid

for(i=2;i<=n*n;i++)
{
if( a!=0 && b!=0 )
{
a1 = a-1;
b1 = b-1;
}

else if( a==0 && b!=0 )
{
a1 = n-1;
b1 = b-1;
}

else if( a!=0 && b==0 )
{
a1 = a-1;
b1 = n-1;
}

else if( a==0 && b==0 )
{
a1 = n-1;
b1 = n-1;
}

if(sq[a1][b1] != 0)
{
a1 = a+1;
b1 = b;
}

sq[a1][b1]=i;
a=a1;
b=b1;

}

printf(“\n \n”);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf(“\t %d”,sq[i][j]);

printf(“\n”);
sum = sum + sq[i][–j];
}

printf(“The sum of every row or column is %d … Try it out…\n”,sum);

return 0;
}