Chapter 3 Intro to Java

Similar documents
CS 177 Recitation. Week 1 Intro to Java

Java Bytecode (binary file)

Fundamentals of Programming. By Budditha Hettige

Chapter 2: Programming Concepts

Creating a Program in JCreator. JCreator is then used to create our program. But the first step is to create a new file.

Getting Started with Java. Atul Prakash

Week 2: Data and Output

Lecture 02, Fall 2018 Friday September 7

Chapter 2 Exercise Solutions

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

Introduction to OOP Using Java Pearson Education, Inc. All rights reserved.

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

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Università degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M

Computer Science is...

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

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

Full file at

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java

Programming with Java

AP Computer Science A Unit 2. Exercises

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

Computer Programming, I. Laboratory Manual. Final Exam Solution

Chapter 2, Part I Introduction to C Programming

Introduction to Computer Science Unit 2. Notes

Lesson 2: First Java Programs

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

4 Programming Fundamentals. Introduction to Programming 1 1

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

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

Introduction. Introduction to OOP with Java. Lecture 01: Introduction to OOP with Java - AKF Sep AbuKhleiF -

Lab # 2. For today s lab:

CS 231 Data Structures and Algorithms, Fall 2016

Program Fundamentals

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

Lesson 04: Our First Java Program (W01D4

CS 106 Introduction to Computer Science I

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

Certified Core Java Developer VS-1036

Mobile App:IT. Methods & Classes

CSE 114 Computer Science I

CHAPTER 7 OBJECTS AND CLASSES

Full file at

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Outline. CIS 110: Introduction to Computer Programming. What is Computer Science? What is computer programming? What is computer science?

Table of Contents Date(s) Title/Topic Page #s. Abstraction

Introduction to Java Applications; Input/Output and Operators

ICOM 4015: Advanced Programming

B.V. Patel Institute of BMC & IT, UTU 2014

IT 374 C# and Applications/ IT695 C# Data Structures

First Java Program - Output to the Screen

download instant at

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

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

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

CS 11 java track: lecture 1

Introduction to Java. Handout-1d. cs402 - Spring

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

Programming Languages (Outsource: 2-2)

Introduction to Software Development (ISD) David Weston and Igor Razgon

CS11 Java. Fall Lecture 1

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

4 WORKING WITH DATA TYPES AND OPERATIONS

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

13 th Windsor Regional Secondary School Computer Programming Competition

COMP 110 Project 1 Programming Project Warm-Up Exercise

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

AP CS Unit 3: Control Structures Notes

Java Basics Lecture: January 26, 2012 (On-line Lecture 1)

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

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Lecture 4: Introduction to Java and your Development Environment

Lecture 14 CSE11 Fall 2013 For loops, Do While, Break, Continue

Give one example where you might wish to use a three dimensional array

CHAPTER 7 OBJECTS AND CLASSES

Oct Decision Structures cont d

Supplementary Test 1

CP122 CS I. Chapter 1: Introduction

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

Conditionals, Loops, and Style

Conditionals, Loops, and Style. Control flow thus far. if statement. Control flow. Common branching statement Evaluate a boolean expression

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

An overview of Java, Data types and variables

Anatomy of a Java Program: Comments

From Algorithms to Architecture....a lightning introduction to computer architecture

Introduction to Java Applications

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Sri Vidya College of Engineering & Technology

A variable is a name that represents a value. For

CS111: PROGRAMMING LANGUAGE II

TUGCE KEMEROZ - ASLI OZKAN - AYSE TARTAN. Week 12/02/ /02/2007 Lecture Notes:

Chapter 5 Control Statements: Part 2 Section 5.2 Essentials of Counter-Controlled Repetition

Object-oriented programming in...

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Transcription:

Chapter 3 Intro to Java Introducing Java Barrett Computer Science Designing Technology Solutions 1

2 Key Terminology - OS Operating System

3 Why Program in Java? Java is an Object Oriented Programming (OOP) language. OOP programmers create programs, called classes, that can be used over and over again in/for a variety of other programs. The Java platform runs on all major operating systems (windows and Mac OS) thus allowing Java applications to run on just about any computer.

4 What A Java program consist of: Object Class Package

5 Example of Classes and Objects Lets look at an example The class defines the information contained in a Blue-ray movie database (e.g., Red Box) - title, genre, year, loan status and borrower name. The objects in this example will be specific entries.

6 So what does that mean?...(1 of 3) Classes define the type of data and actions, that will be associated with an object. Objects are the instructions for performing actions on a specific set of data. Note: A class can be used to create many objects.

7 So what does that mean?...(2 of 3) Note: A class can be used to create many objects.

8 So what does that mean?...(3 of 3) A Package is a group of related classes Packages are sometimes referred to as libraries.

9 A Java Application There are four main parts in a Java application: Statement instructions A semicolon is required to indicate the end of a statement. Related statements are enclosed by curly braces { } to begin and end the instructions.

10 A Java Application Controlling Class program starting point Public class Greeting is our class declaration. The class is available to anyone (public) and is named greeting.

11 A Java Application Method named set of statements performing a single well defined task. The main () method is placed in the controlling class. To define our main method we will use the following method declaration: Public static void main (String[] args){ } The main method s statements are automatically run when the program is executed.

12 A Java Application cont. Comments info provided to reader and has nothing to do with executing a program The three types of comments: 1) /* */ to enclose single or multiline comments 2) // are used for adding a comment to the end of a statement or to create a single line comment 3) /** */ are used for documentation.

13 Let s look at an Example HERE is an example of java code.. comment //The Greeting class displays a greeting class declaration public class Greeting{ public static void main(string[] args){ } System.out.println("Hello,world!"); } statement method

14 Making your first Java Project and class - Walk class through example using the LCD Projector. Dismiss students to make their first project and class Project Name: Bbarrett Chpater3 Class Name: HelloWorld Comments include: /* Name Date Period Class */

15 Java Terminology Java code typed by a programmer is called source code. For this code to execute it must be translated into code the computer understands. This process of translating is called compiling. Compiled java source code is called bytecode. The java Virtual Machine (JVM) interprets the bytecode.

16 Executing a Java Application source code public class Greeting public static void System.out.printl } } compiler...c cilbup bytecode 03 3b 84 01 ff f9 68 05 1a JVM...48 b3 30 Hello,world! This is your output

17 General Java Notes Programs are created to solve problems All Java Applications have at least one class The main method is the method that runs (executes) a program Platform Independence: This means that Java applications can be run on just about any computer no matter the brand

18 Displaying Output Output stream sends data to an output device To process data for the output stream, Java provides the System class with methods for displaying output Displaying data to the standard output stream (Typically this is the computer screen): You would Use System.out.

19 Displaying Output Examples of a type of output stream are: System.out.print() System.out.println() These methods require arguments in the () One type of arguments are strings Strings A set of characters, which are enclosed in quotation marks.

20 Escape Sequences Another example of output are called escape sequences escape sequence is a backslash (\) followed by a symbol that together represent a character. They are used to display special characters The 4 Commonly used escape sequences: 1. \n newline 2. \t tab (8 spaces) 3. \\ backslash 4. \" double quotation mark

Exercises (Chapter 3 pt. 1) 21

22 Exercises Exercise 3 (p 72) Save as Ch3Ex3 Exercise 7 (p 74) Save as Ch3Ex7 Both exercises will be saved in your chapter 3 project folder.

23 The Format Method CS, DTS

24 The format() Method The System.out.format() method is used to Control the way output is displayed.

25 The format() Method String A sequence comprised of characters. Ex: This sentence is a string. Numbers can be represented as strings or numerals. It all depends on how it is defined by the programmer, aka YOU!

26 The format() Method Example The format string specifier takes the form: %[alignment][width]s % - Indicate the start of a specifier Alignment means skip for right alignment You would use a minus sign (-) for left alignment Width the number of characters to use for output S indicates that the corresponding argument is a string An example. System.out.format("%-6s %4s", "Test1", "90"); Will display: Test1 90

Exercises (Chapter 3 pt. 2) 27

28 Exercises Exercise 4 (p 73) Save as Ch3Ex4 Exercise 5 (p 73) Save as Ch3Ex5 Both exercises will be saved in your chapter 3 project folder.