Respond to the following and if appropriate include personal

Respond to the following, and if appropriate, include personal experience as part of your answers.

When you go to the grocery do you buy the store brand? Will you buy a knock off brand? What is the difference between these kinds of copies and a Java generic?
What if you ordered a BIG program for your company? The software company building it decided that you would pay for it by paying for each line of code written. Their cost would be $50.00 per line of fully implemented, tested code. What do you think about them using generics in this process? Should you pay for generics differently than you pay for code that does not use generics?

Solution

Every software project will have some errors even after a lot of careful planning, programming and all kinds of necessary testing was done. We usually say that the sofware is bug free. This doesnt mean that it is 100% bug free. This problem becomes more when the software is being updated or its complexity increases.

We generally make some mistakes like when we are supposed to enter the string type data we may end up with entering a number unknownly. As a result the expected results may not occur. Now to avoid such errors the software should explicitly say which type of data to be entered and should raise an exception when we do such errors.

For this we use Generics. By adding generics to our code, it becomes stable. This can be done by adding generic enabled types to the code ie generic enables classes, interfaces and methods. These can be declared using angular braces < and >

For example:

public static <A> void showArray( A[] )

{

....

}

When we declare an array of type generic this means that we can use this of any datatype ie either int or float or double or char or any desired type. We can be able to enter only a specific type.

The code with generics would be more stable that the code without generics.

Respond to the following, and if appropriate, include personal experience as part of your answers. When you go to the grocery do you buy the store brand? Will y

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site