Site icon JVM Advent

Pleading for Java

This post is based on an article I wrote almost 10 years ago in the GInfo Computer Science Magazine. I am surprised things did not change much since then. So, here I go again…
In Romanian high schools the programming languages used or teaching Computer Science are Pascal and C++. In college, the students learn other programming languages they might need in order to become software engineers. Unfortunately, this is true only from a theoretical perspective. Most Romanian software engineers claim they had to learn by themselves…
Imagine a junior high school student who’s dream is to become a software engineer. He starts by learning how to implement more and more complicated algorithms (using the above mentioned languages) and then also learns something about databases.
When she graduates from high school, she realizes show know nothing useful. She knows how tosolve many problems, but she has no idea how to create a simple application with a friendly user interface. She decides to go to college so that she can learn more…
Therefore, the student must go to college because she does not learn enough in high school. In my opinion, a high school graduate should be able to a software engineer without a college diploma. She should not be one of the best, but she should be able to join the crowd. Why? Because it is possible. There are many college students that work as programmers while still studying and there are also enough experienced programmers that do not have a University degree. Of course, they learn by themselves, but they learn. Therefore, it is possible!
About 20 years ago, high school students started by learning QBasic. Someone decided this cannot go on and, at some point, the first programming language was Pascal. A few years later the C language was introduced as an alternative to Pascal.
Things changed, so change is possible. Was it hard? Yes! Why? Because it will be harder for the kids to learn Pascal then it was to learn Basic. This was the official answer. Unfortunately the real answer was something like: it will be harder for the teachers to teach Pascal then it was to teach Basic. But, this was changed. The Basic language was forgotten; Pascal and C were introduced. Then, someone came with the idea to start with C. To war between Basic and Pascal was replaced by a war between Pascal and C. Why? Because it will be harder for the kids to learn C then it was to learn Pascal.
I remember that a computer science teacher said that a math teacher graduates from college and is able to teach math for the next 50 years without having tolearn anything new. The two teachers have the same salary. Therefore, why should the computer science teacher have to learn new things. Because she teaches computer science, not math (I would say)!
Anyway, another small (half)step was made. The programming language was no longer specified in the curricula. The teacher may choose Pascal or C or something else (Algol, Fortran, Java, C# or anything else comes to mind). Again, the theory is nice. In practice, for the Maturity exams at the end of high school, the solutions must be written in Pascal or C.
These were useful steps (or half-steps), but it is not enough. The current curricula creates several stars (who win medals in international olympiads) and many unknowledgeable student who cannot say what’s the difference between sorting an array and finding the last digit of a number. And… so what? Someone will teach them to draw some nice user interfaces using Delphi and they will become software engineers.
I think the effort to teach algorithms to all computer science students is useless. Algorithms might be necessary, but it is more important to know a modern programming language.
Let’s see now why it is more difficult for a student to learn Java rather than C or Pascal. The for is still a for, the while is still a while, the if is still an if. Therefore, the control structures that must be explained are the same. The subroutines are also the same. Some claim the Java syntax is more difficult. Might be, but it is practically identical to the C++syntax. But, we have objects in Java and the teacher must explain difficult concepts like inheritance, polymorphism etc. Does she really have to? Of course,but not from the beginning.
The teacher can start without adding anything complicated without adding anything to the current style. Then, object oriented paradigms can be added. I think people someone is missing an important point: at the beginning, the student know nothing. Why should we believe it is easier for the student to learn structured programming rather than object oriented programming? The only reason is: we think structured programming is easier. I am confident that the engineers that know both techniques have no problem using any of them. They do not think one of them is easier than the other. They both have some basic things that must be understood.
I claim that it is not more difficult to understand the object oriented paradigms and they are more useful. Why aren’t they more difficult? Because the student knows nothing. She is not accustomed to work based on some principles; the teachers are… Any new things can be assimilated; it all depends on the talent of the teacher.
I will now try to show that the Java language is a viable alternative. First of all, Java is a language that was accepted by the software engineer community. It is not just a trendy language that will disappear in a few years. There are many Java technologies that are developed based on the core language. Even if one cannot expect JSP or hibernate to be thought in high school, the student will be able to easily learn all these technologies if she knows the Java basics. Java is an object oriented language. Most languages actually used for developing software are object oriented. If one knows such a language, it will be easy to learn the others (when needed).
Please allow me to present some examples that will show how good the “coffee” actually is.
Operations with big integers are a pain for all students that take part in programming competitions. In most contests there is at least a problem that needs the implementation of such operations. If dividing is necessary, everything turns into a nightmare.
By using Java we do not have this problem. Someone already implemented these operations and we only have to use the already written code. The following example shows how easy it is to use big integers:
import java.math.BigInteger;
public class BigIntegers {
  public static void main(String[] args) {
    BigInteger a = new BigInteger(“2458”);
    BigInteger b = new BigInteger(“13”);
    System.out.println(a + ” + ” + b + ” = ” + a.add(b));
    System.out.println(a + ” – ” + b + ” = ” + a.subtract(b));
    System.out.println(a + ” * ” + b + ” = ” + a.multiply(b));
    System.out.println(a + ” / ” + b + ” = ” + a.divide(b));
    System.out.println(a + ” % ” + b + ” = ” + a.remainder(b));
  }
}
But it does not stop here. We have operations for decimal numbers too:
import java.math.BigDecimal;
public class BigDecimals {
  public static void main(String[] args) {
    BigDecimal a = new BigDecimal(“2458”);
    BigDecimal b = new BigDecimal(“13”);
    System.out.println(a + ” + ” + b + ” = ” + a.add(b));
    System.out.println(a + ” – ” + b + ” = ” + a.subtract(b));
    System.out.println(a + ” * ” + b + ” = ” + a.multiply(b));
    System.out.println(a + ” / ” + b + ” = ” + a.divide(b, 5, BigDecimal.ROUND_DOWN));
  }
}
One may say that, given a few hours, an engineer would have implemented all that. That might be true, but it would be a couple of wasted hours. But, Java allows us to save days or even months in some cases. How long do you think it would take you to implement the compressing of a regular file into a zip file? You would probably need a few days just to study the format of the zip file.
I think the next sequence of code needs no further comments:
import java.util.zip.ZipOutputStream;
import java.util.zip.ZipEntry;
import java.io.FileOutputStream;
import java.io.FileInputStream;
public class ZIP {
  public static void main(String args[]) throws Exception {
    ZipOutputStream zo = new ZipOutputStream (new FileOutputStream(“myfile.zip”));
    ZipEntry e = new ZipEntry(“myfile.txt”);
    zo.putNextEntry(e);
    FileInputStream in = new FileInputStream(“myfile.txt”);
    byte b[] = new byte[16384];
    int i;
    while ((i = in.read(b)) > 0)
      zo.write(b, 0, i);
    zo.flush();
    zo.closeEntry();
    zo.close();
  }
}
Like I stated 10 years ago, I will not draw any conclusions. I am waiting for other opinions…
P.S.
I apologize for my English. It is not what it should be… 🙂

Meta: this post is part of the Java Advent Calendar and is licensed under the Creative Commons 3.0 Attribution license. If you like it, please spread the word by sharing, tweeting, FB, G+ and so on! Want to write for the blog? We are looking for contributors to fill all 24 slot and would love to have your contribution! Contact Attila Balazs to contribute!

Author: gpanther

Exit mobile version