CS2514

Introduction to Java

Dr Derek Bridge

School of Computer Science & Information Technology

University College Cork

Administrivia: Module delivery

Credit weighting: 5 credit module
Prerequisites: CS1117
Lectures: 2 × 1 hr per week
Labs: 1 × 2 hr per week
Private study: At least 2 hrs per week

Administrivia: Assessment

Examination: 1.5 hr written exam (80% of the marks)
Continuous assessment: Programs (20% of the marks)

The usual finger-wagging shit

How to fail: Skip lectures & labs; avoid private study; cram at Easter; expect the exam to be a memory test
How to pass: Attend lectures & labs; summarize the notes; tackle the lab activities properly; expect a problem-solving exam

Resources

Why learn Java?

Java SE versions

Java 11996JDK 1.0250 classes
1997JDK 1.1500 classes
Java 21998J2SE 1.22300 classes
2000J2SE 1.3
2002J2SE 1.4
Java 52004J2SE 5.0 (internally 1.5)3500 classes
Java 62006Java SE 6 (internally 1.6)
Java 72011Java SE 7 (internally 1.7)
Java 82014Java SE 8 (internally 1.8)
Java 9September 2016?

Why object-oriented programming?

What's an object?

Getting work done

'Printing' to the screen

Where to write your code

Store this in HelloWorld.java:

class HelloWorld {
            
    public static void main(String[] args) {
    
        // For now, all your code goes here
        
    }
    
}

Compiling and running programs

Compiling C gives machine code

You re-compile for machines with different instruction sets

Compiling and running Java programs

Compiling Java gives bytecode

A Java slogan is: write once, run anywhere

Reading input from the keyboard

Creating new objects

Exercise

Write a program that asks the user for his/her name and prints it out again, e.g.:

Halt! Who goes there? Ann
Hello, Ann. You may pass.

(User's input is shown in red.)