What programming languages do you have experience with?
Can you name one difference between Python and Java?
If you become a good programmer, what kind of application would you like to develop?
Learning to write programs stretches your mind, and helps you think better, creates a way of thinking about things that I think is helpful in all domains.
— Bill Gates, Microsoft co-founder
Course objectives
Understanding Programming Constructs: Develop a deep understanding of Java programming constructs, including syntax, semantics, control structures, and object-oriented principles.
Problem-Solving Skills: Enhance problem-solving abilities by applying programming knowledge to design and implement software solutions.
Critical Thinking in Code Analysis: Cultivate the ability to trace, analyze, and evaluate code for correctness, efficiency, and maintainability.
Software Design and Development: Learn to create modular, reusable, and maintainable software using object-oriented programming (OOP) principles.
Practical Application: Apply learned concepts in a complex project that mimics real-world programming tasks.
Methodology
Flipped Clasroom style
(1 ~ 2 hours) Watch online lectures and complete readings before class.
(2 hours) Offline activities (10:00 am)
Initial Quiz: Formative assesement of basic concepts and syntax.
Interactive Q&A: discussions and to clarify doubts.
Programming Quizzes: Take regular quizzes to reinforce concepts.
Hands-On Practice: Engage in coding exercises to apply what you’ve learned.
Command Line: to manually compile and run Java applications.
What about IDE?
During the first weeks of our course, we are going to work only with text editor, to learn well the structure of Java applications and how to successfully run our projects.
What specific IDE we are going to use, will be announced later.
Learn what is a programming language, program and computer programming
Distinguish between low-level and high-level programming languages
Explain the difference between compiled and interpreted languages, and classify Java as a compiled language.
Become familiar with executing programs
Write and execute several programs in Java, following the steps to compile and run the program using a text editor and the command line.
Learn to write programs that print text.
Know what the term “parameter” means.
Problem-solving for computer scientists
It involves the ability to formulate problems, think creatively about solutions, and express solutions clearly and accurately.
Broad goals of this module:
Learn to read Java programs
Learn to write Java programs
Design and write Java programs to solve problems
What is a programming language?
A programming language is a formal system used to communicate with computers, allowing humans to write instructions that a computer can understand and execute (i.e., to write, compile, and execute programs).
A programming language is described by its syntax (form) and semantics (meaning)
Syntax: the rules that define the combinations of symbols that are considered to be correctly structured statements or expressions in that language
Semantics: the meaning of programming languages. Semantics assigns computational meaning to valid strings in a programming language syntax.
Programms and programming?
A program is a sequence of instructions that specifies how to perform a computation on computer hardware.
input: Get data from the keyboard, a file, a sensor, or some other device.
output: Display data on the screen or send data to a file or other device.
math: Perform basic mathematical operations like addition and division.
decision: Check for certain conditions and execute the appropriate code.
repetition: Perform an action repeatedly, usually with some variation.
Programming can be seen as the process of breaking down a large, complex task into smaller and smaller subtasks.
Types of computer languages
Low-level languages
Machine languages: any computer can directly understand
Defined by hardware design
Machine dependent
Assembly languages
English-like abbreviations to represent elementary operations
Assemblers – translators to a machine language
High-level languages
Write instructions that look almost like everyday English
Compilers – convert a high-level language into a machine language
Interpreters – execute high-level language programs directly
Interpreted vs compiled programming languages
How interpreted languages are executed
The process of compiling and running a Java program
What about LLM?
Recently, large language models (LLMs) have become highly capable at generating code.
They operate through natural language prompts.
Example:
“Write a Java program that reads input from the user and calculates the average of five numbers.”
This raises important questions:
Is a prompt a programming language?
If it is a language, is it high-level?
Who is actually doing the “programming”, the human or the model?
Food for thought
What defines a programming language?
Must it have strict syntax? Must it produce deterministic output?
Determinism vs Probability
Traditional programs behave deterministically.
LLMs are probabilistic.
Understanding vs Delegation
If a student uses an LLM to generate code without understanding it:
Is that programming? Is understanding still necessary? What happens when debugging is required?
Integrated Development Environment
Modern programming is practically always done in an IDE (integrated development environment).
An IDE contains a set of useful tools for the programmer.
It does not create the program by itself, but it can give hints about common mistakes in the code, and help the programmer understand the structure of the program.
But, for the first weeks, we are going to use a much simpler approach.
Our first minimalist development environment
In order to understand better how Java programs are written, compiled and executed, we are going to do it manually.
The following steps must be followed:
Get and install Java Development Kit (JDK).
Configure our system to run Java applications.
Run our first Java program.
What is the JDK?
JDK stands for Java Development Kit.
It provides the tools necessary to develop, compile, and run Java applications.
It Includes the Java Runtime Environment (JRE), compiler, and various utilities.
Create a folder structure that you are going to use for our course, for example comlang/week1/01_helloworld/.
Inside that folder, create a file named HelloWorld.java with the following code:
publicclass HelloWorld {publicstaticvoidmain(String[] args){System.out.println("Hello, Computer Language ITM!");}}
Compile the program:
javac HelloWorld.java
Run the program:
java HelloWorld
Programmers Write Source Code
Source Code is the written code composed of statements and expressions read sequentially.
Java offers many built-in commands to simplify development.
You will learn this by doing a lot of programming exercises.
Example:
System.out.println("Hello World");
This command instructs the computer to print the provided string.
Note the semicolon ; at the end, which marks the end of a statement.
These basics form the foundation for all Java programming.
What does this program print?
publicclass Example {publicstaticvoidmain(String[] args){// The statements used by the program are placed hereSystem.out.println("Welcome to the course - you will learn to program!");}}
Welcome to the course - you will learn to program!
Welcome to the course - you will learn to program
you will learn to program!
Welcome to the course
The program prints nothing since it cannot do anything about the substraction
The print command
The print command System.out.println("Hello world"); prints the text “Hello world”.
System.out.println("Hello world!");
Output
Hello world!
You can print any text you want with the command, as long as the command System.out.println("arbitrary text"); — i.e., System dot out dot println open parenthesis ( “the text” close parenthesis ) and semicolon ; remains unchanged.
Program boilerplate
In Java, our programs have to include some boilerplate code1 to work.
This boilerplate, an example of which is shown below, for example tells the computer what your program is called.
Below, the name of the program is Example. This name has to correspond to the name of the file that contains the source code (e.g. Example.java).
publicclass Example {publicstaticvoidmain(String[] args){System.out.println("Text to be printed");}}
Executing code
Execution of the program starts from the line that follows public static void main(string[] args) {, and ends at the closing curly bracket }.
Commands are executed one line at a time.
We’ll learn what the terms public class and public static void mean later on.
In this example, System.out.println("Text to be printed") is the only command to be executed.
Its output is: Text to be printed
publicclass Example {publicstaticvoidmain(String[] args){System.out.println("Text to be printed");}}
Code templates
The examples in our slides will not always show the template, but you can assume that your program file always needs one.
As such, the examples might be as short as a single line, such as the example below that illustrates the print command.
System.out.println("Hello world");
In reality, the above example, when written as a full Java program, looks like so:
publicclass Example {publicstaticvoidmain(String[] args){// Here goes the statements used by the programSystem.out.println("Hello world!");}}
Exercise 2
Here’s the second programming exercise of this course.The exercise template has the following boilerplate code:
publicclass AdaLovelace {publicstaticvoidmain(String[] args){// Write your program here}}
The line “// Write your program here” is a line comment, and the computer will ignore it when executing the program.
Add a new line below the line comment that prints the string “Ada Lovelace” and run the program. The output of the program should be:
Ada Lovelace
Running Java programs
Running the program is straightforward, but a lot is happenings behind the scenes. Can you explain it step by step?
When a program is run, the source code is first compiled into Java bytecode by the java compiler. What command do we use for this?
Following that, the program gets executed, meaning the commands are executed one-by-one by a Java-interpreter that is able to read Java bytecode. What is the name of the Java interpreter?
This compile process affects how and when errors occur. When a program is compiled before execution, the compiler can search for errors in it.
Printing multiple lines
Programs are constructed command-by-command, where each command is placed on a new line.
In the example below, the command System.out.println appears twice, which means that two print commands are being executed in the program.
publicclass HelloWorldMultiLine {publicstaticvoidmain(String[] args){System.out.println("Hello world!");System.out.println("... and the universe!");}}
The program above will print:
Hello world!... and the universe!
Precision Matters in Programming
The guidelines in the assignments regarding the print format are very precise. If the assignment expects you to print a parenthesis, you must print the parenthesis.
Missing a single character may cause an error. Novice programmers often:
Enter a comma instead of a dot
Write printin instead of println
Leave out apostrophes, or forget the semicolon after a command.
Any error of these would cause an error and cause the program execution to fail.
Learning programming is, a path full of mistakes — and every error message is a chance to learn.
Exercise 3
The exercise comes with the following template:
publicclass OnceUponATime {publicstaticvoidmain(String[] args){// Write your program here}}
Modify the program so that it will print the following text. Use three System.out.println-commands for printing.
Once upon a timethere wasa program
Terminology and Code Comments
Command parameters
The information to be printed by the print command, i.e. its parameters, are passed to it by placing them inside the parentheses () that follow the command.
For example, passing Hi as a parameter to the System.out.println command is done like this: System.out.println("Hi").
Semicolon Separates Commands
Commands are separated with a semicolon ;.
We could, if we wanted to, write almost everything on a single line.
Source code can be commented to clarify it or to add notes. There are two ways to do this.
Single-line comments are marked with two slashes //. Everything following them on the same line is interpreted as a comment.
Multi-line comments are marked with a slash and an asterisk /*, and closed with an asterisk followed by a slash */. Everything between them is interpreted as a comment.
Comments (II)
Below is an example of a program where both are used.
publicclass Comments {publicstaticvoidmain(String[] args){// PrintingSystem.out.println("Text to print");System.out.println("More text to print!");/* Next: - more on printing - more practice - variables - ... */System.out.println("Some other text to print");// System.out.println("Trying stuff out")}}
The last line of the example shows a particularly handy use-case for comments. Code that has been written does not need to be deleted to try out something else.
Exercise 4
The exercise comes with the following template:
publicclass Dinosaur {publicstaticvoidmain(String[] args){// Write your program here}}
Edit the program so that it will print the following text:
Once upon a timethere wasa dinosaur
Checking our learning objectives
Learn what is programming language, program and computer programming
Distinguish between low-level and high-level programming languages
Explain the difference between compiled and interpreted languages, and classify Java as a compiled language.
Become familiar with executing programs
Write and execute several programs in Java, following the steps to compile and run the program using a text editor and the command line.
Learn to write programs that print text.
Know what the term “parameter” means.
Next week
Output and variables
Acknowledgements
Some contents of this lecture are partially adapted from:
Comments (I)
Source code can be commented to clarify it or to add notes. There are two ways to do this.
Single-line comments are marked with two slashes
//. Everything following them on the same line is interpreted as a comment.Multi-line comments are marked with a slash and an asterisk
/*, and closed with an asterisk followed by a slash*/. Everything between them is interpreted as a comment.