CompSci 125 Lecture 02

Similar documents
Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

COMP 202 Java in one week

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

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

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

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

An overview of Java, Data types and variables

2 rd class Department of Programming. OOP with Java Programming

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

ECE 122 Engineering Problem Solving with Java

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

CHAPTER 1 Introduction to Computers and Java

Java is a high-level programming language originally developed by Sun Microsystems and released in Java runs on a variety of

3. Java - Language Constructs I

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

Program Fundamentals

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CS1007: Object Oriented Design and Programming in Java. Lecture #2 Sept 8 Shlomo Hershkop Announcements

DM550 Introduction to Programming part 2. Jan Baumbach.

Building Java Programs. Introduction to Programming and Simple Java Programs

CSC 1214: Object-Oriented Programming

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

CS 231 Data Structures and Algorithms, Fall 2016

Chapter 1. Introduction

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

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

Chapter 1 Introduction to Computers, Programs, and Java

Java Programming. Atul Prakash

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

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

Pace University. Fundamental Concepts of CS121 1

3 CREATING YOUR FIRST JAVA APPLICATION (USING WINDOWS)

Getting started with Java

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

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

CS 11 java track: lecture 1

For the course, we will be using JCreator as the IDE (Integrated Development Environment).

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

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

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

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

Chapter 2. Elementary Programming

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

AP Computer Science A: Java Programming

Lecture 1: Overview of Java

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

Fundamentals of Programming. By Budditha Hettige

CSE 421 Course Overview and Introduction to Java

Lesson 01 Introduction

Building Java Programs. Chapter 1: Introduction to Java Programming

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

CMSC 150 LECTURE 1 INTRODUCTION TO COURSE COMPUTER SCIENCE HELLO WORLD

13 th Windsor Regional Secondary School Computer Programming Competition

Java Bytecode (binary file)

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

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Getting Started with Java. Atul Prakash

Crash Course Review Only. Please use online Jasmit Singh 2

Introduction Basic elements of Java

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

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Chapter 1 Introduction to Computers, Programs, and Java. What is a Computer? A Bit of History

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

Java Programming. Zheng-Liang Lu. Java 301 Summer Department of Computer Science & Information Engineering National Taiwan University

Course Outline. Introduction to java

CSC116: Introduction to Computing - Java

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

Lecture 4: Introduction to Java and your Development Environment

CS 177 Recitation. Week 1 Intro to Java

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

COMP 202. Java in one week

-Alfred North Whitehead. Copyright Pearson Education, 2010 Based on slides by Marty Stepp and Stuart Reges from

Accelerating Information Technology Innovation

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

Lecture 1: Basic Java Syntax

CSCI 2101 Java Style Guide

Games Course, summer Introduction to Java. Frédéric Haziza

AP Computer Science A

Introduction to Java

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

COMP 202 Java in one week

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

Introduction to Java

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B

Lab5. Wooseok Kim

CHAPTER 1. Introduction to JAVA Programming

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

A web-based IDE for Java

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

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

Introduction to Computers and Java. Objectives. Outline. Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich.

Announcements. 1. Forms to return today after class:

Course information. Petr Hnětynka 2/2 Zk/Z

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

Lesson 04: Our First Java Program (W01D4

Certified Core Java Developer VS-1036

Transcription:

Assignments CompSci 125 Lecture 02 Java and Java Programming with Eclipse! Homework:! http://coen.boisestate.edu/jconrad/compsci-125-homework! hw1 due Jan 28 (MW), 29 (TuTh)! Programming:! http://coen.boisestate.edu/jconrad/cs125-programming-assignments! p0 due Jan28 (MW), 29 (TuTh) Homework 1! hw1 posted on web site. Due Jan 28 (MW), 29 (TuTh)! Hand-in completed homework using onyx submit command:! CS125-003: submit dornelas cs125-3 hw1!! CS125-004: submit dornelas cs125-4 hw1!! dornelas refers to Diana Ornelas, our sections TA! Be nice to the TAs --- they grade your homework Program 0! Posted on web site. Due Jan 28 (MW), 29 (TuTh)! The instructions in the assignment to hand-in your completed program assume you placed the requested files (Hello.java, Quote.java and README) in a folder called p0! CS125-003: submit dornelas cs125-3 p0!! CS125-004: submit dornelas cs125-4 p0!! Be nice to the TAs --- they re going to save you

Course Web Site! http://coen.boisestate.edu/jconrad! Course syllabus! Link to the Facebook Group! Slides! Homework assignments! Programming assignments! Installing/Using programming tools! Onyx Computer Lab information! Files/documents for distribution Facebook Group! http://www.facebook.com/groups/157148657767138! Optional but well-received! Extends classroom discussion! Discuss questions about lecture, Java and Computing! Virtual helpdesk for assignments --- best source for help when you are off-campus Review:''Everything'is'in'RAM' Computer Organization Random Access Memory (RAM) SATA bus Central Processing Unit (CPU) Northbridge High-speed bus controller Southbridge Low-speed bus controllers Programs Numbers Documents Spreadsheets Photographs PowerPoint slides MP3s Most everything

Memory Organization! If the computer encodes everything in memory with 1s and 0s! How does Java know whether to interpret the 1s and 0s in memory as a number, or a text string, or a photograph, or music, or a video, or as a program? Memory Organized into Bytes! A byte is the smallest addressable location in RAM! Every byte has a unique numerical address assigned by hw! The CPU accesses a specific byte in memory by referencing its numerical address 01110000011010101000011111100010101110001110011111 01110000 11010111 10001010 01010111 00000000 11101000 00010111 11111111 00000001 00100000 01010101 10001000 10011001 11011011 10101010 10101000 Types determine how Java interprets the content of memory! If everything in memory is organized as a sequence of bytes, each containing 8 bits, each of these being a 1 or 0! How does a program know to interpret the content of memory as a number, text string, photograph, music, video?! A type determines how Java interprets the 0s and 1s in memory at a specified address Example Java Types! integer: A positive or negative whole number! double: Approximates a rational number! String: A sequence of characters (e.g. abc )! You will define your own type known as a class!! More!

Variables Store Data in RAM A Java variable stores data in memory Every Java variable has a numerical address, name and type Java programmers almost always refer to variables by name Java takes care of mapping the variable names to RAM locations Variable Name Numerical Address Value 1000 0 1001 1 1002 255 somecharacter 1003 A numberx 1005 21,983,114 Review: Java Data Types and Variables! Data Type! Determines how a value is encoded with 0s and 1s in memory! Does not occupy memory it s just a plan (like a blueprint)! Variable! Occupies one or more bytes of memory! Implements an instance of a data type! Has a unique name! Has a unique numerical (usually unknown) address in memory! Has a value Java Programs are Composed of es! Programs are organized into smaller units known as classes! Each class may define variables storing data (numbers, strings of characters, pictures, sound, or even other classes)! Each class may define methods containing a sequence of instructions for the computer! A class is one form of a Java type! A class does not occupy memory --- it s a plan (blueprint) Java source code! You compose and revise in a text editor! Understandable by programmers --- you can read it! The Java source code defines one or more classes! The CPU cannot directly execute Java source code!! The CPU executes a machine language! The Java compiler translates the source code into machine language for the CPU

The Java Vision Example: Java Source Code public class HelloWorld {!!public static void main(string[] args) {!!!System.out.println( Hello, world! );!!}! }!! Originally intended for mobile devices (e.g. cell phones)! Programmer would compose a program in Java source code! Then compile it into a bytecode version of the same program! Distribute machine-independent bytecode to end-users! End-users would install the bytecode on their devices! Vendors would include a Java Runtime Environment (JRE also known as the JVM) on every device! JRE executes the bytecode! Any program would run anywhere!! Didn t work out as planned, but Java became important anyway James Gosling Program Structure Java is! A high-level language! Machine independent! Object-oriented! An important programming language! Popular on servers Program Variables Methods Methods

An object is an instance of a class = Blueprint One blueprint to create several similar, but different, houses: An instance of a CheckingAccount class CheckingAccount An instance of a CheckingAccount A CheckingAccount class defines common behaviors (methods) for adding and withdrawing funds. The class also defines common attributes such as name, account number and balance But the values of these attributes are unique to each instance of a CheckingAccount object object Copyright 2012 Pearson Education, Inc. Object:( An'object'is'an'instance'of'a'class, ' An'object'may'implement'methods'and/or'variables'in' memory, ' A'reference,variable'may'contain'the'address'of'an'object'in' the'computer s'memory' ' You'compose'classes'in'your'java'source'code' ' Your'execuAng'program'builds'( new'up )'objects' ' Objects'may' model 'realgworld'things'(e.g.'a'student)' Packages help organize large programs Package Program Package Variables Methods Methods Variables Methods

Built-in Package java.lang Built-in Package java.util Package java.lang Package java.util System String Math Scanner Random Date Java Program Structure Example: public class HelloWorld {! public static void main(string[] args) {! System.out.println("Hello World!");! }! } //HelloWorld! // comments about the class public class MyProgram { Every Java program defines one or more classes. Hint: Java requires the class filename, e.g. HelloWorld.java, to match the class name with the.java extension. } Copyright 2012 Pearson Education, Inc.

Example: Method public class HelloWorld {! public static void main(string[] args) {! System.out.println("Hello World!");! }! } //HelloWorld! Most classes define one or more methods. This class defines a single method named by the identifier, main. This method contains a single statements explaining how the computer is to perform a specific task. The main Method! Special method known as main public void main(string[] args) { System.out.println( Hello world ); }! This method must be named main as in the example above! Your program defines exactly one main method! Java starts your program by invoking your main method Java Program Structure Example: Statement public class HelloWorld {! public static void main(string[] args) {! System.out.println("Hello World!");! }! } //HelloWorld! // comments about the class public class MyProgram { // comments about the method public static void main (String[] args) { } The statement System.out.println invokes the method println implemented by the class out built into the Java System package. } Confusing? It just prints a String to stdout. In this case, the String is Hello World!. Copyright 2012 Pearson Education, Inc.

Definitions: Code Block! Java source code placed inside of braces, a sub-unit of code { } System.out.println( Beginning of this code block ); System.out.println( Middle of this code block ); System.out.println( End of this code block ); Identifier Rules! You may use letters, digits, underscores or the dollar sign! Must start with a letter or a dollar sign! Must not be a Java keyword Valid Identifiers SoccerTeam soccer_team $cash4game numberofgoals Soccer Invalid Identifiers soccer team soccer-team 4game #goals class Java Reserved Words abstract assert boolean break byte case catch char class const continue default do double else enum extends false final finally float for goto if implements import instanceof int interface long native new null package private protected public return short static strictfp super switch synchronized this throw throws transient true try void volatile while Review: Key Java Concepts! Programs are constructed with one or more classes! A class may define methods and/or variables! A method contains a sequence of statements! es are one form of a Java type! The class is just the plan, a blueprint! Your program may construct objects, instances of classes, in memory Copyright 2012 Pearson Education, Inc.

Language Levels There are four programming language levels: fourth-generation language (RPG-II, SPSS, SQL, R ) high-level language (Java, C#, C++) assembly language machine language Introduction to Computer Science I Java Program Development Each type of CPU has its own specific machine language The other levels were created to make it easier for a human being to read and write programs Copyright 2012 Pearson Education, Inc. How does a Java Program become Machine Language executed by the CPU? Text Editor Java Program Byte Code Java Compiler Java Runtime Environ Machine Language Low-Level vs. High-Level Languages! Instructions in a low-level language are specific to a particular CPU. We say they are machine-dependent. Examples: Machine language, assembly language.! Instructions in a high-level language are relatively independent of a particular CPU. We say these are machine-independent. Example: Java You write this CPU executes this

Syntax and Semantics The syntax rules of a language define how we can put together symbols, reserved words, and identifiers to make a valid program The semantics of a program statement define what that statement means (its purpose or role in a program) A program that is syntactically correct is not necessarily logically (semantically) correct A program will always do what we tell it to do, not what we meant to tell it to do Development Tools: What software do I install? Your Computer Your own LINUX Computer Your own OS X Computer ET213/214 LINUX Computers Java JDK Install fm ur distro Already installed (Lion asks on first use) Already installed eclipse Text Editor Install fm ur distro Install on hard drive if you choose eclipse Already installed Copyright 2012 Pearson Education, Inc. Development Tools: LINUX in ET213 and ET214! LINUX --- Important for CompSci majors! Software is already installed, but you have to learn how to use LINUX! Accounts are available --- see me if you haven t by now! Computer Labs Doc: http://cs.boisestate.edu/~jconrad A Couple Important Details! Java requires the name of the source code and byte code files to be the same except for the extensions! Eclipse will normally take care of this, but you can get in trouble outside of Eclipse! The source code file must have the.java extension! The bytecode file must have the.class extension

How to Install the Eclipse IDE How to Install Eclipse --- Part II! http://www.eclipse.org/downloads! You only need to do this on your own computers! Eclipse is already installed on the ET213/214 LINUX systems ( onyx )! Must install the Java Development Kit (JDK) prior to installing Eclipse! Installing the Eclipse IDE at http://cs.boisestate.edu/~jconrad! Problems? Post screenshots/questions on the FaceBook group! How to Install Eclipse --- Part VIII! Click the curvy arrow to get past the Eclipse welcome screen! Hint: Different versions of Eclipse place the arrow at different places How to Install Eclipse --- Part IX! This is what eclipse looks like after you get it running

Eclipse running on LINUX in ET213/214 How to run Eclipse on LINUX On the ET213/214 Systems (onyx)! Eclipse is already on installed on CompSci s LINUX systems! Login with your CompSci onyx account! Run from the Desktop menu! Or Get a terminal shell (e.g. bash) window and enter the command, /usr/local/eclipse/eclipse Writing your First Program: Using Eclipse! Eclipse organizes each homework assignment in a project! An Eclipse project is something like a folder! You begin by running Eclipse and creating a new project Create a new Java Project

Name your project (e.g. hw2 ) Result of creating my project hw2 Create a New Name your class HelloWorld

Writing your 1 st Program: Eclipse will compose part of your first program! You must write the remainder Click Green Arrow to Run Program Let Eclipse Save HelloWorld.java

Your Program s Output Appears Where did Eclipse hide HelloWorld.java? Where did Eclipse hide HelloWorld.class? Running your program in a command shell

Java Development Process Bytecode version What Eclipse did for You Text Editor HelloWorld.class Java Compiler Java Runtime Environ! Eclipse composed part of the HelloWorld class for you, but you ll need to know it on the exams! Eclipse invoked the Java Compiler automatically for you! Eclipse also invoked the Java Runtime Environment for you! The JRE invoked your program s main method to start it HelloWorld.java Machine Language Java source code CPU executes this