I think Kotlin would be a much better language to learn programming. Kotlin avoids much of the noise and is very readable.
The hello world example is symptomatic:
public class Example {
public static void main(String ...args) {
System.out.println("Hell, World!");
}
}
vs
fun main(args: Array<String>) {
println("Hello, World!")
}
Some more examples:
// java
for (Element element : collection)
// kotlin
for (element in collection)
// java
(OtherType) somehting;
// kotlin
somehting as OtherType
// java
a.equals(b);
// kotlin
a == b
// java
Color color = x < 5 ? Color.RED : Color.GREEN;
// kotlin
val color = if (x < 5) Color.RED else Color.GREEN
And some more like constructors just named "constructor", init blocks are name "init", varargs are prefixed with "vararg", type checks with "is", ranges with 1..9, strings wicht embedded variables ...
Kotlin or not, I feel like Java is just the wrong choice. Even Kotlin, there's a lot of noise to start with. What's a function? What's an Array? What's a String? I have to either explain all those things, or handwave it as "magic; ignore it for right now" to students. I would find that incredibly frustrating as both a student, and a teacher.
I TAed an intro to CS class in Python for a number of years. I am rather ambivalent toward Python as a developer, but as a first language to be taught it worked pretty well. There are others, but having the minimum amount of noise for some basic coding examples I think is incredibly helpful (though I admit, I think I'm basically just saying "I think dynamically/optionally typed scripting languages > statically, explicitly typed compiled languages for this task").
I started with Pascal in school (6th grade I think). The book contained a few lines of code and said: This is the smallest program possible: it does nothing.
program HelloWorld;
begin
end.
I was puzzled: why would you need to write something for it to do nothing? But it becomes clear very easily: all programs need to have a special structure to be correctly defined. This structure happens to be a block of code with a name. And that explanation was enough to satisfy me for the moment. I turned a few pages, and sure enough all examples had that structure with something else inside. I was already feeling good with myself for being able to recognize well structured programs.
Just the way it allows you to create an inmutable class in a single line already makes it way easier to read, while also saving time.
Compare Java:
public class Person {
private final String name;
private final int age;
public Person(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
}
Starting in a very-widely-used language is useful though - someone interested in learning further has a wide range of materials, from books to MOOCs, to choose from. Switching from one language to another before they're fully comfortable with the basic ideas of programming is not going to go well.
The hello world example is symptomatic:
vs Some more examples: And some more like constructors just named "constructor", init blocks are name "init", varargs are prefixed with "vararg", type checks with "is", ranges with 1..9, strings wicht embedded variables ...