Question

I have a few doubts on java concepts:

  1. Is code reuse in java similar to using functions as defined in other programming languages like C?

  2. Is Java robust by nature or does it provide a way to write robust code ?

Can anyone explain the above two. I have read a few books and I did not get a clear picture

Was it helpful?

Solution

Code Reuse

I do like to point you to some links on this topic.

Some points about code reuse from the first link.

Code reuse, the most common kind of reuse, refers to the reuse of source code within sections of an application and potentially across multiple applications. At its best, code reuse is accomplished by sharing common classes or collections of functions and procedures. At its worst, code reuse is accomplished by copying and then modifying existing code. A sad reality of our industry is that code copying is often the only form of reuse practised by developers.

Robust

Quoted from Core Java, Volume I, Fundamentals.

"Java is intended for writing programs that must be reliable in a variety of ways. Java puts a lot of emphasis on early checking for possible problems, later dynamic (runtime) checking, and eliminating situations that are error-prone. . . . The single biggest difference between Java and C/C++ is that Java has a pointer model that eliminates the possibility of overwriting memory and corrupting data."

This feature is also very useful. The Java compiler detects many problems that, in other languages, would show up only at runtime. As for the second point, anyone who has spent hours chasing memory corruption caused by a pointer bug will be very happy with this feature of Java.

If you are coming from a language like Visual Basic that doesn’t explicitly use pointers, you are probably wondering why this is so important. C programmers are not so lucky. They need pointers to access strings, arrays, objects, and even files. In Visual Basic, you do not use pointers for any of these entities, nor do you need to worry about memory allocation for them. On the other hand, many data structures are difficult to implement in a pointerless language. Java gives you the best of both worlds. You do not need pointers for everyday constructs like strings and arrays. You have the power of pointers if you need it, for example, for linked lists. And you always have complete safety, because you can never access a bad pointer, make memory allocation errors, or have to protect against memory leaking away.

OTHER TIPS

If by "code reuse" you mean including other files from the same project: yes. Otherwise, no.

As for the second, Java is robust, as taken from here: http://java.sun.com/docs/overviews/java/java-overview-1.html:

Java: A simple, object-oriented, network-savvy, interpreted, robust,
    secure, architecture neutral, portable, high-performance, multithreaded,
    dynamic language.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top