Exercise 1: Intro to Java & Eclipse

Similar documents
3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Getting Started with Eclipse/Java

Javac and Eclipse tutorial

Lesson 04: Our First Java Program (W01D4

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Getting Started with Java. Atul Prakash

PART 1. Eclipse IDE Tutorial. 1. What is Eclipse? Eclipse Java IDE

Lecture 4: Introduction to Java and your Development Environment

CSC116: Introduction to Computing - Java

Class 1: Homework. Intro to Computer Science CSCI-UA.0101 New York University Courant Institute of Mathematical Sciences Fall 2017

For live Java EE training, please see training courses at

Eclipse Environment Setup

CSC116: Introduction to Computing - Java

Programming in Java Prof. Debasis Samanta Department of Computer Science Engineering Indian Institute of Technology, Kharagpur

CSC116: Introduction to Computing - Java

Using Eclipse for Java. Using Eclipse for Java 1 / 1

AP Computer Science Summer Assignment (updated 5/29/2018) DUE : Sept. 4, 2018

Get JAVA. I will just tell you what I did (on January 10, 2017). I went to:

You should now start on Chapter 4. Chapter 4 introduces the following concepts

13 th Windsor Regional Secondary School Computer Programming Competition

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Setup and Getting Startedt Customized Java EE Training:

Introduction Basic elements of Java

CompSci 125 Lecture 02

Using Eclipse Europa - A Tutorial

Software and Programming 1

C02: Overview of Software Development and Java

CS 177 Recitation. Week 1 Intro to Java

Programming with Java

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

Introduction to Java

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

1. Download the JDK 6, from

Classes. Classes. Classes. Class Circle with methods. Class Circle with fields. Classes and Objects in Java. Introduce to classes and objects in Java.

Software and Programming 1

CS 11 java track: lecture 1

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

G52PGP. Lecture oo3 Java (A real object oriented language)

Object Oriented Programming. Week 1 Part 3 Writing Java with Eclipse and JUnit

Example: Fibonacci Numbers

Getting Started with Eclipse for Java

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Java with Eclipse: Setup & Getting Started

Assignment Marking Criteria

Advanced Computer Programming

Programming Basics. Digital Urban Visualization. People as Flows. ia

II. Compiling and launching from Command-Line, IDE A simple JAVA program

Instructions PLEASE READ (notice bold and underlined phrases)

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Java Bytecode (binary file)

Computer Science AP 2017 Summer Assignment Mrs. McFarland

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

CPS109 Lab 1. i. To become familiar with the Ryerson Computer Science laboratory environment.

CS Week 2. Jim Williams, PhD

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

JAVA Programming Practice Course Overview Lecture Schedule Today s Task Contact

IT151: Introduction to Programming (java)

Fall 2017 CISC124 9/16/2017

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Getting Started with Eclipse for Java

Overview of Eclipse Lectures. Module Road Map

CPSC 150 Laboratory Manual. Lab 1 Introduction to Program Creation

COMP-202 More Complex OOP

Java Programming Language Mr.Rungrote Phonkam

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Java Professional Certificate Day 1- Bridge Session

SDKs - Eclipse. SENG 403, Tutorial 2

Starting In Java With JPT in Eclipse

Crash Course Review Only. Please use online Jasmit Singh 2

Workbook 1. In each practical class you will find three course instructors who have the following duties:

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011

AP Computer Science A Summer Assignment

Do this by creating on the m: drive (Accessed via start menu link Computer [The m: drive has your login id as name]) the subdirectory CI101.

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

RTMS - Software Setup

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

Certified Core Java Developer VS-1036

Programming by Delegation

Lec 3. Compilers, Debugging, Hello World, and Variables

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

A JavaBean is a class file that stores Java code for a JSP

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

Recursion 1. Recursion is the process of defining something in terms of itself.

CS520 Setting Up the Programming Environment for Windows Suresh Kalathur. For Windows users, download the Java8 SDK as shown below.

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

CHAPTER 1. Introduction to JAVA Programming

Initializers: Array initializers can be used with class base types as well. The elements of the initializer can be expressions (not just constants).

MEAP Edition Manning Early Access Program Get Programming with Java Version 1

Midterm Exam CS 251, Intermediate Programming March 12, 2014

COMP 250 Winter 2011 Reading: Java background January 5, 2011

Software Installation for CS121

An AspectJ-enabled Eclipse Runtime Engine - Demonstration at AOSD 04 - Martin Lippert

Expanded Guidelines on Programming Style and Documentation

Software Construction

AP Computer Science A: Java Programming

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Transcription:

Exercise 1: Intro to Java & Eclipse Discussion of exercise solution We do not put the exercise solution s source code online! But we show & publish the most important parts on slides There are sometimes several possible solutions Tips for the next exercise Remarks about the week s topic Tips about programming tools, libraries, etc.... 1

Your assistant for this week Velko Vechev PhD student at Advanced Interactive Technologies (AIT) Department of Computer Science (D-INFK) Technical Human-Computer Interaction (HCI) E-mail: velko.vechev@inf.ethz.ch Office: CNB H 100.9 Please submit exercise 1 solutions to me Complex.java 2

No testat, but exercises are exam material Exercises: Exercises 1-3: Recommended to do alone Exercises 4-11: Teams of two are recommended (it is a lot of work) Hand-in (by Email) Velko Vechev, velko.vechev@inf.ethz.ch Stefan Stevsic, stefan.stevsic@inf.ethz.ch Deadline: Two weeks after hand-in (there are exceptions) Assistants may not be able to provide feedback for late submissions Ask specific questions 3

Today Installation of Java + Eclipse First steps with eclipse (Demo) Hello World in Java Vektor-Class 4

Installation of Java install Java Development Kit (JDK) Version 9 aka. 1.9, (versions 1.4 lack features used in this course) Windows / OSX: Download from http://www.oracle.com/technetwork/java/javase/downloads/index.html Linux: Installation via Package-Manager (apt-get, Synaptic etc.) or download from Oracle Attention: Java Runtime Environment (JRE) is not sufficient: The compiler is missing! JRE is part of the JDK. 5

Hello World Application in Java Enter source in text-editor and save as HelloWorld.java Filename must be equal to the class name. public class HelloWorld { public static void main(string args[]) { System.out.println( Hello World! ); HelloWorld.java 6

Hello World Programm in Java Name of the class: HelloWorld Application entrance point: main( ) The Java Virtual Machine (VM) searches the static method static void main(string[]) within the class that was given to the java command. Array args contains the command line arguments. public class HelloWorld { public visibility (all) public static void main(string args[]) { System.out.println( Hello World! ); class object method System static field (class variable) 7

Start java from the command line The Java VM (java.exe) as well as the compiler (javac.exe) can be started from the console: 8

Extend the searchpath (Windows) The bin directory of the JDK must be in the PATH environment variable: Under : My Computerà Properties extend Path (append) ;C:\<INSTALLATION-DIRECTORY>\Java\jdk1.8.0_121\bin; 9

Eclipse IDE Download: http://www.eclipse.org/downloads recomended Eclipse is an open-source framework, primarily used as a Integrated Development Environment (IDE) Eclipse is modular and can be extended by plugins Eclipse is available in several packages (different set of pre-installed plugins) 10

Eclipse Workspaces Workspace: Contains the projects Where is my workspace? Shown at startup It is possible to have several workspaces Hides this dialog in the future. Can be changed later in: Window à Preferences à General à Startup and Shutdown à Workspaces à Prompt for workspace on startup 11

Eclipse 12

Eclipse Execute Application Icon or: Run As => Java Application in context menu of Hello.java Helpers while coding: Code formatting: CTRL+SHIFT+F Code Completion: CTRL+SPACE Refactoring: Renaming of methods, classes, fields, incl. changing of all references. a lot more... Stefan Müller Software Design Übungsstunde Frühlingssemester 2012 13

Documentation Complete Java Documentation: http://docs.oracle.com/javase/8/docs/ Documentation of all Classes that come with java http://docs.oracle.com/javase/8/docs/api/ Tooltips in Eclipse: 14

Java Coding Style Guideline for Java-Programming style Increases readability of the code 80% of software cost is from maintenance Code usually is not maintained by the original author Be able to read your own code 6 months from now J Code Conventions for the Java Programming Language http://www.oracle.com/technetwork/java/codeconv-138413.html Used by almost all professional java developers Automatic in Eclipse : Source àformat 15

Some Code Conventions Package names are lower-case (e.g. ch.ethz.inf.sd.math) Classes start with an upper-case letter (e.g. Complex) Java Files are named after the public class they contain. UNIX-like operating systems are case sensitive! Static constants are written all upper-case. Fields and methods start with a lower-case letter. Separation of words by an upper-case letter (camelcase): get_first_element() getfirstelement() Brackets: void foo() void foo() { { if (x>y) { if (x>y) else { { else { Indent code blocks 16

Console output of objects Output of primitive types (int, float, double, usw.) int a, b;... System.out.println(a+b*3.0); Result appears in console Output of objects by converting them to strings: Foo foo = new Foo(); System.out.println(foo); Output: Foo@82ba41 (Classe+hash value) 17

A class for vector operations Encapsulation: Class Vector capsulates vector operations in R 3 Possible operations (not complete): Constructors: Construct vector from the three components R 3 x R 3 à R 3 : addition, subtraction R 3 x R à R 3 : scaling R 3 à R : norm getter and setter methods for the individual components. normalizing Output as string Source code available online after the exercise 18

public class Vector { private double x, y, z; Basic structure public Vector(double x, double y, double z) { this.x = x; this.y = y; this.z = z; //... public double getx() { return x; public void setx(double x) { this.x = x; public void add(vector v) { x+=v.x; y+=v.y; z+=v.z; //... also possible: public Vector add(vector v) { return new Vector(x+v.x, y+v.y, z+v.z); 19

How to use the vector class: The class VectorTest uses Vector public class VectorTest { public static void main(string args[]) { Vector a = new Vector(3.0, 1.0, 5.0); Vector b = new Vector(1.0, 0.0, 0.0); a.add(b); System.out.println(a.getX()); 20