Tech Trends - Industry Articles

Why Java should be your first programming language

By Leor Zolman

Although I've been both a student and an instructor of many different programming languages, it has never been easy for me to recommend a first language to someone just starting in programming. Traditional "learning" languages, such as venerable old interpreted BASIC, are great for providing instant gratification -- try something, see what happens almost immediately. But, they also breed some nasty non structured coding practices that eventually require extra effort on the student's part to unlearn, for example, "You mean I'm not supposed to use goto anymore? Why not?"

When I was an M.I.T. computer science undergrad in the mid 70's, the first programming language they tried to teach us was Algol. I've ended up being rather glad about that, but for unique reasons:

  • I already knew how to program in about eight other languages at the time, so I didn't get too demoralized about the prospects for language evolution, and
  • I've been able to use Algol as a wonderful example (in my teaching of other languages) of how not to design a language's identifier scoping rules. This gives Algol the distinction of making C, C++ and Java actually look simple.

I've been teaching C and C++ for ten years now, but all the courses I've taught have included the prerequisite of prior programming experience in some other language -- even if that language was BASIC or COBOL. At least with BASIC and COBOL, you can't write code that crashes the machine because of a typo or knocks out phone service to half of New York due to a misplaced semicolon. If C and C++ let the programmer get away with more than he/she ought to be able to, we can always chalk it up to performance issues. We want our apps to run fast, don't we? Well, C and C++ remove all obstacles to ultra-efficient execution speed…along with most obstacles to horrendous runtime logic bugs.

Enter Java. While many think of Java as just another web-page enhancement tool, it is in fact a full-featured, robust, object-oriented and actually user-friendly application development language.

The combination of Java's robustness and object-oriented focus makes it, in my humble opinion, the best "first language" around right now, and the best language, overall, for a wide variety of applications.

Great Java features

  • Strongly typed variables
  • Exhaustive compile time and runtime consistency checks
  • No pointer bugs!
  • No memory leaks!
  • Automatic garbage collection

While C++ may be used in an object-oriented manner, it is actually a hybrid language that does not require or enforce the use of its OO features at all. In Java, you can't create a program without putting code into a class, and learning to think in terms of classes from the start is the only way to go. Non object-oriented programming will die out as systems become inherently more and more complex, and there's no turning back the clock on that complexity.

Java's robustness comes in the form of strongly typed variables and exhaustive compile time and runtime consistency checks. Java requires local variables to be initialized before they can be read, checks array subscripts for being out-of-bounds, and performs sanity checks on all "casting" (conversion of expression types) at both compile time and runtime.

The most common causes of severe runtime migraines to C/C++ programmers, pointer bugs and memory leaks, cannot happen in Java. There are no pointers in Java (the closest thing being an approximation to the C++ reference type), and all dynamic memory rendered inaccessible to an application becomes subject to automatic "garbage collection" when necessary. No programming effort required.

Thus, learning how to program in Java becomes mostly learning how to program, instead of worrying constantly about how to avoid the numerous ways to crash your C/C++ program with no hints forthcoming as to why it crashed. Once you've learned this language, you may very well find that it is powerful enough to do just about anything you want it to do. Although anything written in Java can be re written in C++ to run marginally faster, the effort required may be immense, and hardware CPU speed will increase by more than that in the next few months anyway, so why worry about performance?

There are many more reasons why Java is a wonderful language, and most of them are well-publicized (see JavaSoft's classic "White Paper" on Java). As I see it, most of these reasons make Java the perfect first programming language for the new millennium, and perhaps the best only programming language.

Please email comments on this article to: Leor Zolman.

About the author

Leor Zolman has been involved in system software development, system administration and applications development for over 25 years. He currently authors and teaches technical seminars in C, C++, Java and Unix.



STUDENTS
Student Downloads Student Downloads

INSTRUCTORS
Instructor Downloads Instructor Downloads
Login Login to Your Account
Request a Desk Copy Request a Desk Copy
Teach with Technology Teach With Technology
Events Events
Catalog Articles Catalog Articles

RESOURCES
Programming Series
Web Warrior Series