Java Crash Course Part I



Similar documents
Introduction to Java

CS 106 Introduction to Computer Science I

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Crash Course in Java

Programmierpraktikum

Chapter 1 Java Program Design and Development

Moving from CS 61A Scheme to CS 61B Java

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Install Java Development Kit (JDK) 1.8

Java Interview Questions and Answers

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Installing Java (Windows) and Writing your First Program

How to use the Eclipse IDE for Java Application Development

Java Programming Fundamentals

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

1001ICT Introduction To Programming Lecture Notes

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Introduction to Java. CS 3: Computer Programming in Java

How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Introduction to Object-Oriented Programming

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Lecture 5: Java Fundamentals III

LAB4 Making Classes and Objects

Pemrograman Dasar. Basic Elements Of Java

A Short Introduction to Writing Java Code. Zoltán Majó

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Informatica e Sistemi in Tempo Reale

Introduction to Programming

Installing Java. Table of contents

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Introduction to Python

Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

An Overview of Java. overview-1

Introduction to programming

Part I. Multiple Choice Questions (2 points each):

Java CPD (I) Frans Coenen Department of Computer Science

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Example of a Java program

J a v a Quiz (Unit 3, Test 0 Practice)

Sources: On the Web: Slides will be available on:

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Java Programming Unit 1. Your first Java Program Eclipse IDE

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Introduction to Python

Object Oriented Software Design

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Chapter 2 Elementary Programming

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

The Java Virtual Machine (JVM) Pat Morin COMP 3002

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

Object Oriented Software Design

CSC230 Getting Starting in C. Tyler Bletsch

Tutorial: Getting Started

13 File Output and Input

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

Java with Eclipse: Setup & Getting Started

Programming Languages CIS 443

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Java applets. SwIG Jing He

CS170 Lab 11 Abstract Data Types & Objects

Java from a C perspective. Plan

Some Scanner Class Methods

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Sample CSE8A midterm Multiple Choice (circle one)

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

Creating a Java application using Perfect Developer and the Java Develo...

Lecture 1 Introduction to Java

Third AP Edition. Object-Oriented Programming and Data Structures. Maria Litvin. Gary Litvin. Phillips Academy, Andover, Massachusetts

CSC 551: Web Programming. Spring 2004

Computational Mathematics with Python

Java Basics: Data Types, Variables, and Loops

Programming in Java Course Technology, a part of Cengage Learning.

An Incomplete C++ Primer. University of Wyoming MA 5310

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Variables, Constants, and Data Types

Introduction to Java Lecture Notes. Ryan Dougherty

Chapter 7D The Java Virtual Machine

An Introduction to Computer Science

Computer Programming Tutorial

Java programming for C/C++ developers

6.1. Example: A Tip Calculator 6-1

AP Computer Science Java Subset

public static void main(string[] args) { System.out.println("hello, world"); } }

Welcome to Introduction to programming in Python

Appendix A Using the Java Compiler

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

Chapter 3. Input and output. 3.1 The System class

Computational Mathematics with Python

1.1 Your First Program

CS506 Web Design and Development Solved Online Quiz No. 01

Transcription:

Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de

Overview (Short) introduction to the environment Linux in the computer lab Getting started with Java Your first Java-application Programming elements Variables Operators Simple predefined functions

Purpose of this course You need/take advantage of this course when: You don't know about using the computer lab You don't know about Java 1. week: First introduction 2. week: Programming elements 3. week: Object orientated programming with Java

Environment Linux or MS-Windows In Room 025 only Linux! All exercises and homework in this course and ISI must be runnable under Linux in the Room 025 (This is reference!) For the exercises you will need Editor (e.g. xemacs, kwrite, nedit, UltraEdit or similar) System shell (Konsole/xterm, command shell) JDK (Version 1.5, download at www.java.sun.com) Web browser (e.g. Konquerer or Firefox) (->later)

Java Platform independent (works on MS-Windows, Linux, MacOS,...) Widely known Industrial standard Easy to learn Object orientated Java Development Kit (JDK) free available

/* Your first Java application Simple displays Hallo Welt! To create the program, you have to Write a java sourcefile e.g. HelloWorld.java Compile this sourcefile to a bytecode file e.g. HelloWorld.class Run the program with the Java-interpreter * The HelloWorld class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorld { } public static void main(string[] args) { } System.out.println("Hallo Welt!"); // Display the string

Class declaration: Everything in Java is organized in classes. (Small logical unit which defines a set of variables and methods(routines)) By convention you declare one class per file and name that file with the classname +.java. /* HelloWorld in detail * The HelloWorld class implements an application that * simply displays "Hello World!" to the standard output. */ class HelloWorld { } public static void main(string[] args) { } System.out.println("Hallo Welt!"); Output: Write some characters Hallo Welt! on the screen The main method / routine: Every program need one 'main' routine, where it starts to perform instructions. Command line arguments are stored in 'args'. At this time take the syntax as a fixed statement! A comment: Everything between /* and */ will be ignored by the compiler. Comments are not important for computers but for humans! // Display the string Brackets and parenthesis: Single line comment: Everything after // will be ignored by the compiler Every logical statement must be started and ended with curly brackets! Arguments to methods/functions/routines always uses parenthesis. Arguments are separated by commas. Be aware of case sensitiveness and the semicolon at the end of instructions!

Your first Java application The Java compiler javac Translates the sourcecode into instructions that the Java Virtual Machine (Java VM) can understand (bytecode) Produces.class files from.java files sko@dussel:/home/sko > javac HelloWorld.java sko@dussel:/home/sko >

Your first Java application The Java Virtual Machine (Java VM) Is implemented by the Java interpreter java Can understand bytecode files (.class) and executes them in a way your computer can understand sko@dussel:/home/sko > java HelloWorld Hallo Welt! sko@dussel:/home/sko >

From.java to a running program MyClass.java MyClass.class Hello World kwrite MyClass.java & javac MyClass.java java MyClass

Variables The smallest item of a program Can store data Each variable has: Type (what kind of data, e.g. int or String or...) Identifier (a name) Scope (characteristic that regularize access) (see lectures) Several variables of the same type can be stored in an array (see lectures)

Variables Declaration: int i; double epsilon; String greeting; String[] sliste; Initialization: i = 3; epsilon = 0.02; greeting = Hallo Welt! ; int j = 4; sliste = new String[10]; Using: // combined! i = i + j; i += j; // same as above j = j + 1; j += 1; // same as above j++; // same as above sliste[0] = Hallo ;

Primitive data types Name Description Value byte Byte-length integer -128 127 short Short integer -32768 32767 int Integer -2 32 2 32-1 long Long integer -2 64 2 64-1 float Single-precision floating point 2-149 (2-2 23 )*2 127 double Double-precision floating point 2-1074 (2-2 52 )*2 1023 char One character 1 unicode char. boolean Logical value (true or false) true/false String Text (a string of characters) For every primitive data type exists an equivalent class definition. (e.g. int -> Integer) * String is not really a primitive data type, but can be used as one

Operators Operator Use Description + Op1 + Op2 Add Op1 and Op2 - Op1 Op2 Substract Op1 from Op2 * Op1 * Op2 Multiply Op1 with Op2 / Op1 / Op2 Divides Op1 by Op2 ++ Op1 ++ Adds 1 to Op1 -- Op1 -- Substracts 1 from Op1 % Op1 % Op2 Computes div remainder < Op1 > Op2 Op1 is less than Op2 > Op2 > Op2 Op1 is greater than Op2 >= Op1 >= Op2 Op1 is greater than or equal Op2 <= Op1 <= Op2 Op1 is less than or equal Op2 == Op1 == Op2 Op1 is equal Op2!= Op1!= Op2 Op1 is not equal Op2 Op1 Op2 Op1 or Op2 && Op1 && Op2 Op1 and Op2!!Op1 Negates Op1 Op1 = Operand 1, Op2 = Operand 2

Predefined functions In Java exists a huge database of predefined routines and functions organized in hierarchic libraries (packages) Simple Output Use single routines with full path java.lang.system.out.println( Hallo Welt! ); Prefix java.lang is omittable (= default package) Calculation in java.lang.math Constants and functions

{ } int i = 7; double pi = 3.14159; Example String[] argliste = { Hola, Mundo! }; System.out.println( "Hello World!" ); System.out.println( "PI=" + pi ); System.out.println( "i+pi=" + (pi + i) ); System.out.println( argliste[0] + + argliste[1] ); Hello World! PI=3.14159 i+pi=10.14159 Hola Mundo! Output:

Homework Write an application that: Outputs the first command line parameter on the console > java MyClass Hello Hello > Calculates the area of a circle. The radius is given as parameter on command line > java MyCircle 1 The area of a circle with radius 1 is 3.141592653589793 >