Kickstart Intro to Java Part I

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

Programming Language Concepts: Lecture 2

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

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

Introduction to Java

Programming. Syntax and Semantics

CS 11 java track: lecture 1

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

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

Lecture 4: Introduction to Java and your Development Environment

Programming Language Concepts: Lecture 2

Assumptions. History

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.

Java Bytecode (binary file)

Computational Applications in Nuclear Astrophysics using Java Java course Lecture 1

CS11 Java. Fall Lecture 1

COMP 215: INTRO TO PROGRAM DESIGN. Prof. Chris Jermaine Chris Prof. Chris Dr. Chris

Lecture 1: Overview of Java

An overview of Java, Data types and variables

Learning objectives. The Java Environment. Java timeline (cont d) Java timeline. Understand the basic features of Java

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

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

Character Stream : It provides a convenient means for handling input and output of characters.

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

Introduction to Programming Using Java (98-388)

LECTURE 2 (Gaya College of Engineering)

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Getting started with Java

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

CS 231 Data Structures and Algorithms, Fall 2016

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

CHAPTER 1 Introduction to Computers and Java

BM214E Object Oriented Programming Lecture 8

STRUCTURING OF PROGRAM

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Introduction to Java

Java Basic Syntax. Java vs C++ Wojciech Frohmberg / OOP Laboratory. Poznan University of Technology

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

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

Midterms Save the Dates!

Values and Variables 1 / 30

A brief introduction to C programming for Java programmers

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

From C++ to Java. Duke CPS

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

JAVA: A Primer. By: Amrita Rajagopal

BM214E Object Oriented Programming Lecture 4

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

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

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Program Fundamentals

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

Fall 2017 CISC124 9/16/2017

Modern Programming Languages. Lecture Java Programming Language. An Introduction

Chapter 1 Getting Started

Pace University. Fundamental Concepts of CS121 1

Lecture 2, September 4

2 rd class Department of Programming. OOP with Java Programming

1. Download the JDK 6, from

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

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

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

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

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

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Administration. Classes. Objects Part II. Agenda. Review: Object References. Object Aliases. CS 99 Summer 2000 Michael Clarkson Lecture 7

JAVA An overview for C++ programmers

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

Lecture 1 - Introduction (Class Notes)

13 th Windsor Regional Secondary School Computer Programming Competition

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

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

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

CE221 Programming in C++ Part 2 References and Pointers, Arrays and Strings

Java Programming. Manuel Oriol, March 22nd, 2007

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

6.S096 Lecture 10 Course Recap, Interviews, Advanced Topics

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

17 Hello world 18 Type: String: literal 19 Standard API: System: out.println() 20 Hello world 21 Statement 22 Statement: simple statements are ended w

Lesson 04: Our First Java Program (W01D4

엄현상 (Eom, Hyeonsang) School of Computer Science and Engineering Seoul National University COPYRIGHTS 2017 EOM, HYEONSANG ALL RIGHTS RESERVED

Programming Language Concepts: Lecture 1

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

Outline. Object Oriented Programming. Course goals. Staff. Course resources. Assignments. Course organization Introduction Java overview Autumn 2003

INFO Object-Oriented Programming

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Answer1. Features of Java

VALLIAMMAI ENGINEERING COLLEGE

CS171:Introduction to Computer Science II

G52CPP C++ Programming Lecture 3. Dr Jason Atkin

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

1 Shyam sir JAVA Notes

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.

CS 335 Lecture 02 Java Programming

Java Basics. Object Orientated Programming in Java. Benjamin Kenwright

CompSci 125 Lecture 02

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

CS121/IS223. Object Reference Variables. Dr Olly Gotel

Transcription:

Kickstart Intro to Java Part I COMP346/5461 - Operating Systems Revision 1.6 February 9, 2004 1

Topics Me, Myself, and I Why Java 1.2.*? Setting Up the Environment Buzz about Java Java vs. C++ Basic Java Syntax Compiling and Running Java Programs Example(s) Next Tutorial References 2

Me, Myself, and I Name: Serguei Mokhov, for simplicity just Serguei, no Sir s please!!! :-) E-mail: mokhov@cs - maybe the best way to reach me. Questions are welcome (but please allow some time to reply - I m only one and you re so many :-) ). My Course web page for COMP346/546: http://www.cs.concordia.ca/~mokhov/comp346/ 3

Setting Up the Environment Please, refer to the separate set of slides for Java version and setting up environment. 4

Why is Java sooo co0ol??? Dear Serguei, you promised an Intro to Java!! Here it goes: Java is a quite simple, OO, distributed, interpreted, robust and secure, platform and architecture independent, multithreaded and dynamic language. A bunch of buzzwords? No, they aren t buzzwords, it s just an incomplete summary of the features of the language. 5

Java vs. C/C++ Java s syntax is very similar to that of C/C++; thus, it is quite easy to learn for C/C++ programmers. However, there are some conceptual differences behind this syntactical similarity, which you should pay close attention to. 6

Java vs. C/C++ (2) Java is pure OO language unlike C/C++. has everything as an object with and exception of few primitive data types (int, float, etc.). uses two-byte (16 bit) Unicode characters. has well defined and sometimes mandatory to use the Exception Handling Mechanism (will be covered later). has automatic garbage collection. 7

Java vs. C/C++ (3) Java DOESN T have Multiple inheritance (well, it somewhat does through interfaces and, but this is not a true inheritance). Templates. Vast majority of objects inherit from the Object class or its descendants (implicitly or explicitly), so any object can be cast to the Object class. Pointers, only references. All objects manipulated by reference by default in Java, not like in C++. So, there is no & in the syntax for function parameters. Operator overloading Some others 8

Java Program Structure Since Java is a pure OO language even the main() function has to be defined in a class. An instance of the class, which defines main(), will be the main thread when run. There should be only one public class with main in a file and the file name must be the same (including capitalization and spelling) as the main class name plus the.java extension. In general: one (any) public class per file. It is possible to have more than one class defined within one.java file, but only one of them should be public and the file name should correspond to that, public, class name. When a java program compiled with no errors with javac, a JVM object code is produced and stored in.class files. One file per class. 9

main() Java Program Structure (2) Declaration: public static void main(string argv[]){ } The argv is a list of arguments passed via command line, just like in C/C++. There is no argc in Java for a reason we ll see in a moment. Note, unlike in C/C++, there s no return value that you have to explicitly pass back using the return <int>; statement. Use System.exit(<int>); instead. 10

Examples Immortal Hello World Application Note, a java file must be named as HelloWorld.java public class HelloWorld { public static void main(string argv[]) { System.out.println( Hello dear World! It s me again! ); } } 11

Examples (2) Command Line Arguments ShowArguments.java public class ShowArguments { } public static void main(string argv[]) { } for(int i = 0; i < argv.length; i++) A public property of an array object System.out.println( Arg[ + i + ]: + argv[i]); Simple string concatenation with + 12

Compiling and Running a Java Application Command line compiler: javac javac HelloWorld.java To run the compiled code you have to invoke JVM to interpret it: java HelloWorld (Note: no extension this time, just the name of the main class!) 13

On-line Tutorial Sun s Tutorial on Java: http://java.sun.com/docs/books/tutorial/ Material for the course: Getting Started Learning the Java Language Essential Java Classes, especially Thread and Object Collections For your own pleasure and enjoyment: Everything else :-) 14

Next Tutorial Arrays Exception Handling Basics of Inheritance in Java Threads and Scheduling More Examples Whatever I forgot to mention above and your questions. 15

Links and References Official Java site: http://java.sun.com Java in a Nutshell, Second Edition by David Flanagan, (C) 1997 O Reily & Associates, Inc. ISBN: 1-56592-262-X Past semester s stuff from Paul and Tony on Dr. Aiman Hanna s web site: http://www.aimanhanna.com/concordia/comp346/ Manual pages for ssh, vim, [x]emacs, pico 16