The Good and the Bad of Java Programming
Want to learn more about some of the basic advantages and disadvantages of Java programming? Click here to learn more about the impact of Java.
Join the DZone community and get the full member experience.
Join For FreeThere are not many technologies that can brag about staying relevant for more than 20 years. But this year, Java was voted the 5th most popular technology, eclipsed only by undisputed leaders JavaScript, HTML, CSS, and SQL. While it’s 18th on the list of most loved in the same StackOverflow survey, it’s also down the list in its most-dreaded ranking. Today, we unravel the many successes and challenges of Java — the time-honored technology with the iconic steaming cup-of-coffee logo, a language near and dear to many programmers' hearts.
What Is Java Programming: History and Impact
Java is a general-purpose programming language that follows the object-oriented programming paradigm and the "Write Once, Run Anywhere" approach. Java is used for desktop, web, mobile, and enterprise applications. You can out find out more about it here:
- Java downloads
- Java documentation
- Oracle Java community
- JavaWorld — popular portal for all things Java
- JavaRanch — forums for Java developers
Java is not only a language but an ecosystem of tools covering almost everything you may need for Java development. This includes:
Java Development Kit (JDK) – with that and a standard Notebook app, you can write and run/compile Java code.
Java Runtime Environment (JRE) — this is a software distribution tool containing a stand-alone Java Virtual Machine, the Java standard library (Java Class Library), and a configuration tool.
Integrated Development Environment (IDE) — this is a set of tools that help you run, edit, and compile your code. IntelliJ IDEA, Eclipse, and NetBeans are the most popular amongst them.
Java can be found anywhere you look. It’s the primary language for Android development. You will find it in web applications, governmental websites, and big data technologies, such as Hadoop and Apache Storm. And, it’s also a classic choice for scientific projects, especially natural language processing. Java was dominating mobile even in pre-smartphone days. The first mobile games in the early 2000s were mostly made in Java. So, it’s fair to say that Java, thanks to its long history, has earned its place in the Programming Hall of Fame. TIOBE index, one of the most reputable programming rankings in the world, uses search engine results for calculation. Despite the growing popularity of Go and Python, Java has remained at the top of the list for more than a decade.
TIOBE Index data as of August, 2018
It all started in the early 1990s, when the Sun Microsystems team began developing a better version of C++ that was easily portable, novice-friendly, and enabled with automated memory management. The research resulted in the creation of an altogether new language, and the name was picked from dozens of others yelled out in the meeting room. Today, the logo of a steaming coffee cup is the silent, universally recognizable symbol of programming. And, it’s no longer clear what came first — the programmers’ obsession with caffeine or associations with Java, which are now synonymous with coffee.
These are just some of the changes Java introduced to the programming world:
Flexibility. Java proved that C’s procedural, manually-allocated, and platform-dependent code wasn’t the be-all and end-all. Thanks to Java, more people started adopting object-oriented programming, a commonly-accepted method today.
Applets. In the years before JavaScript, Java introduced applets, small web programs that provided interactive elements, especially useful for visualization and teaching. Although they were never used for anything more than simple animations, it’s what captured the attention of many programmers and paved the road for the development of HTML5, Flash, and, of course, JavaScript.
Test-driven development. With Java, TDD was no longer an experimental practice, but the standard way to develop software. The introduction of JUnit in 2000 is considered one of Java’s biggest contributions.
Benefits of Programming in Java
Though no longer the only officially supported language for Android development and, of course, far from the only choice for web programming, Java keeps pace with the alternatives. And, since that’s not only thanks to its respectable age, let’s explore some of the advantages Java has to offer.
Object-Oriented Programming
Java embraces object-oriented programming (OOP), a coding concept in which you not only define the type of data and its structure, but also the set of functions applied to it. This way, your data structure becomes an object that can now be manipulated to create relationships between different objects.
In contrast to another approach — procedural programming — where you have to follow a sequence of instructions using variables and functions, OOP allows you to group these variables and functions by context, thus, labeling them and referring to functions in the context of each specific object.
Comparing procedural programming and object-oriented programming
Why Is OOP an Advantage?
- You can easily reuse objects in other programs
- It prevents errors by having objects hide some information that shouldn’t be easily accessed
- It makes programs more organized and pre-planned, even the bigger ones
- It offers simple maintenance and legacy code modernization
High-Level Language With Simple Syntax and a Mild Learning Curve
Java is a high-level language, meaning that it closely resembles the human language. In contrast to low-level languages that resemble machine code, high-level languages have to be converted using compilers or interpreters. This simplifies development, making the language easier to write, read, and maintain.
Writing Hello World in Java
Java derived its syntax (set of rules and structure used by programmers) from C++, which is why you will notice that it closely resembles C code. However, it’s much simpler, allowing beginners to learn the technology faster and code more effectively to achieve specific results.
Java may not be as beginner-friendly as Python, but any developer with a basic understanding of frameworks, packages, classes, and objects can grasp it pretty soon. It’s straightforward, strongly-typed, and has very strict expectations that soon help guide your thinking in the right direction. Besides, tons of free online tutorials and courses won’t keep a novice helpless.
Standard for Enterprise Computing
Enterprise applications are Java’s greatest asset. It started back in the 90s when organizations began looking for robust programming tools that weren’t C. Java supports a plethora of libraries, which are the building blocks of any enterprise system, that help developers create any function a company may need. The vast talent pool also helps. Java is a language used as an introduction to computer programming in most schools and universities. Besides, its integration capabilities are impressive, as most of the hosting providers support Java. Last but not least, Java is comparatively cheap to maintain, since you don’t have to depend on a specific hardware infrastructure and can run your servers on any type of machine you may have.
Shortage of Security Risks
You may encounter the notion that Java is a secure language, but that’s not entirely true. The language itself doesn’t protect you from vulnerabilities, but some of its features can save you from common security flaws. First, compared to C, Java doesn’t have pointers. A pointer is an object that stores the memory address of another value that can cause unauthorized access to memory. Second, it has a Security Manager, a security policy created for each application where you can specify access rules. This allows you to run Java applications in a “sandbox,” eliminating risks of harm.
Platform-Independency (Write Once, Run Anywhere)
Write Once Run Anywhere (WORA) is a popular programming catchphrase introduced by Sun Microsystems to describe Java’s cross-platform capabilities. It meant you could create a Java program on, let’s say, Windows, compile it to bytecode, and run the application on any other platform that supports a Java Virtual Machine (JVM). In this case, a JVM serves as an abstraction level between the code and the hardware.
How WORA approach works in Java
All major operating systems, including Windows, Mac OS, and Linux, support the JVM. And, unless you’re writing a program that relies mostly on platform-specific features and UI, you can share — maybe not all — a big chunk of bytecode.
Distributed Language for Easy Remote Collaboration
Java was designed as a distributed language meaning that it has an integrated mechanism for sharing data and programs among multiple computers for improved performance and efficiency.
Distributed computing vs parallel computing
Unlike other languages, where you have to use external APIs for distribution, Java offers this technology at its core. Java-specific methodology for distributed computing is called Remote Method Invocation (RMI). Using RMI allows you to bring all Java benefits, such as security, platform-independence, and object-oriented programming, to distributed computing. Apart from that, it also supports Socket Programming and the distribution methodology of CORBA for sharing objects between programs written in different languages.
Automatic Memory Management
Java developers don’t have to worry about manually writing code for memory management tasks, thanks to automatic memory management (AMM), also used in the Swift programming language, and garbage collection, an application that automatically handles allocation and deallocation of memory. What exactly does it mean?
A program’s effectiveness is directly linked to memory. And, memory is limited. By using languages with manual management, developers risk forgetting to allocate memory, resulting in increased memory footprint and lagging. A garbage collector can locate objects that are no longer referenced by your program and remove them. Despite the fact that it affects your program’s CPU, you can reduce or prevent it with smart optimization and tuning.
Multithreading
In programming, a thread is the smallest unit of processing. To maximize utilization of CPU time, Java allows you to run these threads simultaneously — in a process called multithreading.
Threads share the same memory area, so switching between them takes little time. They are also independent, so if one thread faces exception, it doesn’t affect other threads. This is especially useful for gaming and animation-heavy programs.
Multithreading example
Stability and Massive Community
Java has survived to a respectable age, thanks to the community, Oracle’s support, and the cornucopia of applications and languages that keep running on JVM. Besides, new versions of Java are regularly released with new, interesting features.
Java’s developer community is also unmatched. About 45 percent of StackOverflow 2018 survey respondents use Java. It has an extremely large ecosystem of well-tested libraries and frameworks for any use case. Java is most likely to be one of the first languages beginning developers encounter in their studies, as there are 1000+ Java-related courses on Udemy and 300+ on Coursera.
Drawbacks of Programming in Java
Here are the cons you want to know before writing your next project in Java.
Paid Commercial License
Oracle recently announced that they will start charging Java SE 8 for “business, commercial, or production” use starting in 2019. To get all new updates and bug fixes, you’ll need to pay by the number of users or per processor.
Today, the current version of Java is free and available for redistribution for general purpose computing. To prepare for the change, each company has to evaluate how much of Java they use and seek an alternative technology if the price upgrade promises to be too painful.
Poor Performance
Any high-level language has to deal with poor performance due to the compilation and abstraction level of a virtual machine. However, it’s not the only reason for Java’s often criticized speed. Take garbage collector, a useful feature that unfortunately can lead to significant performance problems if it takes more than 20 percent of CPU time. Bad caching configuration can also cause excessive memory and garbage collection usage. There are also thread deadlocks that happen when several threads are trying to access the same resource, and — every Java developer’s nightmare — out-of-memory errors. Although each of these problems can be prevented with skillful planning, they do add up and can cause different volumes of damage.
Far From a Native Look and Feel on the Desktop
To create a program’s graphical user interface (GUI), developers use different language-specific tools. Thus, for Android apps, there’s Android Studio that helps create apps that look and feel native. However, when it comes to desktop UI, Java noticeably lacks.
There are a few GUI builders Java programmers can choose from: Swing, SWT, JavaFX, JSF being the most popular. Swing is an old-but-reliable, cross-platform, and already-integrated GUI builder with various Java IDEs, including Eclipse and NetBeans. But, unless you’re using templates, you’ll notice interface inconsistencies. SWT uses native components, but it’s not suitable for complicated UI. JavaFX is clean and modern-looking, but it’s not very mature. Overall, choosing a good fit for your GUI building on Java requires additional research.
Verbose and Complex Code
When the code is verbose, it means it uses too many words. While it may seem an advantage when you’re trying to understand the language, long, over-complicated sentences make code less readable and scannable. By trying to emulate English, many high-level languages tend to make too much noise. Java, created to tone down the unapproachable C++, forces programmers to type exactly what they mean, which makes the language more transparent to non-experts but, unfortunately, less compact.
If we compare Java to its rival Python, we can see how clear Python code appears — it doesn’t require semicolons and uses “and,” “or,” and “not” as operators instead of Java’s “&&,” “||,” and “!” Generally, Python has fewer bells and whistles, such as parentheses or curly braces.
Java vs Python code
Conclusion: Where Is Java Used?
Most organizations use Java in one way or another. A wide range of use cases makes these applications almost invisible, which is why the question “where to use Java” is often raised. To finish our overview, let’s see which domains can be covered by Java:
Android apps. Despite Kotlin’s invasive growth, Java is still the de facto language for Android apps, which automatically turns a big pool of Java developers into Android programmers. While Android uses Android SDK instead of JDK, the code is still written in Java.
Software products. Apart from already-mentioned Hadoop and Apache Storm, Java was used to create Eclipse, OpenOffice, Gmail, Atlassian, and more.
Finance programs. Being one of the most demanded language skills in the financial industry, Java is used both on the server- and client-side to build reliable, fast, and simple websites. It’s also a preferred language for data simulations and modeling.
Point of sale systems. Many businesses use Java to create PoS systems, as they usually require platform-independency and a vast talent pool.
Trading applications. Murex, a popular bank management program for front and back connectivity, is written in Java.
Big data programs. Hadoop is written in Java. Scala, Kafka, and Spark use JVM. Also, Java gives you access to tons of tried-and-tested libraries, debuggers, and monitoring tools.
This article was originally published at AltexSoft's blog, "The Good and the Bad of Java Programming."
Hope you enjoyed!
Published at DZone with permission of Maryna Ivakhnenko. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments