Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, December 7, 2010

Java Practical Exam

I recently faced Java Practical Exam. The problem given this time was:

Make a Java applet program to meet following requirements:

(I have made a untidy sketch. Refer to it.)

Tuesday, October 19, 2010

Typing Tutor in C

Coding is Fun. Don't believe me? Try the below program and verify yourself...


Monday, October 11, 2010

OOP VS POP - From the programmers eye.

"The complexity and efforts made to develop an application remains the same." Maybe I should call this "Law of conservation of Coding".


Let us see what does it mean.

Consider a scenario where an application is developed via POP as well as OOP.

Wednesday, August 18, 2010

Combating one of the most common Programming Mistake

Lets begin with question.

Do you know the most common programming mistake? Try to recollect the times when you used to compile your baby size programs and print Hello World.

Didn't get it? Its omittance of semicolon at the end;

What I am about to share is solution to just another big common mistake, staking programmers scared sleeps.


The scenario:
After hapless efforts, tonnes of Page Dn and Page Up, when your eyes swell of digging screen and at last you encounter the villain: "if(x=0)". You take a deep breath and after adding the required '=' the program finally complies.


The Solution:
In order to avoid this just use a simple rule: always put conditions with constants on left: "if(0==x)". It might look bit odd but has the 'miracle' thing. It will always generate error if you put single '='. Here's how,

Lets assume you forget to put the second '=' (No way if you have read this post) and you try to compile, it would throw an error because "if(0=x)" is illegal in language - you cannot assign variable to constant.


Hence always keep these practices:
  • Use (0==x) in conditions
  • Read this blog everyday before brushing

That said will save you real time.

Saturday, July 17, 2010

Environment Variables in Windows


Being a computer engineering student, I had to face Java language this year.

On the first lab some instructions were given to run commands prior compiling (Setting path.)
set path=c:\program files\java\jdk1.6.0\bin

Surprisingly (for me) just running javac command then worked. I knew there was no command called "javac" and the current directory in cmd did not have any "javac" file.

Curiosity bubbled and I asked the instructor of this, and he explained:

The command "set path" alters the default-set system path "C:\windows" and "C:\windows\system32".

It can be verified by My Computer > Properties > Advanced tab > Environment Variables Button.






















Hence First lesson: System path (Under Environment Variables) is like virtual current directory. You can execute exe's lying in these folders, just like you execute them as if they are in your current directory.

Lemme explain,

Suppose there is an executable "temp.exe" in directory D:\temp. When you start command prompt, you are at c:\Documents and settings\

Now try to run "temp.exe".

Failed ? Eh ?

Reason is, there is no file called "temp.exe" in your current folder.

Navigate to D:\temp\ and then run "temp.exe". That goes well.

So to run any executable just by name (as we did by just typing "javac") we need to be in that directory.(My perception before lab)

But windows provides a mechanism through which you can setup another directories virtually as your current directories and execute files in them as if they were in your current directory.

Best example could be "notepad". Running this command opens up notepad editor. The executable for notepad is located @ C:\windows\system32 folder. Hence this directory being set as path by default we can run files in this folder just by names.

When I altered the path by "Set path" command, I could no longer run "notepad". It had the error.


Hence the confusion waded away and I carried on with Java.