JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, [email protected].

9
JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, [email protected]

Transcript of JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, [email protected].

Page 1: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

JAVA (NPRG013) LABS

2012/2013

Page 2: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

BASIC INFORMATION

Course website http://d3s.mff.cuni.cz/~hnetynka/index.cgi/teaching/java

“Grupík” module in SIS

Page 3: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

CREDIT CONDITIONS Attendance (max 3 absences)

Elsewise an extra homework

One obligatory homework

Final “project” Topic due at Nov. 14th 2012 Finalized preferably till the end of February

Hard deadline May 24th 2013 12:00 (end of summer semester)

Final test

Details on the course website

Page 4: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

GUIDELINES

Basic Java info package = a directory with a particular structure,

containing source files classpath = list of directories, where to look for

packages -cp, CLASSPATH environment variable

public static void main(String args) { … } System.exit(int retval) System.out.println(…)

print(…), printf(…)

Page 5: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

GUIDELINES 2 Basic shell commands (bash, …)

man – manual pages mkdir – create a directory

-p creates also the non-existing parent directories cd – change directory ls [-a, -l] – list directory contents rm [-r-f] – delete a file/directory [recursively] export CLASSPATH = “…”

Sets the CLASSPATH environment variable

Unix at MS home vs home/BIG

cp –r .gnome BIG/.gnome ln –s BIG/.gnome

Editor vim/gvim, gedit (Gnome), kwrite (KDE), …

Java tools java – runtime javac – compiler

Page 6: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

GUIDELINES 3Basic procedure

// create a directory structure for the project & package

mkdir -p project/src/cz/cuni/mff/keznikl

// implement stuff

gvim project/src/cz/cuni/mff/keznikl/Test.java

// compile (creates Test.class)

javac project/src/cz/cuni/mff/keznikl/Test.java

// run it

java –cp project/src cz.cuni.mff.Test

Implementation

package cz.cuni.mff.keznikl;

public class Test {

public static void main(String[] args) { ... }

}

Page 7: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

ASSIGNMENT 1

Program Hello World Use your own package (not the default=“” one)

Page 8: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

ASSIGNMENT 2 An application that uses a class from a different project/package

2 projects hello, library src directory for source files

/…/home/…/projects/hello/src/ /…/home/…/projects/library/src/

Project library package: org.company.library contains class Printer

static method print(String msg)

Project hello package: cz.cuni.mff.example method main Prints “Hello world” using the Printer class

Page 9: JAVA (NPRG013) LABS 2012/2013 Jaroslav Keznikl, keznikl@d3s.mff.cuni.cz.

Jaroslav Keznikl, [email protected]

ASSIGNMENT 3,4

Assignment 3 Create a program, which prints out all its arguments

from the command line.

Assignment 4 Create a program, which prints out a multiplication

table for numbers 1-10