Making Java Easier For The Beginner |
Written by Mike James | |||
Monday, 12 May 2025 | |||
Java is an intimidating language for the complete beginner, but now there is hope of simplification in the recently proposed JEP512. And the fact that it is 512 must count for something - right? You can argue that one of the big attractions of Python is that you can ignore the fact that it is object-oriented or even that it has functions. In Python Hello World is just: print("Hello World") In fact it is so short and simple that you could argue that it is too simple and doesn't give any hint as to what is to come. Even so, Python is regarded as a language that you can start at an easy level and gradually add the extra bits you need to build a sophisticated program and I suppose to become a sophisticated programmer. The point is that programming in the large, which is what Java is designed for, is not the same as programming in the small. Java is all about classes and objects and ways they can interact. Programming in the small is what you do when you are first learning to program and it involves writing procedural code and your concerns are variables, flow of control and - eventually - functions. Classes and objects only make an appearance when you need to find a way to organize your larger programs. Now compare a simple Java Hello World to Python's: public class HelloWorld { There is a lot here that the beginner is going to struggle to understand and indeed most of the time the whole thing is just wished away with a "you don't need to know about that". But even if the beginner is wimpy enough to accept the boilerplate, they generally can't help but ask what System.out.println is all about? The problem is that all of the boilerplate is about programming in the large and has nothing to add to the simple Hello World in the small. If JEP512 gets implemented the Hello World could be written: void main() { IO.println("Hello, World!"); } Almost as simple as the Python version and certainly as simple as the equivalent in C++. To make this work, JEP512 has to introduce the idea of a compact source file. With this, when the compiler encounters a source file that has code not enclosed in a class it will assume it is dealing with a compact source file and it will implicitly declare a class that has the functions and variables as its methods and fields. Notice that this means that the beginner can define functions with a compact source file and call them without having to worry about classes and methods. It also drops the need to use static and to deal with a command line parameter. The simplification of the output function call is courtesy of the new IO class with five static methods: public static void print(Object obj); public static void println(Object obj); public static void println(); public static String readln(String prompt); public static String readln(); The beginner still has to use a qualified name, but it is only IO.print rather than a three-part name. This isn't such a problem and they are going to have to learn that other functions have to be called with a prefix as well - e.g. Math.sin(x). What is more, the IO class lives in java.lang and so it doesn't have to be explicilty imported and it can be used in standard source code files. It is a small change, but it could make a big difference when trying to select a programming language to use to introduce beginners to the art. More InformationCompact Source Files and Instance Main Methods Related ArticlesAn Attempt To Make Java Easier To Learn 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.
Comments
or email your comment to: comments@i-programmer.info |
|||
Last Updated ( Monday, 12 May 2025 ) |