Programming Fundamentals. Java Boot Camp Module 1

Size: px
Start display at page:

Download "Programming Fundamentals. Java Boot Camp Module 1"

Transcription

1 Programming Fundamentals Java Boot Camp Module 1 Copyright 2008 Orange & Bronze Software Labs

2 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, primitive data types, variable types,identifiers and operators Develop a simple valid Java program using the concepts learned in this chapter

3 Dissecting my First Java Program

4 Dissecting my First Java Program indicates the name of the class which is SampleOne In Java, all code should be placed inside a class declaration The class uses an access specifier public,, which indicates that our class in accessible to other classes from other packages (packages are a collection of classes). We will be covering packages and access specifiers later.

5 Dissecting my First Java Program The curly brace { indicates the start of a block. There should be a corresponding closing curly brace }to end the block.

6 Dissecting my First Java Program The next three lines are a Java comment.

7 Dissecting my First Java Program The main method is the starting point of a Java program. Make sure to follow the exact signature and note that it has a closing curly brace.

8 Dissecting my First Java Program The next line is another Java comment, a single- line comment.

9 Dissecting my First Java Program The command System.out.println(),, prints the text enclosed by quotation on the screen.

10 Best Practices Your Java programs should always end with the.java extension. Filenames should match the name of your public class. So for example, if the name of your public class is Hello,, you should save it in a file called Hello.java. You should write comments in your code explaining what a certain class does, or what a certain method do.

11 Java Comments Comments These are notes written to a code for documentation purposes. These notes are not part of the program and do not affect the flow of the program. 3 Types of comments in Java C++ Style Comments C Style Comments Javadoc Comments

12 Java Comments C++-Style Comments C++ Style comments start with // All the text after // is treated as a comment For example:

13 Java Comments C-Style Comments C-style comments, also called multiline comments start with a /* and end with a */. All text in between the two delimiters is treated as a comment. Unlike C++ style comments, it can span multiple lines. For example:

14 Java Comments Javadoc Comments Javadoc comments are used for generating HTML documentation for your Java programs. You can create javadoc comments by starting the line with /** and ending it with */.

15 Java Statements Statement one or more lines of code terminated by a semicolon.

16 Java Blocks Block is one or more statements bounded by opening and closing curly braces that group the statements as one unit. Block statements can be nested indefinitely. Any amount of whitespace is allowed.

17 Java Statements and Blocks Best Practice You should indent block-enclosed statements four spaces after the start of a block. For example:

18 Java Identifiers Identifiers are tokens that represent names of variables, methods, classes, and other user-defined program elements. Examples of identifiers are: Hello, main, System, out. Java identifiers are case-sensitive. This means that the identifier Hello is not the same as hello.

19 Java Identifiers Identifiers must begin with either a letter, an underscore _, or a dollar sign $. Letters may be lower or upper case. Subsequent characters may use numbers 0 to 9. Identifiers cannot use Java keywords like class, public, void,, etc. We will discuss more about Java keywords later.

20 Java Identifiers Best Practices For names of classes,, capitalize the first letter of the identifier. For example: ThisIsAnExampleOfClassName For names of methods and variables,, the identifier should start with a lower-case letter. For example: thisisanexampleofmethodname When creating multi-word identifiers, use capital letters to indicate the start of each word except the first word. For example, chararray, filenumber, ClassName.

21 Java Identifiers Best Practices For constants use all capitals and separate words with underscores. For example: EXAMPLE_OF_A_CONSTANT Avoid using underscores at the start of the identifier such as _read or _write.

22 Java Keywords Keywords are predefined identifiers reserved by Java for specific purposes. You cannot use keywords as identifiers for any user-defined elements such as variables, methods, classes, and constants. The next slide contains the list of the Java Keywords.

23 Java Keywords

24 Java Literals Literals are tokens that do not change - they are constant. The different types of literals in Java are: Integer Literals Floating-Point Literals Boolean Literals Character Literals String Literals

25 Primitive Data Types The Java programming language defines eight primitive data types. Logical boolean Textual char Numerical byte short int long (integral) double float (floating point).

26 Primitive Data Types: Logical-boolean A boolean data type represents one of two states: true and false. An example is The example declares a boolean type variable named result and assigns it a value of true.

27 Primitive Data Types: Textual-char A character data type (char( char), represents a single Unicode character. It must have its literal enclosed in single quotes( ). To represent special characters like ' (single quotes) or " (double quotes), use the escape character \.

28 Primitive Data Types: Textual-char The following literals all refer to the same character: Hexadecimal

29 Primitive Data Types: Textual-char String is not a primitive data type, but due to its very common use we will introduce String in this section. A String is a data type composed of multiple characters. As such it is not a primitive data type, it is a class. It has its literals enclosed in double quotes( ).

30 Primitive Data Types: Integral byte, short, int & long Integral data types have the following ranges:

31 Primitive Data Types: Integral byte, short, int & long Integral data types in Java can take values in three forms decimal, octal or hexadecimal. Integral types have int as default data type. You can define a long value by appending the letter l or L (upper or lowercase 'L')

32 Primitive Data Types: Floating Point float and double Floating-point data types have the following specs: type bits accuracy range represented (approximate only) float 32 6 to 7 significant digits ±1.40e-45 to ±3.40e+38 double to15 significant digits ±4.94e-324 to ±1.79e+308 Though floating-point data types can represent the exact value of some integers, as a general practice we never regard floating-point representations as exact.

33 Primitive Data Types: Floating- Point float and double Floating-point types have double as default data type. Floating-point literals/constants include either a decimal point or one of the following, E or e //(add exponential value) F or f //(float) D or d //(double) Examples:

34 Casting Among integral types, casting is implicit if from narrow to wide

35 Casting Among integral types, casting is implicit if from narrow to wide

36 Casting Casting to a narrower datatype requires an explicit cast. Initial bits will be dropped.

37 Casting Similar rules apply to floating-point primitives:

38 Casting Integral types can be implicitly cast to floating-point types.

39 Casting If a floating-point is cast to an integral, digits after the decimal-point are dropped: value of i: 4

40 Casting char can be implicitly cast to int, long or floating-point types

41 Casting booleans cannot be cast to any other data type

42 Variables A variable is an item of data used to store the state of objects. A variable has a: data type The data type determines the type of value that the variable can hold. name The variable name must follow rules for identifiers.

43 Declaring and Initializing Variables Declare a variable as follows: <data type> <name> [=initial value]; Note: Values enclosed in < > are required values, while those values in [ ] are optional.

44 Declaring and Initializing Variables: Sample Program

45 Declaring and Initializing Variables: Best Practices It always good to initialize your variables as you declare them. Use descriptive names for your variables. For example, if you want a variable that contains a student's grade, give it a name like grade or englishgrade,, and not just random letters and/or numbers like g1.

46 Declaring and Initializing Variables: Best Practice Declare one variable per line of code. For example, the variable declarations are preferred over the declaration

47 Scope of a Variable The scope determines where in the program a variable is accessible. determines the lifetime of a variable or how long the variable can exist in memory. The scope is determined by where the variable declaration is placed in the program. To simplify, think of the scope as anything between the curly braces {...}. Areas outside the curly braces are called the outer blocks,, and blocks enclosed by the curly braces are called inner blocks.

48 Scope of a Variable A variable's scope is Inside the block where it is declared, starting from the point where it is declared, and in the inner blocks.

49 Example 1 A B C D E

50 Example 1 The code we have here represents five scopes indicated by the boxes and the letters representing the scope. Given the variables i, j, k, m and n, and the five scopes A, B, C, D and E, we have the following scopes for each variable: The scope of variable i is A. The scope of variable j is B. The scope of variable k is C. The scope of variable m is D. The scope of variable n is E.

51 Example 2 A B C D E

52 Example 2 In the main method, the scopes of the variables are, ages[] scope A i in B scope B i in C scope C In the test method, the scopes of the variables are, arr[] scope D i in E scope E

53 Scope of a Variable When declaring variables, only one variable with a given identifier or name can be declared in a scope. That means that if you have the following declaration, your compiler will generate an error since you should have unique names for each variable within a single block.

54 Scope of a Variable However you can have two variables of the same name if they are not declared in the same block. For example,

55 Outputting Variable Data In order to output the value of a certain variable to console, we can use the following commands:

56 Outputting Variable Data: Sample Program The program will output the following text on screen:

57 System.out.println() vs. System.out.print() System.out.println() Appends a newline at the end of the data output System.out.print() Does not append newline at the end of the data output

58 System.out.println() vs. System.out.print() Program 1: Output: Program 2: Output:

59 Reference Variables vs. Primitive Variables Two types of variables in Java: Primitive Variables Reference Variables Primitive Variables variables with primitive data types such as int or long. stores data in the actual memory location of where the variable is

60 Reference Variables vs. Primitive Variables Reference Variable a variable that stores the address in its memory location points to another memory location where the actual data is stored. When you declare a variable of a certain class, you are actually declaring only a reference to a possible instance of that class (which might not exist yet), and are not creating the object itself.

61 Example Suppose we have two variables with data types int and String.

62 Example The picture shown below is the actual memory of your computer, wherein you have the address of the memory cells, the variable name and the data they hold.

63 Operators Different types of operators: arithmetic operators relational operators logical operators conditional operators These operators follow a precedence that tells the compiler which operation to evaluate first when multiple operators are used in one statement.

64 Arithmetic Operators

65 Arithmetic Operators: Sample Program

66 Arithmetic Operators: Sample Program

67 Arithmetic Operators: Sample Program

68 Arithmetic Operators: Sample Program Output

69 Pop Quiz What is the result of writing this code:

70 Pop Quiz What is the result of writing this code: Will not compile!

71 Arithmetic Operators byte, short and char get automatically promoted to int before any arithmetic operation.

72 Arithmetic Operators In mixed expressions, all participants get promoted to datatype of widest participant Floating point numbers are always considered wider than integrals. all promoted to float

73 Increment and Decrement Operators unary increment operator (++) unary decrement operator (--) Increment and decrement operators increase and decrease a value stored in a number variable by 1. For example, the expression, is equivalent to

74 Increment and Decrement Operators

75 Increment and Decrement Operators The increment and decrement operators can be placed before or after an operand. When used before an operand, it causes the variable to be incremented or decremented by 1, and then the new value is used in the expression in which it appears.

76 Increment and Decrement Operators When the increment and decrement operators are placed after the operand, the old value of the variable will be used in the expression where it appears.

77 Increment and Decrement Operators: Best Practice Always keep expressions containing increment and decrement operators simple and easy to understand.

78 Relational Operators Relational operators compare two values and determines the relationship between those values. The output of evaluation are the boolean values true or false.

79 Relational Operators: Sample Program

80 Relational Operators: Sample Program

81 Relational Operators: Sample Program

82 Relational Operators: Sample Program Output

83 Logical Operators Logical operators have one or two boolean operands that yield a boolean result. There are six logical operators: && (short-circuit logical AND, binary) & (logical AND, binary) (short-circuit logical OR, binary) (logical inclusive OR, binary) ^ (logical exclusive OR, binary)! (logical NOT, unary)

84 Logical Operators The basic expression for a logical operation is, x1 op x2 where, x1, x2 - can be boolean expressions, variables or constants op - is either &&, &,, or ^ operator. The truth tables that will be shown next, summarize the result of each operation for all possible combinations of x1 and x2.

85 Logical Operators: &&(logical) and &(boolean logical) AND Here is the truth table for && and &

86 Logical Operators: &&(logical) and &(boolean logical) AND The basic difference between && and & operators : && supports short-circuit evaluations (or partial evaluations), while & doesn't. Given an expression: exp1 && exp2 && will evaluate the expression exp1, and immediately return a false value is exp1 is false. If exp1 is false, the operator never evaluates exp2 because the result of the operator will be false regardless of the value of exp2. In contrast, the & operator always evaluates both exp1 and exp2 before returning an answer.

87 Logical Operators: &&(logical) and &(boolean logical) AND

88 Logical Operators: &&(logical) and &(boolean logical) AND The output of the program is Note, that the j++ on the line containing the && operator is not evaluated since the first expression (i>10( i>10) ) is already equal to false.

89 Logical Operators: (logical) and (boolean logical) inclusive OR Here is the truth table for and,

90 Logical Operators: (logical) and (boolean logical) inclusive OR The basic difference between and I operators : supports short-circuit evaluations (or partial evaluations), while doesn't. Given an expression: exp1 exp2 will evaluate the expression exp1,, and immediately return a true value is exp1 is true If exp1 is true, the operator never evaluates exp2 because the result of the operator will be true regardless of the value of exp2. In contrast, the operator always evaluates both exp1 and exp2 before returning an answer.

91 Logical Operators: (logical) and (boolean logical) inclusive OR

92 Logical Operators: (logical) and (boolean logical) inclusive OR The output of the program is, Note, that the j++ on the line containing the operator is not evaluated since the first expression (i<10( i<10) ) is already equal to true.

93 Logical Operators: ^ (boolean logical exclusive OR) Here is the truth table for ^, The result of an exclusive OR operation is TRUE, if and only if one operand is true and the other is false. Note that both operands must always be evaluated in order to evaluate the result of an exclusive OR.

94 Logical Operators: ^ (boolean logical exclusive OR)

95 Logical Operators: ^ (boolean logical exclusive OR) The output of the program is

96 Logical Operators:! (logical NOT) The logical NOT takes in one argument, wherein that argument can be an expression, variable or constant. Here is the truth table for!,

97 Logical Operators:! (logical NOT) The output of the program is

98 Logical Operators: Conditional Operator (?:) The conditional operator?: is a ternary operator. This means that it takes in three arguments that together form a conditional expression. The structure of an expression using a conditional operator is exp1?exp2:exp3 Result: exp1 - is a boolean expression whose result must either be true or false If exp1 is true, exp2 is the value returned. If it is false, then exp3 is returned.

99 Logical Operators: Conditional Operator (?:) The output of this program will be

100 Logical Operators: Conditional Operator (?:)

101 Operator Precedence

102 Operator Precedence Given a compound expression, 6%2*5+4/ we can re-write the expression and place some parentheses based on operator precedence, ((6%2)*5)+(4/2)+88-10

103 Operator Precedence: Best Practice To avoid confusion in evaluating mathematical operations, keep your expressions simple and use parentheses.

104 Summary Java Comments (C++-Style Comments, C- Style Comments, Special Javadoc Comments) Java statements, blocks, identifiers, keywords Java Literals (integer, floating point, boolean, character, String) Primitive data types( boolean, char, byte, short, int, long, float, double) Casting

105 Summary Variables (declare, initialize, output) Scope of a variable System.out.println() vs. System.out.print() Reference Variables vs. Primitive Variables Operators (Arithmetic operators, Increment and Decrement operators, Relational operators, Logical operators, Conditional Operator (?:), Operator Precedence)

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

More information

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper

More information

Moving from CS 61A Scheme to CS 61B Java

Moving from CS 61A Scheme to CS 61B Java Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you

More information

Lecture 5: Java Fundamentals III

Lecture 5: Java Fundamentals III Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved.

JavaScript: Introduction to Scripting. 2008 Pearson Education, Inc. All rights reserved. 1 6 JavaScript: Introduction to Scripting 2 Comment is free, but facts are sacred. C. P. Scott The creditor hath a better memory than the debtor. James Howell When faced with a decision, I always ask,

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java. CS 3: Computer Programming in Java Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

More information

Computer Programming I

Computer Programming I Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 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 and compile the java

More information

Introduction to Python

Introduction to Python Caltech/LEAD Summer 2012 Computer Science Lecture 2: July 10, 2012 Introduction to Python The Python shell Outline Python as a calculator Arithmetic expressions Operator precedence Variables and assignment

More information

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

More information

VB.NET Programming Fundamentals

VB.NET Programming Fundamentals Chapter 3 Objectives Programming Fundamentals In this chapter, you will: Learn about the programming language Write a module definition Use variables and data types Compute with Write decision-making statements

More information

PL / SQL Basics. Chapter 3

PL / SQL Basics. Chapter 3 PL / SQL Basics Chapter 3 PL / SQL Basics PL / SQL block Lexical units Variable declarations PL / SQL types Expressions and operators PL / SQL control structures PL / SQL style guide 2 PL / SQL Block Basic

More information

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

More information

Introduction to Java

Introduction to Java Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Java Basics: Data Types, Variables, and Loops

Java Basics: Data Types, Variables, and Loops Java Basics: Data Types, Variables, and Loops If debugging is the process of removing software bugs, then programming must be the process of putting them in. - Edsger Dijkstra Plan for the Day Variables

More information

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

J a v a Quiz (Unit 3, Test 0 Practice)

J a v a Quiz (Unit 3, Test 0 Practice) Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

AP Computer Science Java Subset

AP Computer Science Java Subset APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

More information

Java Programming Fundamentals

Java Programming Fundamentals Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few

More information

Objective-C Tutorial

Objective-C Tutorial Objective-C Tutorial OBJECTIVE-C TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Objective-c tutorial Objective-C is a general-purpose, object-oriented programming

More information

Java Crash Course Part I

Java Crash Course Part I Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe skolbe@wiwi.hu-berlin.de Overview (Short) introduction to the environment Linux

More information

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

More information

Writing Control Structures

Writing Control Structures Writing Control Structures Copyright 2006, Oracle. All rights reserved. Oracle Database 10g: PL/SQL Fundamentals 5-1 Objectives After completing this lesson, you should be able to do the following: Identify

More information

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

Lecture 1 Introduction to Java

Lecture 1 Introduction to Java Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer About The Tutorial C is a general-purpose, procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system.

More information

Chapter 3. Input and output. 3.1 The System class

Chapter 3. Input and output. 3.1 The System class Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

Conditionals (with solutions)

Conditionals (with solutions) Conditionals (with solutions) For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87;

More information

JavaScript: Control Statements I

JavaScript: Control Statements I 1 7 JavaScript: Control Statements I 7.1 Introduction 2 The techniques you will learn here are applicable to most high-level languages, including JavaScript 1 7.2 Algorithms 3 Any computable problem can

More information

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

6.087 Lecture 2 January 12, 2010

6.087 Lecture 2 January 12, 2010 6.087 Lecture 2 January 12, 2010 Review Variables and data types Operators Epilogue 1 Review: C Programming language C is a fast, small,general-purpose,platform independent programming language. C is used

More information

Chapter 3 Operators and Control Flow

Chapter 3 Operators and Control Flow Chapter 3 Operators and Control Flow I n this chapter, you will learn about operators, control flow statements, and the C# preprocessor. Operators provide syntax for performing different calculations or

More information

Introduction to Python

Introduction to Python WEEK ONE Introduction to Python Python is such a simple language to learn that we can throw away the manual and start with an example. Traditionally, the first program to write in any programming language

More information

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui

More information

Software Development (CS2500)

Software Development (CS2500) (CS2500) Lecture 15: JavaDoc and November 6, 2009 Outline Today we study: The documentation mechanism. Some important Java coding conventions. From now on you should use and make your code comply to the

More information

Iteration CHAPTER 6. Topic Summary

Iteration CHAPTER 6. Topic Summary CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many

More information

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following:

Classes and Objects in Java Constructors. In creating objects of the type Fraction, we have used statements similar to the following: In creating objects of the type, we have used statements similar to the following: f = new (); The parentheses in the expression () makes it look like a method, yet we never created such a method in our

More information

Outline Basic concepts of Python language

Outline Basic concepts of Python language Data structures: lists, tuples, sets, dictionaries Basic data types Examples: int: 12, 0, -2 float: 1.02, -2.4e2, 1.5e-3 complex: 3+4j bool: True, False string: "Test string" Conversion between types int(-2.8)

More information

Chapter 5 Names, Bindings, Type Checking, and Scopes

Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Names, Bindings, Type Checking, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Type Checking Strong Typing Scope Scope and Lifetime Referencing Environments Named

More information

Programming and Data Structures with Java and JUnit. Rick Mercer

Programming and Data Structures with Java and JUnit. Rick Mercer Programming and Data Structures with Java and JUnit Rick Mercer ii Chapter Title 1 Program Development 2 Java Fundamentals 3 Objects and JUnit 4 Methods 5 Selection (if- else) 6 Repetition (while and for

More information

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

More information

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share. LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.

More information

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

csce4313 Programming Languages Scanner (pass/fail)

csce4313 Programming Languages Scanner (pass/fail) csce4313 Programming Languages Scanner (pass/fail) John C. Lusth Revision Date: January 18, 2005 This is your first pass/fail assignment. You may develop your code using any procedural language, but you

More information

Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

More information

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6) Semantic Analysis Scoping (Readings 7.1,7.4,7.6) Static Dynamic Parameter passing methods (7.5) Building symbol tables (7.6) How to use them to find multiply-declared and undeclared variables Type checking

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

Conditional Statements. 15-110 Summer 2010 Margaret Reid-Miller

Conditional Statements. 15-110 Summer 2010 Margaret Reid-Miller Conditional Statements 15-110 Summer 2010 Margaret Reid-Miller Conditional statements Within a method, we can alter the flow of control (the order in which statements are executed) using either conditionals

More information

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I

More information

Introduction to Visual C++.NET Programming. Using.NET Environment

Introduction to Visual C++.NET Programming. Using.NET Environment ECE 114-2 Introduction to Visual C++.NET Programming Dr. Z. Aliyazicioglu Cal Poly Pomona Electrical & Computer Engineering Cal Poly Pomona Electrical & Computer Engineering 1 Using.NET Environment Start

More information

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A

Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Summit Public Schools Summit, New Jersey Grade Level / Content Area: Mathematics Length of Course: 1 Academic Year Curriculum: AP Computer Science A Developed By Brian Weinfeld Course Description: AP Computer

More information

1.00/1.001 - Session 2 Fall 2004. Basic Java Data Types, Control Structures. Java Data Types. 8 primitive or built-in data types

1.00/1.001 - Session 2 Fall 2004. Basic Java Data Types, Control Structures. Java Data Types. 8 primitive or built-in data types 1.00/1.001 - Session 2 Fall 2004 Basic Java Data Types, Control Structures Java Data Types 8 primitive or built-in data types 4 integer types (byte, short, int, long) 2 floating point types (float, double)

More information

Selection Statements

Selection Statements Chapter 5 Selection Statements 1 Statements So far, we ve used return statements and expression ess statements. e ts. Most of C s remaining statements fall into three categories: Selection statements:

More information

#820 Computer Programming 1A

#820 Computer Programming 1A Computer Programming I Levels: 10-12 Units of Credit: 1.0 CIP Code: 11.0201 Core Code: 35-02-00-00-030 Prerequisites: Secondary Math I, Keyboarding Proficiency, Computer Literacy requirement Semester 1

More information

Chapter 1 Java Program Design and Development

Chapter 1 Java Program Design and Development presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented

More information

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code 1 Introduction The purpose of this assignment is to write an interpreter for a small subset of the Lisp programming language. The interpreter should be able to perform simple arithmetic and comparisons

More information

Course Title: Software Development

Course Title: Software Development Course Title: Software Development Unit: Customer Service Content Standard(s) and Depth of 1. Analyze customer software needs and system requirements to design an information technology-based project plan.

More information

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459)

Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459) Management Information Systems 260 Web Programming Fall 2006 (CRN: 42459) Class Time: 6:00 8:05 p.m. (T,Th) Venue: WSL 5 Web Site: www.pbvusd.net/mis260 Instructor Name: Terrell Tucker Office: BDC 127

More information

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE

PROGRAMMING IN C PROGRAMMING IN C CONTENT AT A GLANCE PROGRAMMING IN C CONTENT AT A GLANCE 1 MODULE 1 Unit 1 : Basics of Programming Unit 2 : Fundamentals Unit 3 : C Operators MODULE 2 unit 1 : Input Output Statements unit 2 : Control Structures unit 3 :

More information

Introduction to Java Lecture Notes. Ryan Dougherty redoughe@asu.edu

Introduction to Java Lecture Notes. Ryan Dougherty redoughe@asu.edu 1 Introduction to Java Lecture Notes Ryan Dougherty redoughe@asu.edu Table of Contents 1 Versions....................................................................... 2 2 Introduction...................................................................

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

Chapter 5. Selection 5-1

Chapter 5. Selection 5-1 Chapter 5 Selection 5-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

1001ICT Introduction To Programming Lecture Notes

1001ICT Introduction To Programming Lecture Notes 1001ICT Introduction To Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 3 A First MaSH Program In this section we will describe a very

More information

Understanding class definitions

Understanding class definitions OFWJ_C02.QXD 2/3/06 2:28 pm Page 17 CHAPTER 2 Understanding class definitions Main concepts discussed in this chapter: fields methods (accessor, mutator) constructors assignment and conditional statement

More information

I PUC - Computer Science. Practical s Syllabus. Contents

I PUC - Computer Science. Practical s Syllabus. Contents I PUC - Computer Science Practical s Syllabus Contents Topics 1 Overview Of a Computer 1.1 Introduction 1.2 Functional Components of a computer (Working of each unit) 1.3 Evolution Of Computers 1.4 Generations

More information

Java (12 Weeks) Introduction to Java Programming Language

Java (12 Weeks) Introduction to Java Programming Language Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short

More information

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

More information

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science updated 03/08/2012 Unit 1: JKarel 8 weeks http://www.fcps.edu/is/pos/documents/hs/compsci.htm

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio

More information

Tokens and Python s Lexical Structure

Tokens and Python s Lexical Structure Chapter 2 Tokens and Python s Lexical Structure The first step towards wisdom is calling things by their right names. Chinese Proverb Chapter Objectives ˆ Learn the syntax and semantics of Python s five

More information

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C

Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in

More information

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

Java Application Developer Certificate Program Competencies

Java Application Developer Certificate Program Competencies Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle

More information

C PROGRAMMING FOR MATHEMATICAL COMPUTING

C PROGRAMMING FOR MATHEMATICAL COMPUTING UNIVERSITY OF CALICUT SCHOOL OF DISTANCE EDUCATION BSc MATHEMATICS (2011 Admission Onwards) VI Semester Elective Course C PROGRAMMING FOR MATHEMATICAL COMPUTING QUESTION BANK Multiple Choice Questions

More information

Chapter 2 Basics of Scanning and Conventional Programming in Java

Chapter 2 Basics of Scanning and Conventional Programming in Java Chapter 2 Basics of Scanning and Conventional Programming in Java In this chapter, we will introduce you to an initial set of Java features, the equivalent of which you should have seen in your CS-1 class;

More information

A list of data types appears at the bottom of this document. String datetimestamp = new java.sql.timestamp(system.currenttimemillis()).

A list of data types appears at the bottom of this document. String datetimestamp = new java.sql.timestamp(system.currenttimemillis()). Data Types Introduction A data type is category of data in computer programming. There are many types so are clustered into four broad categories (numeric, alphanumeric (characters and strings), dates,

More information

Sample CSE8A midterm Multiple Choice (circle one)

Sample CSE8A midterm Multiple Choice (circle one) Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

More information

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 7 Scanner Parser Project Wednesday, September 7 DUE: Wednesday, September 21 This

More information