An Attempt To Make Java Easier To Learn
Written by Nikos Vaggalis   
Thursday, 20 April 2023

It's no secret that Java is not the favorite language of Coding Bootcamps. Now an OpenJDK proposal tries to change that by reforming the language's syntax itself.

jdklogo

In stark contrast to Bootcamps, Enterprises just love Java. Why is that?

Enterprises talked and still talk Java. Look no further than the Fortune 500 list of companies reliance on it. Yes, Blue Chips love it. The reasons are plenty.

The one that enterprises value most is backwards compatibility, being notoriously allergic to radical updates and upgrades. Systems that worked 20 years ago, written in Java 5, should be able to compile and run under version 8. Stability is what matters.

Bootcamps and College Programming 101 try to teach languages that are approachable to beginners such as Python and Javascript, which are easy to begin with and without having to get too deep initially, under a scheme of "show first and explain later". Then they're also easy to set up in order to run your first programs as fast as possible.

In contrast, to start writing code in Java, even a simple "Hello World" program


public class Main { 

public static void main(String[] args) {                         System.out.println("Hello World"); 

  }

}

requires you to understand the concept of Classes, Static modifiers, String data type, arguments and the need for method main. Then you need to know that System.out.println is a method that prints text to the console, with the "System" class being part of the Java standard library which provides access to the system resources, such as the standard input, output, and error streams.

In addition, the "out" field of the System class is an instance of the "PrintStream" class, which provides methods to print data to the standard output stream. The "println" method of the PrintStream class is used to print a string to the console followed by a newline character. 

Just mindblowing for a beginner!

This has to change if you want to bring fresh blood to the aging Java developer community. Now the new philosophy goes something like 'what if try to remove as much cruft as we can so we don't give a hard time to novices?'. And that is what JEP 445 "Flexible Main Methods and Anonymous Main Classes" will try to do.

Its goals are to:

  • Offer a smooth on-ramp to Java so that educators can introduce programming concepts in a gradual manner.
  • Help students to write basic programs in a concise manner and grow their code gracefully as their skills grow.
  • Reduce the ceremony of writing simple programs such as scripts and command-line utilities.
  • Not introduce a separate beginner's dialect of Java.
  • No not introduce a separate beginners' toolchain; student programs should be compiled and run with the same tools that compile and run any Java program.


According to it, the "Hello World" example above would become as simple as

void main() {
   System.out.println("Hello World");
}

omitting String[] and the Static modifier as well as making the Main class declaration implicit. Well that leaves "System.out. println" intact but at least taking the rest off can be considered as an improvement.

This, however, does not remove the fact that you still have to go about first compiling in order to invoke the program, having
first of all to setup a JDK on the student's machine. In contrast, interpreted languages like Python or Javascript allow you to just run it without compiling first. That's another boon for the beginners.

If you can't wait for the JEP proposal to be implemented in a forthcoming version of the JDK, you can introduce the language to the beginners under a REPL, which once an inherent property of the interpreted languages is now finding its way into compiled languages too with tools like Jshell.

A REPL is an interactive programming environment that takes single user inputs, executes them, and returns the result to the user; input (Read), execute the input (Evaluate), return the result to the user (Print), wait for the next input (Loop).

So what's the deal with it? It's all about the immediate feedback loop you get; you can enter program elements one at a time, immediately see the result, and make adjustments as needed. You can evaluate anything;variables, code blocks, functions, even define full-fledged classes and use them in the REPL console, always getting instant feedback, or even use C#/Java as a scripting language for testing purposes and running short lived utility scripts.

This comes in stark contrast with the typical workflow of working with a compiled language:

  1. Write a complete program.
  2. Compile it and fix any errors.
  3. Run the program.
  4. Figure out what is wrong with it.
  5. Edit it.
  6. Repeat the process.

Still this is not the "on-ramp programming model" the JDK Committee is looking for which is why this proposal has been made.

The full details of the proposal can be found on the official OpenJDK JEP index entry 445.

javaoraclelogo

 

More Information

JEP 445: Flexible Main Methods and Anonymous Main Classes (Preview)
 

Related Articles

Take Microsoft's Java For Beginners

Where's Java Going In 2022?

 

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

Banner


Remembering Grace Hopper On Her 114th Anniversary
09/12/2024

Today sees the start of Computer Science Education Week and  the 2024 Hour of Code. These educational event are timed to coincide with Grace Hopper's birthday on January 9th, 1906 due to her conc [ ... ]



Google Adds Premium Tier To Developer Program
29/11/2024

Google has added a premium tier to the Google Developer Program. The new tier is described as providing "a tailored suite of services to help developers throughout the learning, building and deploymen [ ... ]


More News

espbook

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Thursday, 20 April 2023 )