Module 1 | Java Introduction, Static and main methods, Exceptions, Arrays, Dev Tools, Pre-post conditions

Objective

By the end of this module, students will be able to:

  • Write simple Java programs involving objects, primitive types and arrays
  • Understand the difference between static and non-static fields and methods
  • Understand object references the consequence of the by value parameter passing
  • Be able to program with exceptions
  • Be able to document correctly Java programs
  • Use the IntelliJ IDE

Resources

Slides (keynote)

Exercises: week 1

  1. Intro to Java
  2. Exceptions
  3. Write code that generates exceptions
  4. CommonElements
  5. Convolution
  6. 1D and 2D arrays

Exercise 1.1.1

  • Write a java program “Calculator” that takes a series of int argument from the command line, make the summation and prints the result. Hint parseInt method may be useful.
  • Compile your program using javac (verify that the file Calculator.class has been generated)
  • Execute your program from the command line and verifies that it works: java Calculator 10 2 13 should output 25
  • Now edit your program in IntelliJ and pass the arguments from IntelliJ