Kids Coding: Simple Java

Moving Beyond Blocks

I recently got my son (9) started on “real” programming with text files and the command line. Here are some notes about that. It’s still early in this experiment so I can’t claim that it’s a great idea, but its kind of working so far. There are so many web sites and product to get kids started in programming, but very little to move them past the basics into something more expansive. They risk getting obsessed but not then staying obsessed.

I learned programming because that is what you did with computers when I was a child. I kept learning programming because I could make the computer do new and interesting things. The problem now is that computers do amazing things without any programming and it requires massive experience and effort to achieve equally impressive results. So we must create a simpler environment which lets the child feel good about creating and understanding something more straightforward. It should be a path to real programming, not another island in a chain.

My son still hadn’t done much real text-based programming other than some playing with inside the IDE (which I also recommend) and some Python in CodeCombat. He had previously played a bit with Scratch and Lego Wedo, Hour of Code, Open Roberta (really good if you have the Lego Mindstorms education kit) and Tynker. He’s also done some Lego Mindstorms, but I think that’s an awful programming experience, at least with the non-education kit.

I’ve chosen Java, reluctantly, because I am familiar with it, it’s forgiving and convenient enough, and its language constructs (for loops, functions, etc) are enough like other C-like languages that the experience should be generally transferable. It’s far from ideal, but helps a little.

I love C++, but it’s clearly not suitable as a first text-based programming language. Neither is C, though I can imagine us trying that sometime. I think Python and Go are worth considering, but Python’s loose type system frustrates me personally and Go doesn’t seem quite mainstream enough.

However, if there is a simple language that you enjoy, whatever it is, I suggest that you use it with your kids. You must have enthusiasm to share and you must help them move past frustrations. If solving problems in the language doesn’t feel interesting to you then it probably won’t seem interesting to them. The overall aim here is to share your own love of programming by rediscovering how you learned programming yourself.

Using the Command Line

First I introduced the Linux command line, presenting it as where the real power is, where you can see and control what’s happening under everything else. (Yes, I know. Nevermind.) I kept is simple, just talking about directories and editing text files. We only covered:

  • Opening the terminal.
  • Seeing where you are with pwd.
  • Seeing what is there with ls.
  • Moving into a directory with cd.
  • Moving back with “cd ..”.
  • Opening a text file with gedit, from the terminal.
  • Using & so we can continue using the terminal after opening the file in gedit.
  • Running our program from the terminal.

Hiding the Boiler Plate

I wanted to mimic the experience of programming in simpler times, or of simple scripting today. At least at first, I wanted us to just write commands into a text file and just run the resulting program, without worrying about main functions or having a parent Java class, without  separate compilation and execution steps, and just using a Println() function instead of System.out.Println(). This let us avoid discussion of functions or classes until later.

I put this in my .bash_aliases file:

processing-run() {
    $HOME/processing/processing-java --sketch="$1" --run

so we can just run a program like this:

$ processing-run add

which runs the program in add/add.pde.

The .pde file just contains Java code, but not in any function and not part of any class (’s “static mode”). However, as soon as you want to implement your own function, you’ll have to put the rest of your code in a void setup() method (’s “active mode”), still not part of any class.

Using for this is a bit awkward, so I’m open to more suitable Java-like environments.

Doing Something Useful But Simple

I wanted to gradually explore simple programming techniques such as variables and loops, so I needed something that would just manipulate inputs and provide useful outputs.

I’ve chosen to gradually develop little programs based on the arithmetic techniques kids often learn in school. For instance, they learn an algorithm to add large numbers together using a carry – they just don’t call it an algorithm. They also learn long multiplication and long division, which add layers of complexity. As a bonus, this can demystify the magic that school requires them to repeat.

For instance, this commit history shows how we gradually wrote and improved a little program to add numbers (as strings). It’s missing the really basic code we started with. I used it to introducing new programming ideas along the way, such as:

  • Using variables.
  • Writing strings with quote marks.
  • Looping over the characters in a string (and backwards), particularly with the awkward for loop syntax.
  • Text output (standard out)
  • Discovering the length of a string instead of hard-coding it, to make the code more general.
  • ASCII Character codes. (Ignoring full Unicode for now.)
  • Getting a number (0, 1, 2, …) corresponding to a character (‘0’, ‘1’, ‘2’, …). Talking about types.
  • Using variables and manipulating them. For instance, adding the two numbers for two digits from two “numbers in strings”.
  • Variables in the loop and variables outside the loop. Some variables’ values are forgotten at the end of each time the loop is run, and some values are kept and used the next time.
  • Conditionals with if.
  • Putting code into functions and calling it.
  • Making functions take parameters, to make them more generally useful.
  • Calling functions from functions.
  • Passing an array instead of several parameters of the same type, to make the function more general.

You soon end up with a bunch of code that is big enough to seem overwhelming to a child. So every now and then I printed the code out so we could discuss it together. We talked about ideas such as variables, and setting variables, about functions, function parameters, and how to call functions, marking places in the code code with colored pencils.

Version Control

Programming is an iterative, experimental, activity. So I think version control should be introduced early as long as you can keep it simple.

We wrote the code at the same time on our own computers while sat next to each other. I checked in the changes to GitHub because they don’t allow users younger than 13. Seeing the changes, and their descriptions, should help kids remember the learning experience and remind them where they are on the path they’ve takhen. But it’s a real shame that kids can’t really own their coding history on GitHub, even privately.

16 thoughts on “Kids Coding: Simple Java

  1. Thanks for the insights! Although I still have a few more years until my sons will start programming, I am always interested in these stories as my wife is a teacher and I am always thinking about how to get children interested in coding.

    One question, though: have you any ideas or insights in how to improve the programming experience for children who do not speak and write English? Especially for German children? I am asking since you are also living in Germany (well, Bavaria, but I’ll accept it …) and may have had some experiences with some tools?

    1. Hour of Code is available in German and is generally great for getting kids started. That means that the command blocks are translated as well as the instructions. However the videos are not translated, which is confusing for non-English-speaking kids.

      Scratch is translated too, I think. Tynker is only in English, I think.

      Unfortunately, when it comes to “real” programming, I think we just have to accept that they have to learn a few English words such as for/while/func/let/var/class/struct/. I can’t think of any mainstream programming languages whose keywords and APIs were translated. Applescript had it, I think, but that’s hardly popular now, and the translation felt weird.

    2. I’m German, too, and I learned to code (partly by instruction from my uncle, later from books) before I had English at school (age 9 or 10; though nowadays they learn English already in elementary school). Frankly, I don’t think it matters at all. You just learn the keywords and get started. As soon as you need to read API docs or StackOverflow threads, I think it can actually help with learning English: not so much because either of these are brilliant works of literature but because it creates an understanding that the English class is worth paying attention to. Personally, my grades in English went from mediocre to top-of-the-class just around the time when I got internet in my room.

      As for the programming language, I personally started with Javascript. I did some HTML before, so Javascript allowed me to turn the websites that I created interactive. Quite some time has passed and today it may not be as “magic” to see dynamic content on a web page as it was in the late 90ies… Still DOM manipulation provides a simple way to *do* something in the code beyond bare command line interactions. From there on, I went down a very similar route, also writing code for string arithmetic or prime factor decomposition (which we had in maths class at the time. I tried very hard to come up with a more efficient algorithm than my naive one because it got really slow for large numbers; I only learned about NP-hardness much later). I still have all of these little Javascript programs and I look through them every now and then when I feel nostalgic ;) Another advantage of Javascript is that you don’t need all of that boilerplate that Java has.

      1. Thanks for the suggestions. Unfortunately, for children at this age (or just for their parents) using the web is awkward in general anyway. I am terrified enough already of kids exploring the web together. I do suspect that understanding how the Internet works technically could later be a real help in understanding how to behave on the Internet.

    3. We are doing some Kids Coding in Hamburg. These are starting lessons for kids at the age of 8. If you want to know more about it, you can contact me. :-)

      Cheers, Uwe

  2. Just curious, what in particular made you ditch C++? Templates? The STL?

    It seems to me that C++ can be kept relatively simple for beginners. The whole model in Java is clearly simpler, but it also requires you to fiddle with classes early – which I can see you had to fight.

    I’m currently thinking I’m going to try Python or perhaps Javascript, in case my children end up being interested in these sort of things.

    1. C++ is just a far bigger language than Java. There would be far more of the language to ignore and there would be almost no code or APIs in books or websites that a beginner (having learned a super-simplified version) could understand.

      You can learn only the basics of Java and still have a pretty good idea what most snippets of Java code are doing.

  3. “The problem now is that computers do amazing things without any programming and it requires massive experience and effort to achieve equally impressive results.”

    Oh man. So true. Back then we’d be happy if little lights lit up in the sequence we programmed them to and now they (kids) expect these things to read our minds.

    Back then we’d grovel for some time with the computer to learn how it works. Today they expect that the majority of the day they’ll be able to use the computer and when they do it’s to watch YouTube videos.

    Unless the kid is a real nerd the only way to entice them with learning programming is if you make it sexy and make it a means to an end. E.g. if you learn to program then maybe one day you can create a company and make a billion dollars like Mark Zuckerberg.

  4. I was successfull getting students interested in computer careers by starting them out with LiveCode, then Python and Java. The hook was programming their own games, apps and useful programs. We did A.I., modifying photos/pixels, school apps, BigData and other great projects. The key was starting with LiveCode (e.g. a HyperCard descendent) LiveCode is object-oriented, graphical interface but text-based programming. It has plain English, simple context and easy to learn but powerful with over 2,000 commands and behaviors.
    You are welcome to use my website and the lessons/projects- like or

  5. I can second Prusko’s advice. After years of teaching high school science I found myself (some years ago) teaching an elective programming class; we built web programs via PHP/MySQL. This was successful because kids could invite their friends to go on the web and explore the program. LiveCode extends this access…LiveCode scripts can compile into software for HTML5, Android, iOS, Linux, Windows, Mac. So parents can load the student-created app on their smart phone…demo and brag about how smart their kid is. This public attention is an important motivator for young people. LiveCode was developed in Scotland and is popular in the UK…not so much in the US. Prusko’s site has great resources for educators.

    1. You have to meet the students in the digital world they now live in. Being able to create your own game or an app for your phone is more useful, fun and productive than what you do in traditional languages. They also learn more real programming and computer concepts without the obstacles of syntax, vocabulary and undue complexities ( ). It is rewarding to see students to get excited about programming and being amazed by what they produce.

  6. For a simple Java editor may I suggest BlueJ version 3.17

    Whilst the upcoming BlueJ 4 isn’t quite as nice, 3.17 provides a nice introduction to OOP with the main project window showing a inheritance graph

  7. I think Processing is under appreciated. Daniel Shiffman is a huge proponent and is entertaining. He has 2 readable texts and many videos. I used Processing (Java based) this year with a group of students who had dropped out of mainstream education. They were doing text based programing with immediate visual results. Check:
    The IDE is easy for beginners.

  8. Concerning teaching kids how to code (e.g. in German and a few other languages), just a few more words on Open Roberta Lab:
    It’s a free open source cloud-based programming environment aimed at kids aged ~ 9-16. The programming language itself is called Nepo. It’s a graphical programming language based on Java using the Blockly-library. With Nepo kids can learn how to code using robots such as Lego Mindstorms, Nao and Bot ‘n’ roll, or microcontrollers such as the BBC micro:bit and Calliope mini – in case there’s no hardware available, they can simply use the simulation. There’s also the possibility to view or download the source code.

    I’ve seen kids using it and it’s a fun and inuitive way to introduce them to the coding world. Of course among others, but I just felt like adding a few words ;)

    1. Yes, thanks, I agree. It’s great. We’ve tried it with some success.

      Unfortunately, I think the project could be run a lot more smoothly, with some focus on the experience for people just arriving at the website rather than via an in-school program. For instance, I wish they would actually tell us what robot to build so that it works exactly as expected:

      Unfortunately, I think it generally requires the Education EV3 kit, not the retail version.

Comments are closed.