Java Course 1: Introduction

32
Introduction Introduction Java course - IAG0040 Java course - IAG0040 Anton Keks 2011

description

Lecture 1 from the IAG0040 Java course in TTÜ. See the accompanying source code written during the lectures: https://github.com/angryziber/java-course

Transcript of Java Course 1: Introduction

Page 1: Java Course 1: Introduction

IntroductionIntroduction

Java course - IAG0040Java course - IAG0040

Anton Keks 2011

Page 2: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 22

Java course – IAG0040Anton Keks

About MeAbout Me

● Anton Keks– Co-founder of Codeborne, an agile company

– Previously, team leader in Swedbank

– Strong believer in Open Source software

– Author of Angry IP Scanner

– Passionate traveler

– Likes motivated students :-)

● Contact– anton @ azib.net

(Estonian, Russian, English)

Page 3: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 33

Java course – IAG0040Anton Keks

The CourseThe Course

● IAG0040 ● “Programmeerimise erikursus II - Java”

“Special course in programming II - Java”● 5.0 EAP / 3.5 AP● In IASM curriculum, but anybody is welcome!● Can be substitued for "Programmeerimine II"

● The official site: http://java.azib.net/http://java.azib.net/

Page 4: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 44

Java course – IAG0040Anton Keks

PrerequisitesPrerequisites

● It is recommended to– know basics of OOP

(Object-oriented programming)– be familiar with C and C++

● It is required to – have a will to study and become a true

professional

Page 5: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 55

Java course – IAG0040Anton Keks

How to pass?How to pass?

● Do the homework (max 50 p)● Pass the exam (max 50 p)● Optionally participate in Robocode

competition (max 10 p extra)

● Standard rules for mark computation:– finalPoints = homework + robocode + exam;

– mark = Math.min((finalPoints - 50) / 10, 5);

Page 6: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 66

Java course – IAG0040Anton Keks

HomeworkHomework

● The task is published on the official websitehttp://java.azib.net/wiki/Homeworkhttp://java.azib.net/wiki/Homework(minor details may change)

● Must work, have good design, quality code● Source code must be committed to Subversion ● Deadline is to be defined, close to the end of

the semester

Page 7: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 77

Java course – IAG0040Anton Keks

RobocodeRobocode

● Competition of robot tanks programmed in Java

● Initiated by IBM● http://robocode.sourceforge.net/http://robocode.sourceforge.net/● A fun way of learning Java language● Competition will be organized

Page 8: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 88

Java course – IAG0040Anton Keks

Registration & TestRegistration & Test

Course registration and test:

http://java.azib.net/questionnaire/http://java.azib.net/questionnaire/

Page 9: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 99

Java course – IAG0040Anton Keks

Version ControlVersion Control

● Historically, there were formalized processes for revision control, e.g. in engineering, law, business– allowed to revert to an earlier version in case of

reaching a dead-end in design– allowed to track authors and dates of changes

● The earliest VCS for software engineering was similar - just manual copying

Page 10: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1010

Java course – IAG0040Anton Keks

VCS HistoryVCS History

● 1972: SCCS (Source Code Control System)– was unique because of the 'weaves' (storage)

● 1980s: RCS (Revision Control System)– for single files only, still used in specific cases

● 1986: CVS (Concurrent Versions System)– initially shell script wrappers for RCS to manage

multiple files at once● 2000: Subversion

– a YACC (Yet Another CVS Clone)

Page 11: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1111

Java course – IAG0040Anton Keks

SubversionSubversion

● A Version Control System (VCS)● Is a 'better CVS'● Allows many developers to work on the same code

base● Supports development on different branches in

parallel● Tracks modification history● Allows restoration and rollbacks● A lot of other possibilities!

Page 12: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1212

Java course – IAG0040Anton Keks

SubversionSubversion

● Subversion repository is accessible using URLs– http:// or https:// - WebDAV, https can be

proxied– svn:// or svn+ssh:// - native protocol (and over

ssh)– file:// - local repository

● During the course we will use this one:

– https://svn.azib.net/javahttps://svn.azib.net/java

Page 13: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1313

Java course – IAG0040Anton Keks

VCS/Subversion terminologyVCS/Subversion terminology

● repository - the place where Subversion holds all the files and their revisions

● checkout - to retrieve (or sometimes update) files from the repository, recreating exactly the same directory structure as on the server.

● commit - to finally put (or checkin) files or their modifications to the server.

● revision - version of the repository state. Subversion assigns a single sequential revision number to the whole commit.

● trunk - the main development tree in the repository.

● tag - a symbolic name, given to a specific state of the repository.

● branch - a parallel branch of modifications in the source code tree, which can be modified and committed independently from the trunk.

Page 14: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1414

Java course – IAG0040Anton Keks

Repository layoutRepository layout

● Standard top-level directories– trunk – the main development tree– branches – for parallel development– tags – labeled states of the tree (released versions)– all of them contain the same project structure

inside● Branching is done via 'svn copy' command

– copies are cheap – only changes are stored– switch to another branch via 'svn switch'

Page 15: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1515

Java course – IAG0040Anton Keks

Project structureProject structure

● Most Java projects have the following top-level elements:

– src - main Java source code (deliverable)– test - automated tests (also written in Java) – lib - used external libraries (jar files) – build.xml - Ant build script, used for continuous

integration

Page 16: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1616

Java course – IAG0040Anton Keks

Java HistoryJava History

● Initially developed as an embedded language for interactive TV consoles, initially named Oak

● In 1995 began to target the Internet. Renamed to Java

● Applets were the “killer app”● Servlets helped to survive● Now the most successful and

dominating programming language

Page 17: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1717

Java course – IAG0040Anton Keks

Most used in...Most used in...

● Server-side enterprise applications● JavaME/CLDC – mobile apps/games● Blue-Ray● Google Android mobile platform● Some cross-platform desktop software

Page 18: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1818

Java course – IAG0040Anton Keks

Latest major newsLatest major news

● Sun Microsystems acquired by Oracle - 2010● Java became open-source (OpenJDK) - 2007● Java 1.6 released in November 2006● Java 1.5 discontinued in November 2009● Development of Java 1.7 is still in progress

Page 19: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 1919

Java course – IAG0040Anton Keks

3-letter acronyms3-letter acronyms

● JDK = Java Development Kitused to write Java programs

● JRE = Java Runtime Environmentused to run compiled Java programs

● JVM = Java Virtual Machineis a part of both JDK and JRE

● Java = language + JVM + API

Page 20: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2020

Java course – IAG0040Anton Keks

Java versionsJava versions

● Java 1.0 – first public release● Java 1.1 – JIT, better AWT, better unicode support● Java 1.2 – first Java 2 release, Collections, JIT● Java 1.3 – dynamic proxies● Java 1.4 – XML, Regular Expressions, assertions● Java 1.5 – aka Java 5 – lots of new language features● Java 1.6 – aka Java 6 – scripting, better desktop● Java 1.7 & 1.8 – many new language features are

planned

Page 21: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2121

Java course – IAG0040Anton Keks

Java flavorsJava flavors

● Java SE – standard edition (J2SE)● Java EE – enterprise edition (J2EE)● Java ME – micro/mobile edition (J2ME) ● Java Card – for smart cards

● Sun Java – official

● IBM Java SDK

● GNU Java – gcj & gij

● Icedtea – early releases of OpenJDK 1.7

● and others

Page 22: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2222

Java course – IAG0040Anton Keks

The progress of abstractionThe progress of abstraction

● Logic ICs, hardware● CPU, instructions● Assembly language● Procedural languages: Fortran, Pascal, C● Problem modeling languages: LISP, LabView● Object-oriented languages: Smalltalk, C++● Java and JVM (Java Virtual Machine)

Page 23: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2323

Java course – IAG0040Anton Keks

Java classificationJava classification

● Java language is– general-purpose– object-oriented– static– strongly typed– memory safe– compiled, but bytecode-interpreted

Page 24: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2424

Java course – IAG0040Anton Keks

Main OOP conceptsMain OOP concepts

● Everything is an object● A program is a bunch of objects telling each

other what to do by sending messages● Each object has its own memory made up of

other objects● Every object has a type● All objects of a particular type can receive the

same messages● An object has state, behavior and identity

Page 25: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2525

Java course – IAG0040Anton Keks

Java vs C++Java vs C++

● Java is loosely based on C++, but is more “pure”

● All objects are on the heap

● No pointers, only references

● Garbage collection

● Simplified constructs

● “Root” object: java.lang.Object

● Checked exceptions

● No multiple inheritance, but interfaces

● No operator overloading, no preprocessor, no macros

● Packages instead of namespaces

Page 26: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2626

Java course – IAG0040Anton Keks

Hello World time!!!Hello World time!!!

public class HelloWorld {

public static void main(String[] args) {

System.out.println(“Hello World!”);

}

}

● Put it into the HelloWorld.java file

● Compile with javac HelloWorld.java (you will get a binary file HelloWorld.class)

● Run with java HelloWorld (means run class HelloWorld, by default look for it in the current directory)

Page 27: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2727

Java course – IAG0040Anton Keks

IntelliJ IDEAIntelliJ IDEA

● The “smartest” Java IDE around● Now has a free Community Edition

– Syntax highlighting– Code completion, suggestions, templates– Refactorings– Integrated Subversion support

● With practice your productivity can increase multiple times (learn shortcut keys)

Page 28: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2828

Java course – IAG0040Anton Keks

Initial SetupInitial Setup

IntelliJ IDEA and Subversion are our main tools during this course, prepare yourself using this

guide:

http://java.azib.net/wiki/Setuphttp://java.azib.net/wiki/Setup

Page 29: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 2929

Java course – IAG0040Anton Keks

Continuous integrationContinuous integration

● Regular automated builds of the software (e.g. after each commit)

– the whole program is recompiled– automated tests are run– documentation is generated– software is packaged and therefore ready to run

Page 30: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 3030

Java course – IAG0040Anton Keks

Benefits of CIBenefits of CI

● Provides quick feedback to developers

● Reduces wasted time of the team due to broken code

● Helps to find integration problems and failed tests early

● The latest builds are always runnable and testable by e.g. customers

● Hudson is one of the tools often used for this purpose

– http://java.azib.net/hudsonhttp://java.azib.net/hudson– it will send you automatic mails if you are guilty!

Page 31: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 3131

Java course – IAG0040Anton Keks

ClassesClasses

● Basically, all you do in Java is define classes

– everything else is inside of them:fields, methods, code instructions

● Class names are in “CamelCase”

– HelloWorld, String, BigDecimal● class MyClass { /*body here*/ }

● Public classes must be defined in files with same names

Page 32: Java Course 1: Introduction

Lecture 1Lecture 1Slide Slide 3232

Java course – IAG0040Anton Keks

PackagesPackages

● Classes generally reside in packages● Specified in the beginning of the file:

– package net.azib.java;

– names usually start with domain name of the author

– package is optional (but highly recommended)● Each dot-separated token represents a directory

– net.azib.java.HelloWorld class should reside in net/azib/java/HelloWord.class file on the disk

● Classes are referenced by their full names unless imported: import net.azib.java.HelloWorld;