# Java or Kotlin for beginners (procedural programming knowledge is existing)?

We are teaching an "introduction to cs" course (bachelor level) and in the first half of a year students are learning the fundamental principles of procedural languages. We are using python 3 and C as exemplary languages for this part.

Up until now, I moved on to C++ and the object oriented part of python 3 in the second half of the year to demonstrate object oriented languages.

Java is currently tought in the third semester.

All three languages will be needed by the students later on, so the pros and cons of C, C++ and python 3 are not part of the question...

Now we decided to start introducing Java one semester earlier instead of C++.

While we were discussion the course design I joked "why don't we just skip Java and move to Kotlin", and since I had this idea I'm really considering it.

Do you already have experiences with Kotlin in teaching? Would you consider replacing Java entirely by Kotlin? Or would you just mention its existence? Any pros and cons? How about GUI design etc. (I used qt in the old course)?

Our students might develop smartphone apps as well as webservices in those languages.

• I wonder, actually, if lots of languages is a good thing to do. As opposed to diving deeply into problem solving in a smaller set. Especially if students never really get to understand any of the paradigms on which those language are based. I think it can become just a syntax jumble, rather than anything deeper. If they have Python, for example, then why Java at all? Nov 16 '18 at 0:27
• @Buffy our education is very applied and we try to teach the relevant programming languages for our domains. Since many students will working with Java later on, they like to learn the languages they are confronted with in their later business fields (which was one reason for C (embedded programming) as well). My personal favourite is Python 3 as well ;-).
– OBu
Nov 16 '18 at 10:27
• To be honest, I'm having trouble understanding the context here. What level of education is this? Secondary? Undergraduate? You say it is very applied. Is this a traditional program at some level or specialized training rather than degree focused? What happens to your graduates, generally? I think more context might make it possible to give advice. Nov 19 '18 at 12:45
• Yes, I realize you said bachelor level, but is it an actual baccalaureate? Sorry that I don't understand the educational system in Germany very well. Nov 19 '18 at 14:27
• @Buffy The German bachelor starts after 12 or 13 years of school. It takes (usually) 7 semester, and afterwards you can do a matter of science (3 semester) which is the entry qualification for a PhD. Many people leave after the bachelor of science to work in industry, in our case maybe as programmer, consultant, product manager, ...
– OBu
Nov 19 '18 at 14:49

I've been using Kotlin for two years now on an introductory course on imperative programming (bachelor's first semester) and I'm very happy with this decision. Before Kotlin, I was using Java for the same course.

Here are some of the benefits:

• No need to explain what are classes on a imperative programming course, since Kotlin programs can only have a main() top level function (like C)
• It is a "safe" language in the sense that it prevents most novice mistakes at compilation time (uninitialised variables, type conversion errors, etc.)
• For simple interactive programs (e.g., ask two numbers and compute their sum), you don't need all the complexity of the Scanner/BufferedReader classes, just use readLine() and println() (without the System.out). This makes the initial learning curve much more pleasant.
• It forces the students to think about the little things that are essential when you are taking the first steps in programming: mutable vs immutable variables, nullable vs non nullable types, mandatory variable initialisation, implicit vs explicit types, conditions as expressions, etc...
• It is easy to jump to Java in later courses (than say Python or Javascript)

Most of all, from my experience students find it more motivating to learn to program in Kotlin than Java, since they have to write less to accomplish the same things while at the same time feeling protected about runtime errors.

My preferred curriculum is to teach relatively few languages explicitly, but require others in projects, even large projects. Then draw it together in a principles course.

Most students in the US come to a CS program knowing some imperative programming, even if they think of it otherwise. But their background is usually very weak and they don't write effective or maintainable programs. They write too few, too large functions, for example with deeply nested logic structures that are hard to unpack. They need to be taught how to write differently. It can be a struggle for many to not just build deeper and deeper logic structures, with lots of badly named flags, etc., hacking a more or less workable solution.

So, in my view, the curriculum, as it relates to programming, focuses on abstraction and how to use it effectively in the different programming paradigms.

Ideally, three languages are sufficient to cover (most of) the ground. A low level language in which you can write things that need to be close to the machine. An object-oriented program in which you can discuss the various kinds of abstraction and encapsulation. A functional language in which you can discuss higher level constructs (first class functions, etc). If that is followed by a language principles course in which you can take a meta level view of the language paradigms, it should be possible, in theory, for a student to learn any new language (until a new paradigm comes along). Paradigms are, by their nature, hard. The principles course can dip a toe into several languages other than the ones the students know, just to give them the flavor of the range of possibilities. This is separate from any compiler course, though.

My preferred method is to start with the OO paradigm as it is sort of mid-way between imperative and functional. I don't start with low level constructs (int, float, if, while) however, but with OO features programmed in a prepared simulation that allows Turing Complete programming without any of the low level detail. The "primitives" of the simulation are much higher level, constructed objects with well defined behavior. From that base you can introduce both higher and lower level ideas.

The German system, however, has much more opportunity to do various things as there are more courses in the curriculum.

However, actually teaching both Python and Java seems to be a waste of resources to me. Teach one and in another course, do a project in the other. The ideas are nearly the same and the differences can be learned by osmosis.

I don't know Kotlin, actually, but brief examination suggests that its benefit is in concurrency. That is actually a different paradigm, of course, to the "big three". But if they know Java or Python, a project based course focusing on concurrent programming in Kotlin might be feasible, with relatively little emphasis on the other features of the language. I wonder a bit if the language is stable enough currently to make it a fundamental part of a curriculum. Hence a project rather than a full course.

• Kotlin advantages go much further than concurrency - see this post for some examples: hashnode.com/post/… Dec 6 '18 at 20:02