Monday, September 7, 2009

Today, I was speaking with my Internet Programming lecturer, Mr. Gupta. He was sharing his experience on teaching C to the first year mechanical class. He said, he couldn't explain the logic of adding sum of n digits to a student. He employed the usual strategy of leaving out the nines in the number. (The student didn't know that simple logic it seems!)

That's when this idea struck me. If you have a number, say x.
It shall be represented as (9*n)+y.

If we identify y then that's the sum of digits.

Say the number is 103

It's simple 99+4, (9*11)+4 hence 4.

y is nothing but (9+9+9+9....11 times) +4
So we skip all those nines and take the 4 alone.

In simpler words if x is the number then (x modulus 9) is the sum of the digits.
So in a programmer's perspective its just x%9.

Sunday, September 6, 2009

What Java does not have?

No functions in Java (Only Methods)
Function vs. Method
1. C++ functions could be present inside and outside the class.
2. But java methods could be written inside classes only.

No pointers in Java
1. Pointers lead to confusion.
2. Pointers crash program easily. (Addition of 2 pointers, Runtime memory leakage-dangling pointers)
3. Pointers break security.

No operator overloading in Java
1. Operators are immutable in java.
2. Operator’s meaning cannot be changed in java.

No preprocessor directives in Java

No multiple inheritance in Java

No static memory in Java

No destructors in Java

No goto statement in Java

Well, there seems to be more features available in C and C++ than in java. Why learn Java then? Doesn’t your brain ask this question? My brain did ask.
And I began searching for the answer.
First we have to compare C and Java to understand how the languages work.

Here is a small comparison between C and Java
C vs. Java





C





Java

So Java is powerful mainly because, of the byte code. It could be interpreted by the Java Virtual Machine. So based on the system, different JVMs are used. But the class file remains the same unlike C's exe file. It’s quite an interesting fact that JVM was written using C.

There is a big table with all the differences between C and Java mentioned in it. I would suggest you to skip it if you feel it to be too big.

Click here to view that table.

C uses a compiler or an interpreter (only one at a time).
Java uses both compiler and interpreter together.

In addition to this it uses a pretty interesting JIT. Now what does this JIT do?
Wikipedia gives the following definition:

In computing, just-in-time compilation (JIT), also known as dynamic translation, is a technique for improving the runtime performance of a computer program. JIT builds upon two earlier ideas in run-time environments: byte code compilation and dynamic compilation. It converts code at runtime prior to executing it natively, for example byte code into native machine code. The performance improvement over interpreters originates from caching the results of translating blocks of code, and not simply reevaluating each line or operand each time it is met. It also has advantages over statically compiling the code at development time, as it can recompile the code if this is found to be advantageous, and may be able to enforce security guarantees. Thus JIT can combine some of the advantages of interpretation and static (ahead-of-time) compilation.

The paragraph does not make complete sense to you unless you already know about JIT ;-).

Now let me try to put it simple.

Consider the following code:

for(i=1;i<=10;i++)
print i

It is a program to print from one to ten.

Normally, a compiler will convert the print i code ten times (say it takes ten
nanoseconds).

JIT Compiler will load print i at a place in the memory with an increment in it
and call it ten times (it takes just 2 nanoseconds).

Convert print I --------> 1 nanosecond.
Load it in memory -----> 1 nanosecond.

Coming back to our comparison, C vs. Java, I think I have told you enough for today. And as for C++ vs. Java, that’s covered in what Java does not have itself.

I have told you what Java does not have?
Why Java does not have those features is the question you have to think upon. Keep meditating till the next post.



I had been spending my last fortnight with Java. As I was studying, I understood its power and the flexibility it gives to a programmer. Though I have learnt Java in bits and pieces, I have not learnt it from the basic (ie., from the origin, history, architecture,..). In my college, we students have not been attending the classes for the past one week due to the fear of getting infected from swine flu in the campus! This has been like a blessing in disguise, I was able to peacefully explore Java. As I was exploring Java, I got an idea of making a small tutorial for people like me who have learnt Java in bits and pieces.

I will be posting my tutorial here in my blog once in a while! It is a tedious process so there is no fixed timeline on my tutorial posts. Continue your support.

Friday, September 4, 2009

Cool Pictures

Following are few photoshop works I liked.



A baby playing his own trick to the mum



Young at heart(s)-Shadow acts as the mind reader



A lady in a faded gray dress and her husband, dressed in a homespun suit walked in timidly without an appointment into the Harvard University President's outer office. The secretary could tell in a moment that such backwoods, country hicks had no business at Harvard and probably didn't even deserve to be in Harvard.
"We want to see the President "the man said softly.
"He'll be busy all day "the secretary snapped.
"We'll wait" the lady replied.
For hours the secretary ignored them, hoping that the couple would finally become discouraged and go away. They didn't and the secretary grew frustrated and finally decided to disturb the president.
"Maybe if you see them for a few minutes, they'll leave" she said to him. The President, stern faced and with dignity, strutted toward the couple.
The lady told him "We had a son who attended Harvard for one year. He loved Harvard. He was happy here. But about a year ago, he was accidentally killed. My husband and I would like to erect a memorial to him, somewhere on campus."
The president wasn't touched....He was shocked. "Madam" he said, gruffly, “We can't put up a statue for every person who attended Harvard and died. If we did, this place would look like a cemetery."
"Oh, no" the lady explained quickly "We don't want to erect a statue. We thought we would like to give a building to Harvard."
The president rolled his eyes. He glanced at the gingham dress and homespun suit, and then exclaimed, "A building! Do you have any earthly idea how much a building costs? We have over seven and a half million dollars in the physical buildings here at Harvard."
For a moment the lady was silent. The president was pleased. Maybe he could get rid of them now. The lady turned to her husband and said quietly, "Is that all it costs to start a university? Why don't we just start our own?"
Her husband nodded. The president's face wilted in confusion and bewilderment. Mr. and Mrs. Leland Stanford got up and walked away, traveling to Palo Alto, California where they established the University that bears their name. Stanford University, a memorial to a son that Harvard no longer cared about.
Most of the time we judge people by their outer appearance, which can be misleading. And in this impression, we tend to treat people badly by thinking they can do nothing for us. Thus we tend to lose our potential good friends, employees or customers.
Remember
In our Life, we seldom get people with whom we want to share & grow our thought process. But because of our inner EGO we miss them forever.

It is you who have to decide with whom you are getting associated in your life.

Tuesday, September 1, 2009

Throughout history, humans have always been prone to accidents. Some, such as the exotic car crashes seen on this page, can be very expensive. But that's trivial compared to the truly expensive accidents. An accident is defined as "an undesirable or unfortunate happening that occurs unintentionally and usually results in harm, injury, damage, or loss". Our aim is to list the top 10 most expensive accidents in the history of the world as measured in dollars.

This includes property damage and expenses incurred related to the accident such as cleanup and industry losses. Many of these accidents involve casualties which obviously cannot be measured in dollar terms. Each life lost is priceless and is not factored into the equation. Deliberate actions such as war or terrorism and natural disasters do not qualify as accidents and therefore are not included in this list.

# 10. Titanic - $150 Million



The sinking of the Titanic is possibly the most famous accident in the world. But it barely makes our list of top 10 most expensive. On April 15, 1912, the Titanic sank on its maiden voyage and was considered to be the most luxurious ocean liner ever built. Over 1,500 people lost their lives when the ship ran into an iceberg and sunk in frigid waters. The ship cost $7 million to build ($150 million in today's dollars).


# 9. Tanker Truck vs. Bridge - $358 Million



On August 26, 2004, a car collided with a tanker truck containing 32,000 liters of fuel on the Wiehltal Bridge in Germany . The tanker crashed through the guardrail and fell 90 feet off the A4 Autobahn resulting in a huge explosion and fire which destroyed the load-bearing ability of the bridge. Temporary repairs cost $40 million and the cost to replace the bridge is estimated at $318 Million.


# 8. MetroLink Crash - $500 Million



On September 12, 2008, in what was one of the worst train crashes in California history, 25 people were killed when a Metrolink commuter train crashed head-on into a Union Pacific freight train in Los Angeles . It is thought that the Metrolink train may have run through a red signal while the conductor was busy text messaging. Wrongful death lawsuits are expected to cause $500 million in losses for Metrolink..


# 7. B-2 Bomber Crash - $1.4 Billion




Here we have our first billion dollar accident (and we're only #7 on the list). This B-2 stealth bomber crashed shortly after taking off from an air base in Guam on February 23, 2008. Investigators blamed distorted data in the flight control computers caused by moisture in the system. This resulted in the aircraft making a sudden nose-up move which made the B-2 stall and crash. This was 1 of only 21 ever built and was the most expensive aviation accident in history. Both pilots were able to eject to safety.


# 6. Exxon Valdez - $2.5 Billion



The Exxon Valdez oil spill was not a large one in relation to the world's biggest oil spills, but it was a costly one due to the remote location of Prince William Sound (accessible only by helicopter and boat). On March 24, 1989, 10.8 million gallons of oil was spilled when the ship's master, Joseph Hazelwood, left the controls and the ship crashed into a Reef. The cleanup cost Exxon $2.5 billion.


# 5. Piper Alpha Oil Rig - $3.4 Billion



The world's worst off-shore oil disaster. At one time, it was the world's single largest oil producer, spewing out 317,000 barrels of oil per day. On July 6, 1988, as part of routine maintenance, technicians removed and checked safety valves which were essential in preventing dangerous build-up of liquid gas. There were 100 identical safety valves which were checked. Unfortunately, the technicians made a mistake and forgot to replace one of them. At 10 PM that same night, a technician pressed a start button for the liquid gas pumps and the world's most expensive oil rig accident was set in motion.
Within 2 hours, the 300 foot platform was engulfed in flames. It eventually collapsed, killing 167 workers and resulting in $3.4 Billion in damages.


# 4. Challenger Explosion - $5.5 Billion



The Space Shuttle Challenger was destroyed 73 seconds after takeoff due on January 28, 1986 due to a faulty O-ring. It failed to seal one of the joints, allowing pressurized gas to reach the outside. This in turn caused the external tank to dump its payload of liquid hydrogen causing a massive explosion.. The cost of replacing the Space Shuttle was $2 billion in 1986 ($4.5 billion in today's dollars). The cost of investigation, problem correction, and replacement of lost equipment cost $450 million from 1986-1987 ($1 Billion in today's dollars).


# 3. Prestige Oil Spill - $12 Billion



On November 13, 2002, the Prestige oil tanker was carrying 77,000 tons of heavy fuel oil when one of its twelve tanks burst during a storm off Galicia , Spain . Fearing that the ship would sink, the captain called for help from Spanish rescue workers, expecting them to take the ship into harbour. However, pressure from local authorities forced the captain to steer the ship away from the coast. The captain tried to get help from the French and Portuguese authorities, but they too ordered the ship away from their shores. The storm eventually took its toll on the ship resulting in the tanker splitting in half and releasing 20 million gallons oil into the sea.
According to a report by the Pontevedra Economist Board, the total cleanup cost $12 billion.


# 2. Space Shuttle Columbia - $13 Billion



The Space Shuttle Columbia was the first space worthy shuttle in NASA's orbital fleet. It was destroyed during re-entry over Texas on February 1, 2003 after a hole was punctured in one of the wings during launch 16 days earlier. The original cost of the shuttle was $2 Billion in 1978. That comes out to $6.3 Billion in today's dollars. $500 million was spent on the investigation, making it the costliest aircraft accident investigation in history. The search and recovery of debris cost $300 million.
In the end, the total cost of the accident (not including replacement of the shuttle) came out to $13 Billion according to the American Institute of Aeronautics and Astronautics.


# 1. Chernobyl - $200 Billion



On April 26, 1986, the world witnessed the costliest accident in history. The Chernobyl disaster has been called the biggest socio-economic catastrophe in peacetime history. 50% of the area of Ukraine is in some way contaminated. Over 200,000 people had to be evacuated and resettled while 1.7 million people were directly affected by the disaster. The death toll attributed to Chernobyl , including people who died from cancer years later, is estimated at 125,000. The total costs including cleanup, resettlement, and compensation to victims has been estimated to be roughly $200 Billion. The cost of a new steel shelter for the Chernobyl nuclear plant will cost $2 billion alone. The accident was officially attributed to power plant operators who violated plant procedures and were ignorant of the safety requirements needed.



Achluophobia Fear of darkness.
Acousticophobia Fear of noise.
Acrophobia Fear of heights.
Agoraphobia Fear of open spaces or of being in crowded places.
Ailurophobia Fear of cats.
Alektorophobia Fear of chickens.
Alliumphobia Fear of garlic.
Allodoxaphobia Fear of opinions.
Altophobia Fear of heights.
Amaxophobia Fear of riding in a car.
Ambulophobia Fear of walking.
Ancraophobia or Anemophobia Fear of wind.
Androphobia Fear of men.
Anglophobia Fear of England, English culture, etc.
Anthrophobia Fear of flowers.
Antlophobia Fear of floods.
Anuptaphobia Fear of staying single.
Apeirophobia Fear of infinity.
Aphenphosmphobia Fear of being touched.
Apiphobia Fear of bees.
Apotemnophobia Fear of persons with amputations.
Arachnephobia/Arachnophobia Fear of spiders.
Arithmophobia Fear of numbers.
Arrhenphobia Fear of men. Arsonphobia Fear of fire.
Astraphobia/Astrapophobia Fear of thunder and lightning.
Astrophobia Fear of stars/space.
Ataxophobia Fear of disorder or untidiness.
Atelophobia Fear of imperfection.
Athazagoraphobia Fear of being forgotton or ignored or forgetting.
Atychiphobia Fear of failure.
Aurophobia Fear of gold.
Automatonophobia Fear of ventriloquist's dummies, animatronic creatures, wax statues
Automysophobia Fear of being dirty.
Autophobia Fear of being alone or of oneself.
Aviophobia/Aviatophobia Fear of flying.

Bacillophobia Fear of microbes.
Bacteriophobia Fear of bacteria.
Bathmophobia Fear of stairs or steep slopes.
Batophobia Fear of heights.
Batrachophobia Fear of amphibians (like frogs)
Belonephobia Fear of pins and needles.
Bibliophobia Fear of books.
Botanophobia Fear of plants.
Brontophobia Fear of thunder and lightning.

Cacophobia Fear of ugliness.
Cainophobia/Cainotophobia Fear of newness, novelty.
Caligynephobia Fear of beautiful women.
Carnophobia Fear of meat.
Catagelophobia Fear of being ridiculed.
Catoptrophobia Fear of mirrors.
Cenophobia / Centophobia Fear of new things or ideas.
Ceraunophobia Fear of thunder.
Chaetophobia Fear of hair.
Chionophobia Fear of snow.
Chiraptophobia Fear of being touched.
Chirophobia Fear of hands.
Chorophobia Fear of dancing.
Chrometophobia/Chrematophobia Fear of money.
Chromophobia/Chromatophobia Fear of colors.
Chronomentrophobia Fear of clocks.
Cibophobia/Sitophobia/Sitiophobia Fear of food.
Claustrophobia Fear of confined spaces.
Climacophobia Fear of stairs.
Clinophobia Fear of going to bed.
Coimetrophobia Fear of cemeteries.
Coulrophobia Fear of clowns.
Cyberphobia Fear of computers.
Cyclophobia Fear of bicycles.
Cymophobia Fear of waves.
Cynophobia Fear of dogs.

Demophobia Fear of crowds.
Dendrophobia Fear of trees.
Dentophobia Fear of dentists.
Didaskaleinophobia Fear of going to school.
Dipsophobia Fear of drinking.
Dishabiliophobia Fear of undressing in front of someone.
Dromophobia Fear of crossing streets.

Eisoptrophobia Fear of mirrors.
Elurophobia Fear of cats.
Emetophobia Fear of vomiting.
Entomophobia Fear of insects.
Ephebiphobia Fear of teenagers.
Epistaxiophobia Fear of nosebleeds.
Equinophobia Fear of horses.
Ergophobia Fear of work.

Felinophobia Fear of cats.

Gamophobia Fear of marriage.
Geliophobia Fear of laughter.
Genophobia Fear of sex.
Gephyrophobia, Gephydrophobia, or Gephysrophobia Fear of crossing bridges.
Gerascophobia Fear of growing old.
Glossophobia Fear of speaking in public or of trying to speak.
Gynephobia/Gynophobia Fear of women.

Haphephobia/Haptephobia Fear of being touched.
Harpaxophobia Fear of being robbed.
Heliophobia Fear of the sun.
Hemophobia/Hemaphobia/Hematophobia Fear of blood.
Hierophobia Fear of priests or sacred things.
Hominophobia Fear of men.
Hylophobia Fear of forests.

Iatrophobia Fear of doctors.
Ichthyophobia Fear of fish.

Judeophobia Fear of Jews.

Keraunophobia Fear of thunder and lightning.
Kymophobia Fear of waves.

Lachanophobia Fear of vegetables.
Ligyrophobia Fear of loud noises.
Limnophobia Fear of lakes.
Liticaphobia Fear of lawsuits.
Lockiophobia Fear of childbirth.
Logizomechanophobia Fear of computers.
Logophobia Fear of words.
Lygophobia Fear of darkness.

Macrophobia Fear of long waits.
Mageirocophobia Fear of cooking.
Maieusiophobia Fear of childbirth.
Megalophobia Fear of large things.
Melissophobia Fear of bees.
Methyphobia Fear of alcohol.
Microphobia Fear of small things.
Misophobia Fear of being contaminated with dirt/germs.
Monophobia Fear of solitude or being alone.
Motorphobia Fear of automobiles.
Musophobia/Murophobia Fear of mice.

Necrophobia Fear of death / dead things.
Neophobia Fear of anything new.
Nosocomephobia Fear of hospitals.
Numerophobia Fear of numbers.

Ochlophobia Fear of crowds or mobs.
Ophidiophobia Fear of snakes.
Ophthalmophobia Fear of being stared at.
Ornithophobia Fear of birds.

Pedophobia Fear of children.
Peladophobia Fear of bald people.
Phasmophobia Fear of ghosts.
Placophobia Fear of tombstones.
Plutophobia Fear of wealth.
Pogonophobia Fear of beards.
Potamophobia Fear of rivers or running water.
Pteronophobia Fear of being tickled by feathers.
Pupaphobia fear of puppets.
Pyrophobia Fear of fire.

Rhytiphobia Fear of getting wrinkles.
Rupophobia Fear of dirt.

Scolionophobia Fear of school.
Selachophobia Fear of sharks.
Sesquipedalophobia Fear of long words.

Tachophobia Fear of speed.
Technophobia Fear of technology.
Telephonophobia Fear of telephones.
Testophobia Fear of taking tests.
Theophobia Fear of gods or religion.
Trypanophobia Fear of injections.

Venustraphobia Fear of beautiful women.
Verbophobia Fear of words.
Verminophobia Fear of germs.
Vestiphobia Fear of clothing.

Xenoglossophobia Fear of foreign languages.

Zoophobia Fear of animals

Friday, August 28, 2009



Let's go through the steps of the events that occur from the time you first push the power button on your computer to the time you click the "shut down" button.

1. You press the buttons to turn on your monitor and computer.

2. A signal is sent to your power supply telling it to turn on. The power supply is what keeps your entire computer system running; it is what makes the difference between a box with a whole bunch of odd-looking devices connected to it and a working computer system! The power supply changes the electrical current from the outlet in your wall into a voltage that can be used by your computer.

3. The fans found in the power supply will begin working. These fans are vital to your computer system. They circulate the air inside the computer case to make sure that the devices do not overheat!

4. Your computer's BIOS(Basic Input) goes to work. BIOS is the software that gives your CPU its first instructions when the computer is turned on. Your BIOS will:
Perform a power-on self-test (POST), an inspection checking to make sure that all of your computer's components are working properly.
Check to see if a reboot is necessary. If not, then it will perform a read/write test for your computer's random-access memory (RAM), it will check the keyboard and the mouse, and it will also check the PCI bus and expansion cards. You will see a string of text on your computer screen as your computer's BIOS checks everything.
Check the CMOS (Complementary Metal Oxide Semiconductor) for your system settings. It will check for what components are installed in your computer system as well as for important information concerning your computer's operating system.
Usually, you will see a string of words on a black screen when your computer first turns on. This is your BIOS system displaying information about your computer's central processing unit, information about how much memory your computer has, as well as information about your hard disk drives and floppy disk drives.

5. The bootstrap loader will load the your computer's operating system into the computer's memory. Bootstrap, or boot, for short, is the process of loading the operating system. The whole process of loading your operating system is called booting up your computer.

6. The operating system will go to work. At this point, all control of your computer system is transferred from the BIOS to the operating system. The tasks your operating system must perform can be broken up into six major categories:
Processor Management: The operating system breaks tasks down into chunks that your CPU can handle and it prioritizes the tasks before sending them off to the processor.
Memory Management: The OS coordinates the information as it flows in and out of the computer's random-access memory.
Device Management: The operating system will let the numerous devices that are part of your computer system communicate with each other and with the central processing unit.
Storage Management: The OS will direct data and information to the places where they are to be stored.
Application Interface: The operating system lets your computer's hardware interface, or talk to, the software.
User Interface: Of course, now you'll need someway to communicate with your computer. This is controlled by your operating system.

7. You open up and run certain programs or applications. First, let's say you open up a word document to type a letter to your Great-Aunt Betty.
Your operating system will realize that you have a word processor open, so when you use either the keyboard or the mouse to input information, it will know to accept the information you input for the word document. Sometimes, if you have more than one program open at a time, your operating system will have to determine which program it is that you are using at the given time, but for now, we will just concentrate on the word processor.

8. Let's say you wanted to type in the letter "D"
You press the "D" key on the keyboard
Your keyboard will send an electrical signal to your computer telling it that you have just pressed a button
The keyboard controller will send an interrupt to the central processing unit telling it to take a look at the key you just pressed. The "D" will be temporarily stored in a special memory until your CPU is ready to deal with it.
Most often, your CPU also has to deal with other tasks. Your operating system will prioritize these tasks. Finally, it is time for your CPU to deal with the key you just pressed.
The CPU determines which program you were using when you pressed the key. In this case, you were in a word processor.
The CPU will tell your operating system to display the letter "D" on the screen. The letter is displayed by adding it to your graphics card, which tells your monitor what to display on the screen! This seems like a long and complicated process, but it occurs almost instantaneously! That shows how fast a computer is!

9. Now, you've finished typing your letter to Great-Aunt Betty, and you want to save it. When you press the "save" button in your word processor, a message will be sent to the operating system. A window will pop up, in which you can choose where you want to save the document to. Then, the operating system will transfer the document from the computer's RAM to the specified storage device.

10. After you have saved your letter, you decide that you want to print it out. Your operating system will translate the file from its present form into a form that your printer can comprehend. Then, your printer will go to work!

11. Now, that you've finished your letter, you decide that you want to go online to chat with some friends. You open up a web browser. Once again, it is your operating system that controls everything. This time, you can either type in the URL of the website you want to go to, or click on a link. By using a modem, your browser software can direct you to the right website, which will be displayed on your monitor!

12. After you've finished chatting, you're done using your computer. You click on the "shut down" button.

13. The operating system will close any programs that you have left open. However, if it finds that you have left a word document open, and that the document contains unsaved information, a prompt will come up asking if you would like to save the file before you exit. How convenient!

14. The operating system will save your current settings for your computer system. This way, it will remember them the next time you turn on your computer.

15. Usually, your computer has special software that will automatically shut down its power supply. If not, you will have to manually press a button.

Wednesday, August 26, 2009

IBM DB2 does not support Windows XP Home Edition. So I had to change my os to windows XP Professional (inorder to use IBM DB2). When the XP installation is run from windows os , it actually allows us to upgrade XP Home to XP Professional. It's a pretty fast process! So there's no need to install the OS and drivers again.