CS 11 java track: lecture 1

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

CS11 Java. Fall Lecture 1

Programming Language Concepts: Lecture 2

Getting started with Java

Java Bytecode (binary file)

Lecture 1: Overview of Java

Introduction Basic elements of Java

CS 231 Data Structures and Algorithms, Fall 2016

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

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

Introduction to Java

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Software and Programming 1

Programming Language Concepts: Lecture 2

COE318 Lecture Notes Week 3 (Week of Sept 17, 2012)

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

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

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

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

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

13 th Windsor Regional Secondary School Computer Programming Competition

Program Fundamentals

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Programming Language Concepts: Lecture 1

An overview of Java, Data types and variables

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

CS 11 C++ track: lecture 1

History of Java. Java was originally developed by Sun Microsystems star:ng in This language was ini:ally called Oak Renamed Java in 1995

BASICS.

Praktische Softwaretechnologie

CMSC131. Introduction to your Introduction to Java. Why Java?

4 Programming Fundamentals. Introduction to Programming 1 1

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Chapters 1-4 Summary. Syntax - Java or C? Syntax - Java or C?

Getting Started with Java. Atul Prakash

Compiling Techniques

1. Download the JDK 6, from

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Lecture 2, September 4

Introduction to Programming Using Java (98-388)

Inf1-OP. Course Overview. Volker Seeker, adapting earlier version by Perdita Stevens and Ewan Klein. February 26, School of Informatics

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Programming. Syntax and Semantics

Getting started with Java

Software and Programming 1

1.1 Your First Program

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

Object-oriented programming. and data-structures CS/ENGRD 2110 SUMMER 2018

Computer Components. Software{ User Programs. Operating System. Hardware

CompSci 125 Lecture 02

Full file at

CS 106 Introduction to Computer Science I

What did we talk about last time? Examples switch statements

Computer Science II Lecture 1 Introduction and Background

1.1 Your First Program

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi...

Lecture Set 4: More About Methods and More About Operators

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings

CSE 421 Course Overview and Introduction to Java

Introduction to Java

Tutorial 1 CSC 201. Java Programming Concepts عؾادئماظربجمةمبادؿكدامماجلاصا

Java Basic Programming Constructs

Full file at

Lecture Set 4: More About Methods and More About Operators

CS61C Machine Structures. Lecture 3 Introduction to the C Programming Language. 1/23/2006 John Wawrzynek. www-inst.eecs.berkeley.

Simple Java Programs. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Section 2.2 Your First Program in Java: Printing a Line of Text

Who and what can help? Inf1-OP. Lecturer: Timothy Hospedales TA: Natalia Zon

data_type variable_name = value; Here value is optional because in java, you can declare the variable first and then later assign the value to it.

Administrative Stuff. Inf1-OP. Additional help? Who to contact for help? Course Overview

Object-Oriented Programming

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Inf1-OOP. Textbooks. Who and What. Organizational Issues. Why Java? Course Overview. Hello, World! in Java. Ewan Klein, Perdita Stevens

COMP-202: Foundations of Programming

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2015

Kickstart Intro to Java Part I

Simple Java Program. public class HelloWorld {

CPSC 213. Introduction to Computer Systems. Numbers and Memory. Unit 1a

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

Atelier Java - J1. Marwan Burelle. EPITA Première Année Cycle Ingénieur.

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

CT 229 Fundamentals of Java Syntax

Code Ninjas: Introduction to Computer Science. Macomb Science Olympiad Presented by Swati Dharia

Introduction to Java. Nihar Ranjan Roy.

AP Computer Science A: Java Programming

Java TM Introduction. Renaud Florquin Isabelle Leclercq. FloConsult SPRL.

Computational Expression

C02: Overview of Software Development and Java

CISC 370: Introduction to Java

Course Outline. Introduction to java

Branching and Boolean Expressions

CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

Inf1-OOP. Textbooks. Who and What. Organisational issues. Why Java? Course Overview. Hello, World! in Java

MODULE 02: BASIC COMPUTATION IN JAVA

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Introduction to Java

CS 61C: Great Ideas in Computer Architecture Introduction to C

Transcription:

CS 11 java track: lecture 1 Administrivia need a CS cluster account http://www.cs.caltech.edu/ cgi-bin/sysadmin/account_request.cgi need to know UNIX www.its.caltech.edu/its/facilities/labsclusters/ unix/unixtutorial.shtml track home page: www.cs.caltech.edu/courses/cs11/material/java/mike

prerequisites some programming experience CS 1 ideal, not required familiarity with C syntax

assignments 1st assignment is posted now due one week after class, midnight late penalty: 1 mark/day redos

textbook, online tutorials Arnold, Gosling, Holmes: The Java Programming Language, 3rd. ed. earlier editions NOT acceptable java on-line tutorials: http://java.sun.com/docs/books/tutorial/ reallybigindex.html very good material!

what is java? java is an object-oriented programming language a programming environment a large set of libraries (java API) a philosophy

java philosophy programs should be portable "write once, run anywhere" programs should be safe no core dumps, no memory corruption programs should be easy to write and understand programs should be as efficient as possible subject to the above constraints

programming in java (1) version: java 1.4.2 (on CS cluster) programmer writes source code files end in ".java" extension java compiler (javac) converts (compiles) source code into "bytecode" (files ending in ".class") bytecode is "machine code" for Java Virtual Machine (JVM)

programming in java (2) example: % javac Foo.java Foo.class (may compile other files too if "Foo.java" depends on them)

programming in java (3) JVM (program name: java) executes bytecode to run the program JVM implementations exist for most platforms (Windows, Linux, Mac...) % java Foo executes bytecode in Foo.class can be compiled to machine code on-the-fly

libraries java API (application programming interface) HUGE set of libraries, including graphics networking database input/output http://java.sun.com/j2se/1.4.2/docs/api/index.html

the java language (1) "object oriented" object: data + functions acting on that data class: template for building objects; includes data (fields) that every object contains functions (methods) that can act on the object objects are instances of a particular class

the java language (2) all data is either an object i.e. an instance of some class a primitive data type int float, double char boolean

the java language (3) java is strongly, statically typed strongly typed: all data has a type statically typed: all types must be declared before use type declarations can occur anywhere in source code int foo; // foo has type int

the java language (4) methods have a name a set of arguments with their types a return type some optional modifiers methods written inside class definition methods have implicit extra argument: the object they're part of (called this)

"hello world" program (1) in file "HelloWorld.java": class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!");

"hello world" program (2) class definition: class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!"); file must be called "HelloWorld.java"

"hello world" program (3) method definition: class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!");

"hello world" program (4) method name: class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!"); program always starts executing with main

"hello world" program (5) method arguments: class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!"); String[] = array of strings (command line args)

"hello world" program (6) method return type: class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!"); void means "doesn't return anything"

"hello world" program (7) method modifiers: class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!"); we'll discuss these later

"hello world" program (8) method body: class HelloWorld { public static void main(string[] args) { System.out.println("Hello, world!"); print "Hello, world!" to the terminal (System.out)

"hello world" program (9) compile: % javac HelloWorld.java HelloWorld.class run: % java HelloWorld Hello, world! %

data types int integers float single precision floating point double double precision floating point char Unicode characters (16 bit) boolean true or false (not 0 or 1) byte 8 bits; "raw data" String character strings

operators like in C: + - * / % = ++ -- += -= etc. precedence: a + b * c a + (b * c) NOT (a + b) * c use parentheses if need to override defaults

comments three kinds: // This comment goes to the end of the line. /* This comment can span * multiple lines. */ /** * This comment is for documentation. */

conditionals if / else if / else like in C: int i = 10; if (i < 20) { System.out.println("less than 20"); else if (i == 20) { System.out.println("equal to 20"); else { System.out.println("greater than 20");

loops (1) for and while loops like in C: int i; for (i = 0; i < 10; i++) { // do something with i while (i < 20) { // do something with i // increment i

loops (2) can declare types at first use: for (int i = 0; i < 10; i++) { // do something with i now "i" only usable inside the loop judgment call; usually the right thing to do

that's all for now this is enough for 1 st assignment lots more to come!