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

Save this PDF as:

Size: px
Start display at page:

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

Transcription

1 Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you will only need to do this once for every installation of BlueJ.) 2. Make sure the JDK selected is version or better. If it is not, you may have to open the bottom of the window and browse or search for a newer JDK. If you can t find one, you will need to install a newer JDK from java.sun.com. 3. Close this window, and start BlueJ as you normally would. Spring 2006 CISC101 - Prof. McLeod 1 Spring 2006 CISC101 - Prof. McLeod 2 4. Click on Project, then New Project. 5. Browse to a convenient folder (where you can find the project again), and type in a name for the Project don t use any spaces (always a good idea with Java filenames and folders!). 6. Click on Create to close the New Project window. The new project name is now at the top of the window. 7. Click on the New Class button at the left. 8. Type in the class s name: HelloWorld and leave the class checked off. 9. Click on OK to close the New Class window. 10.You can now see a new little box representing your class. You can enlarge the box and/or drag it around the screen (entertaining, but not useful!). 11.Double click on the little box, to open the code editor window. 12.Delete all the junk in the editor window by pressing <Cntrl>A followed by <Del>. We don t need all this stuff! (code auto-generation ). Spring 2006 CISC101 - Prof. McLeod 3 Spring 2006 CISC101 - Prof. McLeod Type in the class container code: public class HelloWorld { } 14.Save your program by typing <Cntrl>s or go to Class then choose Save. (Save your code often!!!) 15.You can choose to add a comment at the top of your program, and another comment by the } : // My very first Java program! // By me! public class HelloWorld { } // end HelloWorld Spring 2006 CISC101 - Prof. McLeod 5 Spring 2006 CISC101 - Prof. McLeod 6 1

2 16.Add the container for the main method: // My very first Java program! // By me! public class HelloWorld { public static void main (String[] args) { } // end main } // end HelloWorld 17.Save your program again. Note message at bottom right corner saying Saved. 18.Click on the Compile at the top left. Fix any compilation errors. 19.Just in case you did not have any make an error (like removing a } or { ) and compile again to see what happens. Click on the? to see a semi-useful message about the compilation error. 20. Fix all errors and re-compile. Spring 2006 CISC101 - Prof. McLeod 7 Spring 2006 CISC101 - Prof. McLeod 8 21.Leave the editor window open, but move to the original Project window. Note how the box looks different if your class has not been compiled. You cannot run your program until it has been compiled. 22.Right click on your little box and choose void main(string[] args) to run your program. 23.Click on OK without changing any parameters in the little text box. 24. Nothing happens right? 25.Our program did what we told it to do nothing!! 26.Go back to the editor window and add the following output statement: System.out.println("Hello World!"); 27.Save, compile, and then run your program, as before. (Always, always Save before running!) Spring 2006 CISC101 - Prof. McLeod 9 Spring 2006 CISC101 - Prof. McLeod You should see the following little exciting window called the Terminal or Console window: 29.On your own, from the project window, choose Help then BlueJ Tutorial, if you wish to know more. Spring 2006 CISC101 - Prof. McLeod 11 HelloWorld in Eclipse 1. The first time you start Eclipse, you will see the Welcome page. You should check out some of the information here particularly one of the simple Tutorials and the Overview. 2. For now, click on the Workbench link at the top right. 3. Before proceeding, and for the first time only, you should check the configuration of the program, to make sure it is running the correct Java JDK. Spring 2006 CISC101 - Prof. McLeod 12 2

3 4. In the top menu bar, go to Window then Preferences. 5. Click on the + beside Java and then choose Installed JRE s. You should see the window on the following slide: Spring 2006 CISC101 - Prof. McLeod 13 Spring 2006 CISC101 - Prof. McLeod Make sure the JRE is checked off. 7. Now choose Compiler and make sure the Compiler Compliance Level is set to You should see the following window: Spring 2006 CISC101 - Prof. McLeod 15 Spring 2006 CISC101 - Prof. McLeod There are lots of other options in Preferences but we do not have to worry about any of them right now! 10.Click on OK to close the Preferences window. This might take a little while and if you are asked to re-compile, say OK. 11.Just as in BlueJ, you need to create a new project. Projects can contain many java files, however. Click on the little folder thing at the top left: 12. Click on Project you will see the Project creation wizard: 13.Click on the Next > button. Spring 2006 CISC101 - Prof. McLeod 17 Spring 2006 CISC101 - Prof. McLeod 18 3

4 14.On this screen enter a name for your project. You will see: 15. Click on Finish. 16.Your new project will now be listed at the left in the Package Explorer. Click on the + beside the project s name. 17.There is a link to the JRE System Library, that we are going to ignore. 18.Click on that little folder thing at the top left, and choose Class this time to start the New Java Class wizard. You should see the window on the next slide: Spring 2006 CISC101 - Prof. McLeod 19 Spring 2006 CISC101 - Prof. McLeod Type in HelloWorld for the name of your class. Make sure the method stub checkbox for main is checked (to make your life easier!). 20.Click on Finish and your new class will show up in the editor window. 21. Delete comments and/or add your own. 22.Add the System.out.println() line inside the main method, as you did before. 23.You will notice some advanced editor features when you hit period for example, and other things such as auto indentation. 24.Save your program using <Cntrl>s or by clicking on the little floppy disk button at the top left. Spring 2006 CISC101 - Prof. McLeod 21 Spring 2006 CISC101 - Prof. McLeod Click on the little green arrow thing at the top, as shown on the next slide. 26.Note that Eclipse compiles your program when it saves it. Spring 2006 CISC101 - Prof. McLeod 23 Spring 2006 CISC101 - Prof. McLeod 24 4

5 27.Provided you have not made any compiler errors, you should see your output in the Console window at the bottom. 28.Make some deliberate errors in your code to see what happens. Eclipse pre-compiles your program as you write it, and will not run it until you have fixed all the errors it has detected. Development Environments You can choose BlueJ or Eclipse (or any other tool you like!). I will usually use Eclipse for class demonstrations. (I m not going to try the command prompt again ) Spring 2006 CISC101 - Prof. McLeod 25 Spring 2006 CISC101 - Prof. McLeod 26 Java Keywords abstract double int super assert else interface switch boolean enum long synchronized break extends native this byte for new throw case final package throws catch finally private transient char float protected try class goto public void const if return volatile continue implements short while default import static do instanceof strictfg Spring 2006 CISC101 - Prof. McLeod 27 Java Keywords, Cont. The goto keyword is reserved but does not do anything in java. On the next slide I have highlighted the keywords that we will be using in this course. Spring 2006 CISC101 - Prof. McLeod 28 Java Keywords for CISC101 abstract double int super assert else interface switch boolean enum long synchronized break extends native this byte for new throw case final package throws catch finally private transient char float protected try class goto public void const if return volatile continue implements short while default import static do instanceof strictfg Spring 2006 CISC101 - Prof. McLeod 29 Java Keywords for CISC101, by Category Primitive Types boolean byte char double float int long short Conditionals if else switch case Loops do for while continue break Structural class import new public return static final void Spring 2006 CISC101 - Prof. McLeod 30 5

6 Other Things in Java Programs Comments Variable names Literal values Punctuation like: ;., ( ) { } [ ] Operators like: + - / % > < == =! && We will also see lots of other object names along with their members attributes or methods. Expressions A line of code in java often contains expressions. They are combinations of any or all of: Variables Literal Values Operators Method Invocations A line of code in java is terminated by a ; Spring 2006 CISC101 - Prof. McLeod 31 Spring 2006 CISC101 - Prof. McLeod 32 Variables Java is a declarative language. This means that you have to declare a variable before you can use it. What is a variable anyways? A name for a piece of memory used to store something. The something can be a primitive type value or a pointer to an object (a memory reference). (Don t worry about pointers, yet!!) Spring 2006 CISC101 - Prof. McLeod 33 Variables, Cont. To create a variable, you must state what type it is going to be. For example, to create a variable called anum of type int, you would use the following line of code: int anum; You could assign a value to anum using something like: anum = 200; Spring 2006 CISC101 - Prof. McLeod 34 What is a literal value? We just saw one: 200 Back to Expressions Expressions Now, let s consider each of these elements again, in more detail: variables, literal values, operators. What is an operator? We just saw one of those too: = Other operators, for example, are: + - / * And, what is an expression? We just saw one of those too!: anum = 200; Spring 2006 CISC101 - Prof. McLeod 35 Spring 2006 CISC101 - Prof. McLeod 36 6

7 Java Primitive Types Primitive Types - Cont. Primitive Type variables are those that are not Objects in Java. Primitive Type Variables fall into the categories of integer types, real types, characters and booleans. Integer byte short Real float double Character char Boolean boolean int long Spring 2006 CISC101 - Prof. McLeod 37 Spring 2006 CISC101 - Prof. McLeod 38 An Integer Primitive Type Variable Declare using the int keyword. From to , inclusive (4 bytes). (A byte is 8 bits, where a bit is either 1 or 0.) For example: More Integer Primitive Types Other primitive types: byte, short and long: For byte, from -128 to 127, inclusive (1 byte). For short, from to 32767, inclusive (2 bytes). (For int, from to , inclusive (4 bytes). ) For long, from to , inclusive (8 bytes). int anum; Spring 2006 CISC101 - Prof. McLeod 39 Spring 2006 CISC101 - Prof. McLeod 40 Aside - Storage of Integers Computers like to store numbers in binary - a memory location is either on or off. An un-signed 8 digit binary number can range from to is 0 in base is 1x x x x2 7 = 255, base 10. Storage of Integers - Cont. So, how can a negative binary number be stored? Use the two s complement system of storage. Make the most significant bit a negative number: So, the lowest signed binary 8 digit number is now: , which is -1x2 7, or -128 base 10. Spring 2006 CISC101 - Prof. McLeod 41 Spring 2006 CISC101 - Prof. McLeod 42 7

8 Storage of Integers - Cont. Storage of Integers - Cont. binary base For example, the binary number is 1x x x2 4-1x2 7 = = -107 base 10 Now you can see how the primitive integer type, byte, ranges from -128 to 127. Spring 2006 CISC101 - Prof. McLeod 43 Spring 2006 CISC101 - Prof. McLeod 44 Storage of Integers - Cont. Suppose we wish to add 1 to the largest byte value: This would be equivalent to adding 1 to 127 in base 10 - the result would normally be 128. In base 2, using two s complement, the result of the addition is , which is -128 in base 10! So integer numbers wrap around, in the case of overflow - no warning is given! Storage of Integers - Cont. An int is stored in 4 bytes using two s complement. An int ranges from: to or to in base 10 Spring 2006 CISC101 - Prof. McLeod 45 Spring 2006 CISC101 - Prof. McLeod 46 A Double Primitive Type Variable Declare using the double keyword. For double, (8 bytes) roughly ±4.9 x to ±1.7 x to 15 significant digits. For example: The Other Real Primitive Type Also have float: For float, (4 bytes) roughly ±1.4 x to ±3.4 x to 7 significant digits. For double, (8 bytes) roughly ±4.9 x to ±1.7 x to 15 significant digits. double aval; Spring 2006 CISC101 - Prof. McLeod 47 Spring 2006 CISC101 - Prof. McLeod 48 8

9 Integer Literals A literal integer value is assumed to be of type int. If you want the literal to be a long, then you must add the letter L to the end of the literal value. Double Literals Java assumes a literal number like 2.5 or 3.45e-7 is a double literal. If you want a literal to be recognized as a float type, then you must add the letter F to the end of the number. Spring 2006 CISC101 - Prof. McLeod 49 Spring 2006 CISC101 - Prof. McLeod 50 char Primitive Type Declared as: char achar; Char literals look like: a B 1 (a space) char Primitive Type - Cont. A char primitive type can also refer to a Unicode character. For example: char achar = \u03c0 ; Where 03C0 is the hexadecimal (base 16) value for the Unicode character: π Since two bytes are used to designate the character value, it is possible to refer to 2 16 = 65,536 different characters. Spring 2006 CISC101 - Prof. McLeod 51 Spring 2006 CISC101 - Prof. McLeod 52 Aside - Unicode Characters The ASCII code system only goes to 255 since it only uses one byte. At the moment, just over 49,000 of the Unicode positions are in use. See A Boolean Primitive Type Variable Declare using the boolean keyword. Either true or false For example: boolean aflag; boolean literals are: true, false Spring 2006 CISC101 - Prof. McLeod 53 Spring 2006 CISC101 - Prof. McLeod 54 9

10 Aside - String s String s are not primitive data types, but are Objects. We will discuss the difference later A String can be declared in the same way as a primitive type using the keyword: String. For example: String response; Variable Declaration To declare a variable, use the Java keyword appropriate for the type of variable you are declaring followed by a variable name you have created, followed by a semicolon. Examples: int anum; double totalvolume; String userprompt; Spring 2006 CISC101 - Prof. McLeod 55 Spring 2006 CISC101 - Prof. McLeod 56 Legal Variable Names Legal Variable Names - Cont. Java names may contain any number of letters, numbers and underscore ( _ ) characters, but they must begin with a letter. Standard Java Naming Convention: Names beginning with lowercase letters are variables or methods. Names beginning with uppercase letters are class names. Successive words within a name are capitalized. Names in all capital letters are constants. (We ll get to constants shortly). Legal names: mydata x1 AnotherName TWO_PI Illegal names: _toupper 1Day Variable or method names Class names Constant Spring 2006 CISC101 - Prof. McLeod 57 Spring 2006 CISC101 - Prof. McLeod 58 int s, for example: Literal Values double numbers, for example: E E45 boolean, for example: true String literals: Hello! spaces Variable Declaration - Cont. int and double variables initially are given a value of zero unless they are initialized to a value. Java may prevent you from using variables that are not initialized. So, it is often necessary to initialize your variables before use, for example: int numdaysinyear = 365; double avgnumdaysinyear = ; String greetingline = Hello there! ; Spring 2006 CISC101 - Prof. McLeod 59 Spring 2006 CISC101 - Prof. McLeod 60 10

11 Variable Declaration - Cont. All these statements could be carried out in two lines, for example: int numdaysinweek = 7; Is the same as: int numdaysinweek; numdaysinweek = 7; Constants The Java keyword, final can be used to make sure a variable value is no longer variable. It becomes a constant, because Java will not allow your program to change its value once it has been declared: final int NUM_DAYS_IN_YEAR = 365; final double MM_PER_INCH = 25.4; Spring 2006 CISC101 - Prof. McLeod 61 Spring 2006 CISC101 - Prof. McLeod 62 Arithmetic Operators The standard arithmetic operators in Java are: Addition (+) Subtraction (-) Multiplication (*) Division (/) Modulo (or remainder ) (%) All of these operations apply to all numeric data types. All require values on both sides of the operator. Aside - Strings and the + Operator Not only can + operate on numeric values, but it can also handle String s on either or both sides. If one side is not a String, it will be changed to one, and then it will be concatenated to the String on the other side: 4 + you evaluates to 4you apples + oranges + 99 evaluates to applesoranges little piggies evaluates to 10little piggies Spring 2006 CISC101 - Prof. McLeod 63 Spring 2006 CISC101 - Prof. McLeod 64 Logical Operators Return either true or false. All these require values on both sides of the operator. ==!= > < >= <= && logical And logical Or equals to not equals to greater than less than greater than or equal to less than or equal to Spring 2006 CISC101 - Prof. McLeod 65 Logical Operators - Cont. Truth tables for the And and Or operators: boolean result = testa && testb; && testa testb true false testa true true false testb true false false false false true true true false true false boolean result = testa testb; Spring 2006 CISC101 - Prof. McLeod 66 11

12 = set equal to Assignment Operator This is all we need to be able to build Java expressions. There are other assignment operators (+=, -=, *=, /=), but we ll look at these later. We will also consider unary operators later too. Expressions Expressions are combinations of variables, literal values, and operators. For example: int anum = * 7; // anum is 25 int anum = (4 + 3) * 7; // anum is 49 (4 > 7) (10 > -1) // yields true (5.5 >= 5.0) && (4.0!= 1.0)// yields true double circ = 3.14 * 2.0 * r; ( // precedes a comment in Java) Spring 2006 CISC101 - Prof. McLeod 67 Spring 2006 CISC101 - Prof. McLeod 68 Precedence Rules Operator precedence rules determine which operations take place in what order: First *, /, % Then +, - Then <, >, <=, >= Then ==,!= Then &&, Last = Use ( ) to control order of operations, as the expression inside ( ) will be evaluated before stuff outside of ( ). Spring 2006 CISC101 - Prof. McLeod 69 12

Fall 2017 CISC124 9/16/2017

Fall 2017 CISC124 9/16/2017 CISC124 Labs start this week in JEFF 155: Meet your TA. Check out the course web site, if you have not already done so. Watch lecture videos if you need to review anything we have already done. Problems

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

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

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

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

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

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

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

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

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

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

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

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

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos. Lecture 2: Variables and Operators AITI Nigeria Summer 2012 University of Lagos. Agenda Variables Types Naming Assignment Data Types Type casting Operators Declaring Variables in Java type name; Variables

More information

COMP 202 Java in one week

COMP 202 Java in one week COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Datatypes, Variables, and Operations

Datatypes, Variables, and Operations Datatypes, Variables, and Operations 1 Primitive Type Classification 2 Numerical Data Types Name Range Storage Size byte 2 7 to 2 7 1 (-128 to 127) 8-bit signed short 2 15 to 2 15 1 (-32768 to 32767) 16-bit

More information

CompSci 125 Lecture 02

CompSci 125 Lecture 02 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!

More information

Accelerating Information Technology Innovation

Accelerating Information Technology Innovation Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 02 Variables and Operators Agenda Variables Types Naming Assignment Data Types Type casting Operators

More information

An overview of Java, Data types and variables

An overview of Java, Data types and variables An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public

More information

Getting started with Java

Getting started with Java Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS PAUL L. BAILEY Abstract. This documents amalgamates various descriptions found on the internet, mostly from Oracle or Wikipedia. Very little of this

More information

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

Building Java Programs. Introduction to Programming and Simple Java Programs

Building Java Programs. Introduction to Programming and Simple Java Programs Building Java Programs Introduction to Programming and Simple Java Programs 1 A simple Java program public class Hello { public static void main(string[] args) { System.out.println("Hello, world!"); code

More information

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

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

Java Programming. Atul Prakash

Java Programming. Atul Prakash Java Programming Atul Prakash Java Language Fundamentals The language syntax is similar to C/ C++ If you know C/C++, you will have no trouble understanding Java s syntax If you don't, it will be easier

More information

Software and Programming 1

Software and Programming 1 Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 17 January 2019 SP1-Lab1-2018-19.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon

More information

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

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs Welcome to CSE 142! Zorah Fung University of Washington, Spring 2015 Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs reading: 1.1-1.3 1 What is computer science? computers?

More information

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M. Java Language Essentials Java is Case Sensitive All Keywords are lower case White space characters are ignored Spaces, tabs, new lines Java statements must end with a semicolon ; Compound statements use

More information

Chapter 2. Elementary Programming

Chapter 2. Elementary Programming Chapter 2 Elementary Programming 1 Objectives To write Java programs to perform simple calculations To obtain input from the console using the Scanner class To use identifiers to name variables, constants,

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ OBJECT-ORIENTED PROGRAMMING IN JAVA 2 Programming

More information

Mr. Monroe s Guide to Mastering Java Syntax

Mr. Monroe s Guide to Mastering Java Syntax Mr. Monroe s Guide to Mastering Java Syntax Getting Started with Java 1. Download and install the official JDK (Java Development Kit). 2. Download an IDE (Integrated Development Environment), like BlueJ.

More information

Introduction Basic elements of Java

Introduction Basic elements of Java Software and Programming I Introduction Basic elements of Java Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Module Information Time: Thursdays in the Spring term Lectures: MAL B04: 2

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

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

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail. OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

3. Java - Language Constructs I

3. Java - Language Constructs I Names and Identifiers A program (that is, a class) needs a name public class SudokuSolver {... 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations,

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

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

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS Java language Part 1. Java fundamentals Yevhen Berkunskyi, NUoS eugeny.berkunsky@gmail.com http://www.berkut.mk.ua What Java is? Programming language Platform: Hardware Software OS: Windows, Linux, Solaris,

More information

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

Objectives. Problem Solving. Introduction. An overview of object-oriented concepts. Programming and programming languages An introduction to Java Introduction Objectives An overview of object-oriented concepts. Programming and programming languages An introduction to Java 1-2 Problem Solving The purpose of writing a program is to solve a problem

More information

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1

cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 topics: introduction to java, part 1 topics: introduction to java, part 1 cis20.1 design and implementation of software applications I fall 2007 lecture # I.2 cis20.1-fall2007-sklar-leci.2 1 Java. Java is an object-oriented language: it is

More information

The Java Language The Java Language Reference (2 nd ed.) is the defining document for the Java language. Most beginning programming students expect

The Java Language The Java Language Reference (2 nd ed.) is the defining document for the Java language. Most beginning programming students expect The Java Language The Java Language Reference (2 nd ed.) is the defining document for the Java language. Most beginning programming students expect such a document to be totally beyond them. That expectation

More information

Software Practice 1 Basic Grammar

Software Practice 1 Basic Grammar Software Practice 1 Basic Grammar Basic Syntax Data Type Loop Control Making Decision Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee (43) 1 2 Java Program //package details

More information

Language Fundamentals Summary

Language Fundamentals Summary Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Advanced Computer Programming

Advanced Computer Programming Programming in the Small I: Names and Things (Part II) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University

More information

2 rd class Department of Programming. OOP with Java Programming

2 rd class Department of Programming. OOP with Java Programming 1. Structured Programming and Object-Oriented Programming During the 1970s and into the 80s, the primary software engineering methodology was structured programming. The structured programming approach

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net COURSE ORGANIZATION 2 Course Elements Lectures: 10 lectures Find schedule and class rooms in online

More information

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

More information

13 th Windsor Regional Secondary School Computer Programming Competition

13 th Windsor Regional Secondary School Computer Programming Competition SCHOOL OF COMPUTER SCIENCE 13 th Windsor Regional Secondary School Computer Programming Competition Hosted by The School of Computer Science, University of Windsor WORKSHOP I [ Overview of the Java/Eclipse

More information

COMP 110 Introduction to Programming. What did we discuss?

COMP 110 Introduction to Programming. What did we discuss? COMP 110 Introduction to Programming Fall 2015 Time: TR 9:30 10:45 Room: AR 121 (Hanes Art Center) Jay Aikat FB 314, aikat@cs.unc.edu Previous Class What did we discuss? COMP 110 Fall 2015 2 1 Today Announcements

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information

Getting started with Java

Getting started with Java Getting started with Java by Vlad Costel Ungureanu for Learn Stuff Programming Languages A programming language is a formal constructed language designed to communicate instructions to a machine, particularly

More information

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

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG 1 Notice Reading Assignment Chapter 1: Introduction to Java Programming Homework 1 It is due this coming Sunday

More information

Procedures, Parameters, Values and Variables. Steven R. Bagley

Procedures, Parameters, Values and Variables. Steven R. Bagley Procedures, Parameters, Values and Variables Steven R. Bagley Recap A Program is a sequence of statements (instructions) Statements executed one-by-one in order Unless it is changed by the programmer e.g.

More information

The C++ Language. Arizona State University 1

The C++ Language. Arizona State University 1 The C++ Language CSE100 Principles of Programming with C++ (based off Chapter 2 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Software and Programming 1

Software and Programming 1 Software and Programming 1 Lab 1: Introduction, HelloWorld Program and use of the Debugger 11 January 2018 SP1-Lab1-2017-18.pptx Tobi Brodie (tobi@dcs.bbk.ac.uk) 1 Module Information Lectures: Afternoon

More information

PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write

More information

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

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018 Welcome to CSE 142! Whitaker Brand University of Washington, Winter 2018 1 What is computer science? computers? science? programming? late lonely nights in front of the computer? ALGORITHMIC THINKING al

More information

SFU CMPT 379 Compilers Spring 2018 Milestone 1. Milestone due Friday, January 26, by 11:59 pm.

SFU CMPT 379 Compilers Spring 2018 Milestone 1. Milestone due Friday, January 26, by 11:59 pm. SFU CMPT 379 Compilers Spring 2018 Milestone 1 Milestone due Friday, January 26, by 11:59 pm. For this assignment, you are to convert a compiler I have provided into a compiler that works for an expanded

More information

Course Outline. Introduction to java

Course Outline. Introduction to java Course Outline 1. Introduction to OO programming 2. Language Basics Syntax and Semantics 3. Algorithms, stepwise refinements. 4. Quiz/Assignment ( 5. Repetitions (for loops) 6. Writing simple classes 7.

More information

Week 6: Review. Java is Case Sensitive

Week 6: Review. Java is Case Sensitive Week 6: Review Java Language Elements: special characters, reserved keywords, variables, operators & expressions, syntax, objects, scoping, Robot world 7 will be used on the midterm. Java is Case Sensitive

More information

A Fast Review of C Essentials Part I

A Fast Review of C Essentials Part I A Fast Review of C Essentials Part I Structural Programming by Z. Cihan TAYSI Outline Program development C Essentials Functions Variables & constants Names Formatting Comments Preprocessor Data types

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

More information

BASIC ELEMENTS OF A COMPUTER PROGRAM

BASIC ELEMENTS OF A COMPUTER PROGRAM BASIC ELEMENTS OF A COMPUTER PROGRAM CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING LOGO Contents 1 Identifier 2 3 Rules for naming and declaring data variables Basic data types 4 Arithmetic operators

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 3 - Constants, Variables, Data Types, And Operations Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad Outline C Program Data types Variables

More information

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2 CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,

More information

JAVA Programming Fundamentals

JAVA Programming Fundamentals Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

More information

Programming. Syntax and Semantics

Programming. Syntax and Semantics Programming For the next ten weeks you will learn basic programming principles There is much more to programming than knowing a programming language When programming you need to use a tool, in this case

More information

The MaSH Programming Language At the Statements Level

The MaSH Programming Language At the Statements Level The MaSH Programming Language At the Statements Level Andrew Rock School of Information and Communication Technology Griffith University Nathan, Queensland, 4111, Australia a.rock@griffith.edu.au June

More information

Introduction to. Android Saturday. Yanqiao ZHU Google Camp School of Software Engineering, Tongji University. In courtesy of The Java Tutorials

Introduction to. Android Saturday. Yanqiao ZHU Google Camp School of Software Engineering, Tongji University. In courtesy of The Java Tutorials Introduction to Android Saturday Yanqiao ZHU Google Camp School of Software Engineering, Tongji University In courtesy of The Java Tutorials Getting Started Introduction to Java The Java Programming Language

More information

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

Object-Oriented Programming

Object-Oriented Programming Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,

More information

Basic Operations jgrasp debugger Writing Programs & Checkstyle

Basic Operations jgrasp debugger Writing Programs & Checkstyle Basic Operations jgrasp debugger Writing Programs & Checkstyle Suppose you wanted to write a computer game to play "Rock, Paper, Scissors". How many combinations are there? Is there a tricky way to represent

More information

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to

More information

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

For the course, we will be using JCreator as the IDE (Integrated Development Environment). For the course, we will be using JCreator as the IDE (Integrated Development Environment). We strongly advise that you install these to your own computers. If you do not have your own computer, the computer

More information

Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I. Lecture#12 Spring 2015 Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your

More information

Lecture Set 2: Starting Java

Lecture Set 2: Starting Java Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables 0 This Course: Intro to Procedural

More information

Index COPYRIGHTED MATERIAL

Index COPYRIGHTED MATERIAL Index COPYRIGHTED MATERIAL Note to the Reader: Throughout this index boldfaced page numbers indicate primary discussions of a topic. Italicized page numbers indicate illustrations. A abstract classes

More information

CSCI 2101 Java Style Guide

CSCI 2101 Java Style Guide CSCI 2101 Java Style Guide Fall 2017 This document describes the required style guidelines for writing Java code in CSCI 2101. Guidelines are provided for four areas of style: identifiers, indentation,

More information

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

COSC 123 Computer Creativity. Introduction to Java. Dr. Ramon Lawrence University of British Columbia Okanagan COSC 123 Computer Creativity Introduction to Java Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Key Points 1) Introduce Java, a general-purpose programming language,

More information

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab. University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Second week Variables Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable.

More information

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

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java

More information

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements Review: Exam 1 9/20/06 CS150 Introduction to Computer Science 1 1 Your First C++ Program 1 //*********************************************************** 2 // File name: hello.cpp 3 // Author: Shereen Khoja

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

More information

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide Module 3 Identifiers, Keywords, and Types Objectives Upon completion of this module, you should be able to: Use comments in a source program Distinguish between valid and invalid identifiers Recognize

More information

Data types Expressions Variables Assignment. COMP1400 Week 2

Data types Expressions Variables Assignment. COMP1400 Week 2 Data types Expressions Variables Assignment COMP1400 Week 2 Data types Data come in different types. The type of a piece of data describes: What the data means. What we can do with it. Primitive types

More information

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

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University Lecture 2 COMP1406/1006 (the Java course) Fall 2013 M. Jason Hinek Carleton University today s agenda a quick look back (last Thursday) assignment 0 is posted and is due this Friday at 2pm Java compiling

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

More information

ECE 122 Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Introduction to Programming for ECE Lecture 1 Course Overview Welcome! What is this class about? Java programming somewhat software somewhat Solving engineering

More information

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

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

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 05 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions / Comments? recap and some more details about variables, and if / else statements do lab work

More information

4 Programming Fundamentals. Introduction to Programming 1 1

4 Programming Fundamentals. Introduction to Programming 1 1 4 Programming Fundamentals Introduction to Programming 1 1 Objectives At the end of the lesson, the student should be able to: Identify the basic parts of a Java program Differentiate among Java literals,

More information

JAVA Ch. 4. Variables and Constants Lawrenceville Press

JAVA Ch. 4. Variables and Constants Lawrenceville Press JAVA Ch. 4 Variables and Constants Slide 1 Slide 2 Warm up/introduction int A = 13; int B = 23; int C; C = A+B; System.out.print( The answer is +C); Slide 3 Declaring and using variables Slide 4 Declaring

More information

COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP Primitive and Class Types. Yi Hong May 14, 2015 COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

More information

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above

P.G.TRB - COMPUTER SCIENCE. c) data processing language d) none of the above P.G.TRB - COMPUTER SCIENCE Total Marks : 50 Time : 30 Minutes 1. C was primarily developed as a a)systems programming language b) general purpose language c) data processing language d) none of the above

More information

Fall 2017 CISC/CMPE320 9/27/2017

Fall 2017 CISC/CMPE320 9/27/2017 Notices: CISC/CMPE320 Today File I/O Text, Random and Binary. Assignment 1 due next Friday at 7pm. The rest of the assignments will also be moved ahead a week. Teamwork: Let me know who the team leader

More information

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

1 Introduction Java, the beginning Java Virtual Machine A First Program BlueJ Raspberry Pi... Contents 1 Introduction 3 1.1 Java, the beginning.......................... 3 1.2 Java Virtual Machine........................ 4 1.3 A First Program........................... 4 1.4 BlueJ.................................

More information