CT 229 Fundamentals of Java Syntax

Size: px
Start display at page:

Download "CT 229 Fundamentals of Java Syntax"

Transcription

1 CT 229 Fundamentals of Java Syntax 19/09/2006 CT229

2 New Lab Assignment Monday 18 th Sept -> New Lab Assignment on CT 229 Website Two Weeks for Completion Due Date is Oct 1 st Assignment Submission is There is a link to the submission page from the main course 19/09/2006 CT229 1

3 Assignment Upload 19/09/2006 CT229 2

4 Assignments Submission Submit one file at a time You can only submit.java files Assignment Marking There will be four sections to assignment 20% for successful completion of each section No marks will be awarded unless section is running correctly 20% goes for correct programming style (naming conventions, commenting, formatting etc) Always keep a copy of your completed assignment Original Work Only!!! 19/09/2006 CT229 3

5 Java Style Guide Adhering to a programming style guide results in writing correct, high quality, maintainable and easily readable java code. The Java Programming Style guide can be divided into: Naming Conventions Commenting Formatting 19/09/2006 CT229 4

6 Naming Conventions Variable Names Variable should have mixed-case letters, beginning with lower-case use accountbalance instead of AccountBalance or accountbalance Avoid using abbreviations (accbal) or very long names Use a name that describes the function of the variable Constant Names Use all upper case letters, separating words with underscore INTEREST_RATE instead of interestrate Avoid the use of magic number, that is actual numbers that appear in the code without any explanation interestdue = 2000*10 interestdue = accountbalance * INTEREST_RATE 19/09/2006 CT229 5

7 Naming Conventions Methods As with variables use mixed-case letters for naming methods Method name should indicate its purpose Generally methods that return a the value of a variable have a prefix get (Example: getaccountbalance) While methods that set a variable value have a prefix set (Example: setaccountbalance) Parameter Names Follow same naming convention as used with variables 19/09/2006 CT229 6

8 Commenting Comments should be used to improve the readability of the program Two Types of Comments: Header Comment Single-line Comments 19/09/2006 CT229 7

9 Header Comment A header comment appears at the beginning of a.java file. Informs the reader of the function of the program Identifies the original author Example /* Simple Java program that prints a Hello message */ /* John Doe, Student Number: */ NOTE!! For each assignment ensure that your name and student number is written in the header comments 19/09/2006 CT229 8

10 Single Line Comment Normally provides an overview of a line or a number of lines. Begin with // or nested between /* */ Do not insert useless comments Example // Get hourly pay rate in string form: convert to double ratestr = JOptionPane.showInputDialog("Enter Hourly Rate:"); rate = Double.parseDouble(rateStr); 19/09/2006 CT229 9

11 Formatting Formatting relates to the appearance of your code Code should be tidy and easy to read Two important types of formatting generally applied Indentation Space 19/09/2006 CT229 10

12 Indentation Use of indentation makes code easier to read Simple Rules for indentation After each { move the subsequent code in by three spaces Open and close parentheses { } should be inline with each other Example /* Simple Java program that prints a Hello message */ /* Ted Scully, Sept 2006 */ public class Hello { public static void main(string[] args) { System.out.println("Hello World!"); } } 19/09/2006 CT229 11

13 Space Use of white space improves the readability of programs 19/09/2006 CT229 12

14 Second Java Program Program to Calculate Employee s Total Week s Wages: 1.Look up the employee s pay rate (rate) 2.Determine the number of hours worked (hrs) in week 3.If no. of hours worked < or = 40 then regular wages (wage) = hrs*rate and overtime pay (over) = 0 4.If hrs > 40 then wage = 40*Rate and overtime pay (over) = hrs - 40) * (1.5 * rate) 5.Total Wages (total) = wage + over 19/09/2006 CT229 13

15 Wages.java /* Basic Java Program that asks the user for the hourly payrate and the number * of hours worked. It then calculates the total wage earned for the user */ /* Ted Scully, Sept 2006 */ import javax.swing.joptionpane; // Dialog box methods public class Wages { public static void main(string[] args) { double rate, hrs, over, wage, total; String ratestr, hoursstr; REMEMBER: For Assignments include name and student number // Get hourly pay rate in string form: convert to double ratestr = JOptionPane.showInputDialog("Enter Hourly Rate:"); rate = Double.parseDouble(rateStr); // Get hourly pay rate in string form: convert to double hoursstr = JOptionPane.showInputDialog("Enter Hours Worked:"); hrs = Double.parseDouble(hoursStr); 19/09/2006 CT229 14

16 Wages.java if (hrs <= 40) { wage = rate * hrs; over = 0; } else { wage = rate * 40; over = (hrs - 40) * 1.5 * rate; } total = wage + over; // Display total wage earned JOptionPane.showMessageDialog(null, "Total weekly wages are " + total); } } // Terminate program System.exit(0); 19/09/2006 CT229 15

17 Main Features import javax.swing.joptionpane; Loads classes from Java API that program will use javax.swing is a graphical user interface package JOptionPane is a class in package for displaying msg boxes double rate, hrs, over, wage, total; String ratestr, hoursstr; Declares existence of four variables that can hold numerical data ( double-precision floating-point ), and two variables that can hold string (i.e. text) data ratestr = JOptionPane.showInputDialog("Enter Hourly Rate:"); Invokes a method called showinputdialog, which is part of the JOptionPane class (defined javax.swing package) Displays input box with text Enter Hourly Rate ratestr is set to whatever text the user types in 19/09/2006 CT229 16

18 Main Features rate = Double.parseDouble(rateStr); parsedouble is a method in Double class, that converts text ( 123 ) to a double number (123.0) Double is a class defined in the Java language package (java.lang); imported automatically if (hrs <= 40) Code to make a decision: which lines will be executed next depends on the data in the variable called hrs Exactly like C total = wage + over; Sets total equal to the sum of wage and over This line is after the if-block; it is executed after whichever of the previous blocks of code is executed 19/09/2006 CT229 17

19 Main Features JOptionPane.showMessageDialog (null, "Total weekly wages are " + total); Method that displays a message box Two arguments: 1: usually null 2: the text to display The + joins text; automatically converts numbers to text command (statement) can be split over more than one line The ; indicates the end of a statement System.exit(0); Method of the System class: terminates the program Required for graphical programs Like Double, System is part of java.lang package, which is imported automatically at the start of the program 19/09/2006 CT229 18

20 Comparing C and Java Syntax Java copies basics of C syntax Expressions end in ; Almost all operators the same (Java has a few extra) Basic data types similar but not identical Same comment forms, but Java also has Javadoc comments Same decision and loop syntax, similar use of { } Java method parameters, structure and return values similar to C functions (some differences) 19/09/2006 CT229 19

21 Comparing C and Java Syntax Java is Object-Oriented C has nothing like Java classes (but C++ has) Basic structure of programs different main method has different syntax Class name must be the same as the.java file name Classes and methods in Java standard API completely different from C Standard Library functions Java has automatic garbage collection: no malloc(), no free(), no pointers! 19/09/2006 CT229 20

22 Primitive Data Types All variables must be declared with a name and a data type before they can be used May declare multiple variables of same type: int a, b, c, d; Can have declarations in middle of executable code Primitive Data Types: Primitive Data Types are similar to variables in C. However, they are defined more precisely in the interests of portability. int integer (whole number, pos or neg; 32 bits) long integer (can hold larger value than int; 64 bits) short integer (can hold 16-bit integers) byte integer (can hold 8-bit integers) float real number (with decimal point; 32 bits) double real number (larger precision/size; 64 bits) char holds a single character (Unicode, 16 bits) boolean can be either true or false 19/09/2006 CT229 21

23 Primitive Data Types Unlike C, primitive data types all have fixed storage size Example boolean result = true; char capitalc = 'C'; byte b = 100; short s = 10000; int i = ; 19/09/2006 CT229 22

24 String Data Type String Class defined in java.lang (imported automatically) Stores text (multiple characters) Example public class Main { public static void main(string[] args) { String firstname = John "; String lastname = Doe"; String fullname = firstname + lastname; System.out.print(fullName); } } 19/09/2006 CT229 23

25 Wrapping Primitive Data Types in a Class For every primitive data type, there is a type-wrapper class While primitive types have no associated methods, their associated wrapper classes do Example int number = 5; // Integer is the wrapper class for the primitive type int Integer numberwrapper = new Integer(number); double realnumber1 = number1wrapper.doublevalue(); System.out.println(realNumber1); 19/09/2006 CT229 24

26 Constants The value of a variable can be changed, but the value of a constant is fixed To create a named constant in Java you use the final type modifier A field declared final cannot be changed in the program Remember in C: #define STUDENT_NUMBER Example final int STUDENT_NUMBER = ; final String HELLO_MESSAGE = "Welcome to the Class CT229"; System.out.println(STUDENT_NUMBER); System.out.println(HELLO_MESSAGE); Welcome to the Class CT229 19/09/2006 CT229 25

27 Scope of Variables Class Variables: Declared as part of the class definition Have a class-wide scope (visibility, life-span) Can be accessed by member methods of class Local variables: Variables declared within a method Visible only in this method Two or more methods can use same names for local variables public class variable: Visible throughout the program Will cover public/private visibility modifiers later 19/09/2006 CT229 26

28 Scope of Variables 19/09/2006 CT229 27

29 Primitive Type Conversion Converting from one type to another is possible in a number of ways in Java. One solution is to use wrapper classes Example int number1 = 5; // Integer is the wrapper class for the primitive type int Integer number1wrapper = new Integer(number1); // Converts int number to double double realnumber1 = number1wrapper.doublevalue(); System.out.println("double value is "+realnumber1); 19/09/2006 CT229 28

30 Type Conversion NOTE! Cannot do assignments that involve potential loss of data: OK to assign int value to double variable (implicit cast) Error to assign double value to float variable Could also use casting to force conversion between numeric types Example float floatnumber; double doublenumber = 1.234; floatnumber = (float)doublenumber; 19/09/2006 CT229 29

31 Type Conversion Convert using methods of number classes Can convert a String to a primitive data type int num = Integer.parseInt(str); double rate = Double.parseDouble(rateStr); Can convert a primitive data type to a String String str = Integer.toString(num); Using this method you cannot convert directly from one primitive data type to another 19/09/2006 CT229 30

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway

CT 229. CT229 Lecture Notes. Labs. Tutorials. Lecture Notes. Programming II CT229. Objectives for CT229. IT Department NUI Galway Lecture Notes CT 229 Programming II Lecture notes, Sample Programs, Lab Assignments and Tutorials will be available for download at: http://www.nuigalway.ie/staff/ted_scully/ct229/ Lecturer: Dr Ted Scully

More information

CT 229 Arrays Continued

CT 229 Arrays Continued CT 229 Arrays Continued 20/10/2006 CT229 Lab Assignments Current lab assignment is due today: Oct 20 th Before submission make sure that the name of each.java file matches the name given in the assignment

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

CST141 Thinking in Objects Page 1

CST141 Thinking in Objects Page 1 CST141 Thinking in Objects Page 1 1 2 3 4 5 6 7 8 Object-Oriented Thinking CST141 Class Abstraction and Encapsulation Class abstraction is the separation of class implementation from class use It is not

More information

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

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

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

Chapter 2: Java Fundamentals

Chapter 2: Java Fundamentals Chapter 2: Java Fundamentals Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 2 discusses the following main topics: The Parts of a Java

More information

8/23/2014. Chapter Topics. Chapter Topics (2) Parts of a Java Program. Parts of a Java Program. Analyzing The Example. Chapter 2: Java Fundamentals

8/23/2014. Chapter Topics. Chapter Topics (2) Parts of a Java Program. Parts of a Java Program. Analyzing The Example. Chapter 2: Java Fundamentals Chapter 2: Java Fundamentals Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 2 discusses the following main topics: The Parts of a Java

More information

Chapter 02: Using Data

Chapter 02: Using Data True / False 1. A variable can hold more than one value at a time. ANSWER: False REFERENCES: 54 2. The int data type is the most commonly used integer type. ANSWER: True REFERENCES: 64 3. Multiplication,

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

Lesson 3: Accepting User Input and Using Different Methods for Output

Lesson 3: Accepting User Input and Using Different Methods for Output Lesson 3: Accepting User Input and Using Different Methods for Output Introduction So far, you have had an overview of the basics in Java. This document will discuss how to put some power in your program

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

CS11 Java. Fall Lecture 1

CS11 Java. Fall Lecture 1 CS11 Java Fall 2006-2007 Lecture 1 Welcome! 8 Lectures Slides posted on CS11 website http://www.cs.caltech.edu/courses/cs11 7-8 Lab Assignments Made available on Mondays Due one week later Monday, 12 noon

More information

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension.

12/22/11. Java How to Program, 9/e. public must be stored in a file that has the same name as the class and ends with the.java file-name extension. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Covered in this chapter Classes Objects Methods Parameters double primitive type } Create a new class (GradeBook) } Use it to create an object.

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

CT 229 Java Syntax Continued

CT 229 Java Syntax Continued CT 229 Java Syntax Continued 06/10/2006 CT229 Lab Assignments Due Date for current lab assignment : Oct 8 th Before submission make sure that the name of each.java file matches the name given in the assignment

More information

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

Lec 3. Compilers, Debugging, Hello World, and Variables Lec 3 Compilers, Debugging, Hello World, and Variables Announcements First book reading due tonight at midnight Complete 80% of all activities to get 100% HW1 due Saturday at midnight Lab hours posted

More information

CS 11 java track: lecture 1

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

More information

Handout 3 cs180 - Programming Fundamentals Fall 17 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Handout 3 cs180 - Programming Fundamentals Fall 17 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane. Handout 3 cs180 - Programming Fundamentals Fall 17 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:

More information

Course PJL. Arithmetic Operations

Course PJL. Arithmetic Operations Outline Oman College of Management and Technology Course 503200 PJL Handout 5 Arithmetic Operations CS/MIS Department 1 // Fig. 2.9: Addition.java 2 // Addition program that displays the sum of two numbers.

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

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

What methods does the String class provide for ignoring case sensitive situations?

What methods does the String class provide for ignoring case sensitive situations? Nov. 20 What methods does the String class provide for ignoring case sensitive situations? What is a local variable? What is the span of a local variable? How many operands does a conditional operator

More information

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

Java Tutorial. Saarland University. Ashkan Taslimi. Tutorial 3 September 6, 2011 Java Tutorial Ashkan Taslimi Saarland University Tutorial 3 September 6, 2011 1 Outline Tutorial 2 Review Access Level Modifiers Methods Selection Statements 2 Review Programming Style and Documentation

More information

Oct. 3 fixup - Here are notes and codes in the proper order that they should be.

Oct. 3 fixup - Here are notes and codes in the proper order that they should be. Oct. 3 fixup - Here are notes and codes in the proper order that they should be. The boolean Data Type The boolean data type allows you to create variables that may hold one of two possible values: true

More information

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

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba Laboratory Session: Exercises on classes Analogy to help you understand classes and their contents. Suppose you want to drive a car and make it go faster by pressing down

More information

Data Types Reference Types

Data Types Reference Types Data Types Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To differentiate between Java defined types and user defined

More information

Programming: Java. Chapter Objectives. Control Structures. Chapter 4: Control Structures I. Program Design Including Data Structures

Programming: Java. Chapter Objectives. Control Structures. Chapter 4: Control Structures I. Program Design Including Data Structures Chapter 4: Control Structures I Java Programming: Program Design Including Data Structures Chapter Objectives Learn about control structures Examine relational and logical operators Explore how to form

More information

More about JOptionPane Dialog Boxes

More about JOptionPane Dialog Boxes APPENDIX K More about JOptionPane Dialog Boxes In Chapter 2 you learned how to use the JOptionPane class to display message dialog boxes and input dialog boxes. This appendix provides a more detailed discussion

More information

Introduction to Java. Nihar Ranjan Roy. https://sites.google.com/site/niharranjanroy/

Introduction to Java. Nihar Ranjan Roy. https://sites.google.com/site/niharranjanroy/ Introduction to Java https://sites.google.com/site/niharranjanroy/ 1 The Java Programming Language According to sun Microsystems java is a 1. Simple 2. Object Oriented 3. Distributed 4. Multithreaded 5.

More information

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline Java Intro 3 9/7/2007 1 Java Intro 3 Outline Java API Packages Access Rules, Class Visibility Strings as Objects Wrapper classes Static Attributes & Methods Hello World details 9/7/2007 2 Class Libraries

More information

Array. Prepared By - Rifat Shahriyar

Array. Prepared By - Rifat Shahriyar Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

More information

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA

B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA B2.52-R3: INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING THROUGH JAVA NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE

More information

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.

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. Introduction to JAVA JAVA is a programming language which is used in Android App Development. It is class based and object oriented programming whose syntax is influenced by C++. The primary goals of JAVA

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

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

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

Chapter 2 ELEMENTARY PROGRAMMING

Chapter 2 ELEMENTARY PROGRAMMING Chapter 2 ELEMENTARY PROGRAMMING Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Objectives To write Java programs to perform simple

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

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

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

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

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

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

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

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

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

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

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual: Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom

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

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

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Education, Inc. All Rights Reserved. Each class you create becomes a new type that can be used to declare variables and create objects. You can declare new classes as needed;

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

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

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE

BCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER   COURSE WEBSITE COURSE WEBSITE http://www.steveguynes.com/bcis3630/bcis3630/default.html Instructor: Dr. Guynes Office: BLB 312H Phone: (940) 565-3110 Office Hours: By Email Email: steve.guynes@unt.edu TEXTBOOK: Starting

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

CS 251 Intermediate Programming Java Basics

CS 251 Intermediate Programming Java Basics CS 251 Intermediate Programming Java Basics Brooke Chenoweth University of New Mexico Spring 2018 Prerequisites These are the topics that I assume that you have already seen: Variables Boolean expressions

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

1 Shyam sir JAVA Notes

1 Shyam sir JAVA Notes 1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write

More information

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved. 1 3 Introduction to Classes and Objects 2 You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

Exercise: Inventing Language

Exercise: Inventing Language Memory Computers get their powerful flexibility from the ability to store and retrieve data Data is stored in main memory, also known as Random Access Memory (RAM) Exercise: Inventing Language Get a separate

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

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved.

Introduction to Classes and Objects Pearson Education, Inc. All rights reserved. 1 3 Introduction to Classes and Objects 2 You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

BRANCHING if-else statements

BRANCHING if-else statements BRANCHING if-else statements Conditional Statements A conditional statement lets us choose which statement t t will be executed next Therefore they are sometimes called selection statements Conditional

More information

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.

More information

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:

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

Lecture 2 Tao Wang 1

Lecture 2 Tao Wang 1 Lecture 2 Tao Wang 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common programming errors

More information

Weiss Chapter 1 terminology (parenthesized numbers are page numbers)

Weiss Chapter 1 terminology (parenthesized numbers are page numbers) Weiss Chapter 1 terminology (parenthesized numbers are page numbers) assignment operators In Java, used to alter the value of a variable. These operators include =, +=, -=, *=, and /=. (9) autoincrement

More information

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

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

More information

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators,

Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators, Java Language Basics: Introduction To Java, Basic Features, Java Virtual Machine Concepts, Primitive Data Type And Variables, Java Operators, Expressions, Statements and Arrays. Java technology is: A programming

More information

Coding Standards for Java

Coding Standards for Java Why have coding standards? Coding Standards for Java Version 1.3 It is a known fact that 80% of the lifetime cost of a piece of software goes to maintenance; therefore, it makes sense for all programs

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

The price of gold. source: nowiknow.com. moodle.yorku.ca CSE 1020

The price of gold. source: nowiknow.com. moodle.yorku.ca CSE 1020 The price of gold source: nowiknow.com The price of gold Problem Write an app that prints the price of one kilo of gold in US dollars. Static attributes public static type attributename All attributes

More information

Java Classes: Math, Integer A C S L E C T U R E 8

Java Classes: Math, Integer A C S L E C T U R E 8 Java Classes: Math, Integer A C S - 1903 L E C T U R E 8 Math class Math class is a utility class You cannot create an instance of Math All references to constants and methods will use the prefix Math.

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

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

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Introduction to Classes and Objects

Introduction to Classes and Objects 1 2 Introduction to Classes and Objects You will see something new. Two things. And I call them Thing One and Thing Two. Dr. Theodor Seuss Geisel Nothing can have value without being an object of utility.

More information

Full file at

Full file at MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) 25 % 1 is. 1) A) 2 B) 1 C) 0 D) 4 E) 3 2) Which of the following expressions will yield 0.5? (choose

More information

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

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple

More information

19. GUI Basics. Java. Fall 2009 Instructor: Dr. Masoud Yaghini

19. GUI Basics. Java. Fall 2009 Instructor: Dr. Masoud Yaghini 19. GUI Basics Java Fall 2009 Instructor: Dr. Masoud Yaghini Outline Displaying Text in a Message Dialog Box Getting Input from Input Dialogs References Displaying Text in a Message Dialog Box Displaying

More information

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

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line A SIMPLE JAVA PROGRAM Class Declaration The Main Line INDEX The Line Contains Three Keywords The Output Line COMMENTS Single Line Comment Multiline Comment Documentation Comment TYPE CASTING Implicit Type

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

Chapter 2 Primitive Data Types and Operations. Objectives

Chapter 2 Primitive Data Types and Operations. Objectives Chapter 2 Primitive Data Types and Operations Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs,

More information

Java Review. Java Program Structure // comments about the class public class MyProgram { Variables

Java Review. Java Program Structure // comments about the class public class MyProgram { Variables Java Program Structure // comments about the class public class MyProgram { Java Review class header class body Comments can be placed almost anywhere This class is written in a file named: MyProgram.java

More information

CS 1302 Chapter 9 (Review) Object & Classes

CS 1302 Chapter 9 (Review) Object & Classes CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state

More information

CHAPTER 2 Java Fundamentals

CHAPTER 2 Java Fundamentals CHAPTER 2 Java Fundamentals Copyright 2016 Pearson Education, Inc., Hoboken NJ Chapter Topics Chapter 2 discusses the following main topics: The Parts of a Java Program The print and println Methods, and

More information

Chapter 2 Primitive Data Types and Operations

Chapter 2 Primitive Data Types and Operations Chapter 2 Primitive Data Types and Operations 2.1 Introduction You will be introduced to Java primitive data types and related subjects, such as variables constants, data types, operators, and expressions.

More information

Learning objectives: Enhancing Classes. CSI1102: Introduction to Software Design. More about References. The null Reference. The this reference

Learning objectives: Enhancing Classes. CSI1102: Introduction to Software Design. More about References. The null Reference. The this reference CSI1102: Introduction to Software Design Chapter 5: Enhancing Classes Learning objectives: Enhancing Classes Understand what the following entails Different object references and aliases Passing objects

More information

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School CSE 201 JAVA PROGRAMMING I Primitive Data Type Primitive Data Type 8-bit signed Two s complement Integer -128 ~ 127 Primitive Data Type 16-bit signed Two s complement Integer -32768 ~ 32767 Primitive Data

More information

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent Programming 2 Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent information Input can receive information

More information

Programming with Java

Programming with Java Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules

More information

MODULE 02: BASIC COMPUTATION IN JAVA

MODULE 02: BASIC COMPUTATION IN JAVA MODULE 02: BASIC COMPUTATION IN JAVA Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment

More information

CSc Introduction to Computing

CSc Introduction to Computing CSc 10200 Introduction to Computing Lecture 2 Edgardo Molina Fall 2011 - City College of New York Thursday, September 1, 2011 Introduction to C++ Modular program: A program consisting of interrelated segments

More information

Date: Dr. Essam Halim

Date: Dr. Essam Halim Assignment (1) Date: 11-2-2013 Dr. Essam Halim Part 1: Chapter 2 Elementary Programming 1 Suppose a Scanner object is created as follows: Scanner input = new Scanner(System.in); What method do you use

More information

JAVA WRAPPER CLASSES

JAVA WRAPPER CLASSES JAVA WRAPPER CLASSES Description Each of Java's eight primitive data types has a class dedicated to it. These are known as wrapper classes, because they "wrap" the primitive data type into an object of

More information