Wednesday, January 6, 2010

arguments in java comparing C and C++

Introduction

The focus of this article is to explain how a function or method passes data arguments to another function or method. The former is referred to as the caller and the latter as the callee. Before we dive in, let's get some terminology right.

Primitive data and Objects

Broadly, the data arguments in C, C++ and Java are either primitive data, i.e. variables of primitive types like int, char, double etc or they are objects of user defined types - structs and unions in C and C++, and classes in C++ and Java.

Stack and Heap

Data can be stored either on the stack or on the heap. Data stored on the stack are the local variables of functions or methods allocated on the call stack. When a function returns, the stack pops and its local variables are said to go out of scope, that is, they are deallocated. All data on the stack has a name - the variable name that is used to access it. They also have an address - the address of the memory location on the stack where they are stored. This address is not valid when the variable goes out of scope.

Heap is a common store where any function or method can allocate objects. It is particularly useful for dynamically creating primitive data or objects. Data on the heap has no name! They have an address - and it is the only way to access it. This address can be stored in a pointer type data variable. This pointer data in turn could either be on the stack or the heap, although this does not hold for Java as we will see.

Handle

In object-oriented terminology, a handle refers to the mechanism using which an object is accessed. C/C++ pointers and Java references are example implementations of handles. A handle is usually different from the object itself. The name of a named stack object is not commonly understood as a handle.

Pointers (C and C++)

Pointers are special types of data objects - they can store the addresses of primitive data or objects that are either on the stack and on the heap. The pointer in turn can be either on the stack or the heap. In C and C++, pointers are treated as first class data objects.

References (C++)

A reference is an alias name for a named primitive data or object. Since heap objects cannot be named, you cannot make references to heap objects. References are aliases to stack variables.


No extra memory is allocated to maintain references. It is an additional entry in the symbol table when the program is compiled and is resolved to the exact same location as the name of the data it is aliasing.) Note that this is the general meaning of the term reference and is implemented this way in C++. Such references are not supported in C and Java.

Java Reference (only in Java)

In Java, all objects are created only on the heap. It is impossible to create an objects of user defined types (classes) on the stack. So on the stack we need some variable that points to this heap object. (Recall that heap objects cannot have a name.) This variable is referred to as the Java Reference. It is very different from a C++ or a C pointer in the sense that Java does not allow the programmer to treat this pointer like another data. That is, Java references are not first class data objects. It is just a handle to the object. The type of the handle is either same as that of the object or its super type (to support polymorphism).


In Java, only primitive data is allocated on the stack. Pointers to primitive data are not allowed. There are no C/C++ like pointers in Java. This was one of the core design ideas in Java - to simplify the language by eliminating pointer types.

Now we have well-defined terminology to understand argument passing and how they are implemented in C, C++ and Java.

Pass By Value

A function may pass a copy of local data on its stack to another function that it calls. This data is copied onto the stack memory of the callee. As obvious, changes made to the copy by the callee will not reflect back on to the original data in the stack memory of the caller. You cannot pass objects in the heap by value. And you don't need to! They can be accessed from any function as long as it has a direct or an indirect handle to these objects.

Pass By Pointer

A function may pass a pointer to a data in its stack or on the heap to another function. If the callee function, modifies the data through the pointer, the changes will be observed by the called function as it is the same data that gets modified. However, there is one subtlety. A pointer in itself is a first class data object in languages like C and C++ (unlike Java). In this case, the pointer is, in fact, passed by value. That is, a copy of the address in the pointer data is made for the callee. So if the callee modifies the value in the pointer data, it will not show in the caller's copy of the pointer data.

Pass By Reference

A function may pass a reference to data on its stack. In this case, under the hoods, the callee function gets direct access to a variable in the caller's stack memory. Any change made to the variable will reflect in the caller function. Since functions (in C, C++ and Java) can return only one data value, passing references is often used as a mechanism to have side effects in the caller's stack in order to mimic multiple data values being returned. (References to pointer data types can also be passed. As obvious, there is no such thing as pointer to references. References are not first class data values.)

Argument Passing in C

C supports pass by value and pass by pointer. You can pass data on stack by value or by pointer. You can pass pointers to data on the heap.

Argument Passing in C++

In addition to what C supports, C++ also supports passing references to data on the stack.

Argument Passing in Java

Java supports pass by value and pass by Java reference which can be thought of pass by value or pass by pointer, only that the pointer or the handle passed is not a full fledged pointer as in C or C++. It is a Java reference.

In Java, since primitive types can only be on the stack - they are passed by value. Objects which are only on the heap are not actually passed at all. A Java reference to them is passed and the callee gets to access the exact same object lying on the heap.

Tuesday, January 5, 2010

அகர முதல எழுத்தெல்லாம் ஆதி
பகவன் முதற்றே உலகு.

(01)

விளக்கம்:

அகர (அ) ஒலியே எல்லா எழுத்துக்களுக்கும் முதல்; அதுபோல, ஆதிபகவன் உலகிலுள்ள உயிர்கள் எல்லாவற்றிற்கும் முதல்வனாக இருக்கிறான்.


please go green and save our earth from global warming

Sam Walton (Founder of Wal-Mart) - Success in Retailing: 10 Rules for Building a Successful Business

Sam Walton 1918 - 1992

Sam Walton, the founder of Wal-Mart, grew up poor in a farm community in rural Missouri during the Great Depression. The poverty he experienced while growing up taught him the value of money and to persevere.


After attending the University of Missouri, he immediately worked for J.C. Penny where he got his first taste of retailing. He served in World War II, after which he became a successful franchiser of Ben Franklin five-and-dime stores. In 1962, he had the idea of opening bigger stores, sticking to rural areas, keeping costs low and discounting heavily. The management disagreed with his vision. Undaunted, Walton pursued his vision, founded Wal-Mart and started a retailing success story. When Walton died in 1992, the family's net worth approached $25 billion.


Today, Wal-Mart is the world's #1 retailer, with more than 4,150 stores, including discount stores, combination discount and grocery stores, and membership-only warehouse stores (Sam's Club). Learn Walton's winning formula for business.


Rule 1: Commit to your business. Believe in it more than anybody else. I think I overcame every single one of my personal shortcomings by the sheer passion I brought to my work. I don't know if you're born with this kind of passion, or if you can learn it. But I do know you need it. If you love your work, you'll be out there every day trying to do it the best you possibly can, and pretty soon everybody around will catch the passion from you ?like a fever.


Rule 2: Share your profits with all your associates, and treat them as partners. In turn, they will treat you as a partner, and together you will all perform beyond your wildest expectations. Remain a corporation and retain control if you like, but behave as a servant leader in your partnership. Encourage your associates to hold a stake in the company. Offer discounted stock, and grant them stock for their retirement. It's the single best thing we ever did.


Rule 3: Motivate your partners. Money and ownership alone aren't enough. Constantly, day by day, think of new and more interesting ways to motivate and challenge your partners. Set high goals, encourage competition, and then keep score. Make bets with outrageous payoffs. If things get stale, cross-pollinate; have managers switch jobs with one another to stay challenged. Keep everybody guessing as to what your next trick is going to be. Don't become too predictable.


Rule 4: Communicate everything you possibly can to your partners. The more they know, the more they'll understand. The more they understand, the more they'll care. Once they care, there's no stopping them. If you don't trust your associates to know what's going on, they'll know you really don't consider them partners. Information is power, and the gain you get from empowering your associates more than offsets the risk of informing your competitors.


Rule 5: Appreciate everything your associates do for the business. A paycheck and a stock option will buy one kind of loyalty. But all of us like to be told how much somebody appreciates what we do for them. We like to hear it often, and especially when we have done something we're really proud of. Nothing else can quite substitute for a few well-chosen, well-timed, sincere words of praise. They're absolutely free ?and worth a fortune.


Rule 6: Celebrate your success. Find some humor in your failures. Don't take yourself so seriously. Loosen up, and everybody around you will loosen up. Have fun. Show enthusiasm ? always. When all else fails, put on a costume and sing a silly song. Then make everybody else sing with you. Don't do a hula on Wall Street. It's been done. Think up your own stunt. All of this is more important, and more fun, than you think, and it really fools competition. "Why should we take those cornballs at Wal-Mart seriously?"


Rule 7: Listen to everyone in your company and figure out ways to get them talking. The folks on the front lines ?the ones who actually talk to the customer ?are the only ones who really know what's going on out there. You'd better find out what they know. This really is what total quality is all about. To push responsibility down in your organization, and to force good ideas to bubble up within it, you must listen to what your associates are trying to tell you.


Rule 8: Exceed your customer's expectations. If you do, they'll come back over and over. Give them what they want ?and a little more. Let them know you appreciate them. Make good on all your mistakes, and don't make excuses ?apologize. Stand behind everything you do. The two most important words I ever wrote were on that first Wal-Mart sign: "Satisfaction Guaranteed." They're still up there, and they have made all the difference.


Rule 9: Control your expenses better than your competition. This is where you can always find the competitive advantage. For twenty-five years running ?long before Wal-Mart was known as the nation's largest retailer ?we've ranked No. 1 in our industry for the lowest ratio of expenses to sales. You can make a lot of different mistakes and still recover if you run an efficient operation. Or you can be brilliant and still go out of business if you're too inefficient.


Rule 10: Swim upstream. Go the other way. Ignore the conventional wisdom. If everybody else is doing it one way, there's a good chance you can find your niche by going in exactly the opposite direction. But be prepared for a lot of folks to wave you down and tell you you're headed the wrong way. I guess in all my years, what I heard more often than anything was: a town of less than 50,000 population cannot support a discount store for very long.

Story of ORKUT

The story goes like this :

A guy lost his girlfriend in a train accident....

but the gal's name nowhere appeared in the dead list. This guy grew up n became IT technical architect in his late 20?s, achievement in itself!!. He hired developers from the whole globe and plan to make a software where he could search for his gf through the web.. Things went as planned... and he found her, after losing millions of dollars and 3 long years!!

It was time to shut down the search operation, when the CEO of Google had a word with this guy n took over this application, This Software made a whopping 1 billion dollars profit in its first year, which we today know as ORKUT and, The guy's name is ORKUT BUYUKKOTEN . Yes its named after him only. Today he is paid a hefty sum by Google for the things we do like scrapping. He is expected to b the richest person by 2009.

ORKUT BUYUKKOTEN today has 13 assistants to monitor his scrapbook & 8 tomonitor his friends-list. He gets around 20,000 friend-requests a day & about 85,000 scraps!!!

Some other Cool Facts about this guy:

* He gets $12 from Google when every person registers to this website.

* He also gets $10 when you add somebody as a friend.

* He gets $8 when your friend's friend adds you as a friend & gets $6 if anybody adds you as friend in the resulting chain.

* He gets $5 when you scrap somebody & $4 when somebody scraps you.

* He also gets $200 for each photograph you upload on Orkut.

* He gets $2.5 when you add your friend in the crush-list or in the hot-list.

* He gets $2 when you become somebody's fan.

* He gets $1.5 when somebody else becomes your fan.

* He even gets $1 every time you logout of Orkut.

* He gets $0.5 every time you just change your profile-photograph.

* He also gets $0.5 every time you read your friend's scrap-book & $0.5 every time

Well, the story seems to be ok … though the money he’s making out of it seems to be quite exorbitant and impractical …no doubt, it's quite impressive !!!

Founder of Mc.Donalds-Ray Kroc

Ray Kroc was the mastermind behind the worldwide McDonald's fast food franchise. He bought the fledgling restaurant chain in 1955 and grew it into the largest, most influential fast food chain in the world.

Ray Kroc was born on October 5, 1902 to Czech-Americans in Chicago, Illinois. At the age of four, Kroc's father took him to phrenologist, a person who determines fate based on the shape of someone's skull. The Phrenologist told young Ray Kroc that he would someday work in food service. But, as the first World War erupted, Kroc became interested in learning how to drive ambulances for the war effort instead. The war, however, ended before he had a chance to test his training and Kroc looked elsewhere for employment.

During the late 1950s, Kroc tried his hand at selling paper cups and even worked as a pianist for a short period of time before settling into a position as a milkshake machine salesman. He traveled around the country and sold milkshake machines to various different cafes and restaurants, all the while observing the layout and management of the industry. Kroc was convinced that many restaurants suffered from poor management and were not living up to their potential. It was during this time that he ran across a small hamburger restaurant in San Bernardino, California named McDonald's.

The restaurant, owned by the McDonald brothers, Richard and Maurice, ran eight of the same milkshake machines sold by the fifty-two year old Kroc. Since each machine could spin five milkshakes at once, Kroc was intrigued by the idea of a restaurant that needed the ability to make forty milkshakes at a time. He traveled to California and, upon seeing the orderly, efficient restaurant that served a huge community, Ray Kroc was convinced he could sell the machines to every McDonald store that opened.

In order to capitalize on the venture, Kroc approached the brothers with a business plan and they eventually settled on a deal. As a result of the partnership, however, Kroc would receive only 1.4% of the franchisees' profit, giving 0.5% to the brothers. It didn't take very long for Kroc to realize that his profit would be minimal. So, in order to gain access to more of his investment, Ray Kroc convinced the brothers to sell him the rights to the McDonald's name.

Kroc envisioned a restaurant that ran like a factory and produced hot food, fast service, and with consistent quality no matter where he opened a restaurant. He saw food preparation as a process and broke it down into steps that could be duplicated in any of his restaurants. This way he could keep the product the same no matter where the McDonald's was located.

Low franchise fees made it easy to open new stores but cut into any potential profits for Kroc. As a result, Kroc decided to purchase the land on which McDonald's would open and ultimately serve as a landlord. He set up the Franchise Realty Corporation in 1956 and was able to purchase tracts of land in order to help him produce a profit for his company. By 1960 there were over 200 McDonald's around the United States.

Kroc saw his franchise as a way to sell as service, not food. After all, Big Boy, Dairy Queen, and A&W were already established restaurant chains. Ray Kroc needed McDonald's to stand out. Consistency was the key and he made sure that every McDonald's ran the same. He established national advertising campaigns to support his restaurants and took the brand international in 1971 to Japan and Germany.

Ray Kroc died on January 14, 1984 of old age. At the time he was worth an estimated $500 million.