The Java Language Rules And Tools 3

Size: px
Start display at page:

Download "The Java Language Rules And Tools 3"

Transcription

1 The Java Language Rules And Tools 3 Course Map This module presents the language and syntax rules of the Java programming language. You will learn more about the structure of the Java program, how to insert comments into your code, and how to use various data storage types. Introduction Computer Principles and Components Software Development Language Rules and Constructs The Java Language Rules and Tools Simple Java Programming Constructs Advanced Java Programming Constructs Objects, Arrays, and Methods Object Orientation Methods Arrays Advanced Object Orientation 3-1

2 Relevance Present the following questions to stimulate the students and get them thinking about the issues and topics presented in this module. They are not expected to know the answers to these questions. The answers to these questions should be of interest to the students and inspire them to learn the contents of this module. Discussion The following questions highlight the areas that will be covered in this module: How do you store values in your programs? What sort of values can you store? Are objects the only things you can use? 3-2 Java Programming for Non-Programmers

3 Objectives Upon completion of this module, you should be able to: Use comments to document your code Use the Java technology primitive data storage types Use primitive literal values The Java Language Rules And Tools 3-3

4 The Primary Components of a Java Program Recap As was stated in Module 2, Java programs consist of the following: Classes A class is the programming structure used to group variables and methods together. Classes are written in source-code files. The Java runtime environment uses them to build objects while the program is executing. Those objects are used at runtime to store and manipulate data. Classes are the templates used to build objects. The variables and methods in classes, model ideas or concepts within the problem. You write and use as many classes within a program as there are concepts within the problem. You try to make them represent those concepts that are relevant to your world or paradigm, such as Cat, Door, Table, and so on. The classes you write will depend on the problem you want to solve and on your world (that is, the extents within which the problem lies). 3-4 Java Programming for Non-Programmers

5 The Primary Components of a Java Program Recap Objects Objects are the entities you build when you run your programs. Use them to store and manipulate the data required to solve your problem. The data is stored in variables within the objects and is manipulated by methods. Variables You use variables to store data values inside objects. Each time you build an object you put values into the data variables to represent that individual object. The variables are called attributes or members of that object. If the class models a cat then one variable may be a text string to store the cat s name. One object built from that class may have a name value of Kevin and another object a value of Duncan, representing the different cats Kevin and Duncan respectively. Methods Methods are sequences of Java technology statements ( Java statements ) that perform a discrete task on (or service of) the class. Withdrawing money from an Account object, for example, could be a method. The Java Language Rules And Tools 3-5

6 Programming Rules And Tools Before you can learn much more of the actual structure of the Java programming language, or of the art of programming, there are certain rules and tools you must understand. These are listed here and will be explained in more detail throughout the rest of this module. The Java programming language is case sensitive. supports comments for documenting your programs. is a free-format language, so you can lay out the code within your program file any way that is appropriate or logical. allows you to give various elements of your code names (also known as identifiers ) so you can refer to them appropriately and logically. 3-6 Java Programming for Non-Programmers

7 Programming Rules And Tools has certain words (called keywords or reserved words ) that have meaning and so cannot be used as identifiers. allows you to store values within your programs as variables (which can be changed) and constants (which cannot). has variables and constants that must be given a type, either one of a series of primitive types or a reference to an object. has data type rules governing usage and how you must enter values. has naming conventions for variables, classes, and so on, so you can recognize from the name what it represents. The Java Language Rules And Tools 3-7

8 Case Sensitivity Case sensitivity means distinguishing between the upper- and lowercase representations of each alphabetical character. Java technology source-code files ( Java source-code files ) are, like those of all languages, written using actual words and numbers. You cannot use just any words you want from the language when you program the compiler only understands a few of them (keywords) and it is your responsibility to use those few correctly. The Java programming language demands that all keywords are written entirely in lower case. For example, one of the few keywords we have seen so far is class. The compiler would not understand this if you wrote Class or CLASS or any other representation. A complete list of keywords appears in Table 3-1 on page The case sensitivity of the Java programming language also applies to identifiers. If you create a variable called cat then you cannot refer to it later as Cat. 3-8 Java Programming for Non-Programmers

9 Java Components This section covers the main components of the Java programming language ( Java components ). Comments You now know that the Java programming language understands only certain words, known as keywords. Anything else you wish to include in your source code must be marked for humans only so that the compiler will ignore it. The sorts of things we would want to insert into the files are descriptions of a concept, reasons and explanations for doing something, meta-data such as update history, and so on. This ability for the compiler to ignore certain text is achieved by delimiting those lines with certain character combinations: Single-line comments A // marker tells the compiler to ignore everything to the end of the current line. For example: // This is a single-line comment. The Java Language Rules And Tools 3-9

10 Java Components Comments (Continued) Multiple-line comments A /* character combination tells the compiler to ignore everything on all lines up to, and including, a comment termination marker ( */ ). For example: /* This comment spans across more than one line. */ 3-10 Java Programming for Non-Programmers

11 Java Components Statements, Codeblocks, and Whitespace Java programs are composed of classes, attributes and methods. Methods are a series of statements, each statement being a small, logical action taken towards the overall action of the method. In the Java programming language statements always end with a semicolon ( ; ). The extent of a code structure (a class or method, for example) is marked with braces ( { and } ). Groups of Java statements placed between such braces are called code blocks. Some of the Java programming language commands ( Java commands ) used to control the flow of a program from one statement to another can be enhanced using such code blocks. A code block is syntactically equivalent to a single statement. You can put a code block anywhere you can put a statement. Braces are needed to enclose classes and methods. The Java Language Rules And Tools 3-11

12 Java Components Statements, Codeblocks, and Whitespace (Continued) Whitespace is the term used to describe those characters included within source code that do not influence the program at all but simply enhance its appearance. Because Java is a free-format programming language you could put all the statements of a program onto a single line, or spread one statement over several. Both of these techniques make the code difficult to read and understand, and therefore to maintain. A well structured code block has its braces lined up vertically on lines of their own, and each statement within it indented by a consistent number of spaces. For example: 1 { 2 i = 6 + 9; 3 j = i - 3; 4 } 3-12 Java Programming for Non-Programmers

13 Java Components Identifiers Identifier refers to the names of variables, methods, and so on. Each class has an identifier, as do methods and variables. The following rules dictate the content and structure of identifiers: The first character of an identifier must be one of the following: An uppercase letter (A-Z) A lowercase letter (a-z) The underscore character (_) The dollar character ($) The Java Language Rules And Tools 3-13

14 Java Components Identifiers (Continued) The second and subsequent characters of an identifier must be Any character from the above list Numeric characters (0-9) It is not permitted under any circumstances to use a Java keyword or reserved word as an identifier. These are listed in Table 3-1 on page Note There are other characters that can be added to the second list above, including any accented characters from other languages. These are dictated by the Java programming language. Later in this module you will see some naming conventions that you should adhere to in order to control the look of identifiers. These conventions have been developed for and are used throughout the Java programming language itself Java Programming for Non-Programmers

15 Java Components Keywords and Reserved Words All languages have keywords, including the languages we use to communicate with each other, and in all cases there are certain words which are not allowed as names. For example, naming children The, Because, and Often would cause a great deal of confusion, not just for the children but also for the people they met throughout their lives. Keywords make sense to the compiler when they are used in the correct order (called the syntax of the language) and cause confusion when used incorrectly. The fact that computer languages have a much smaller set of keywords than natural languages makes them less flexible and the parsers in compilers therefore enforce the rules much more strictly than people do. The Java Language Rules And Tools 3-15

16 Java Components Keywords and Reserved Words (Continued) Natural languages also have reserved words. These are terms which are not truly part of the language but do get used in some places and cannot be used for names. In our language we refer to them as slang. There are some surprising members in this group, common words that we use without thinking. Hello, for example, is a word that was invented just a few years after the telephone it was deemed important to have a neutral word that could act as a greeting before you actually knew to whom you were talking. It is officially slang, but is also a good example of how these words can make their way into the accepted part of the language. Table 3-1 contains all the Java programming language keywords ( Java keywords ) and reserved words. While only a few of these will be described during this course, they must not be used as identifiers for classes, methods, variables, and so on. Table 3-1 Java Keywords and Reserved Words abstract default goto null synchronized boolean do if package this break double implements private throw byte else import protected throws case extends instanceof public transient catch false int return true char final interface short try class finally long static void const float native super volatile continue for new switch while 3-16 Java Programming for Non-Programmers

17 Java Components Variables and Constants The CPU and associated support chips are considered the workforce of the computer. These chips have a series of storage places (called registers ) in which they can store and manipulate the values that make up the program. There are not many of these registers in any computer, certainly not enough to provide one for each piece of information you will ever need. You therefore need to be able to store your values somewhere else and retrieve them as quickly as possible. The RAM fulfills this purpose. Each statement that manipulates a value within a program starts by transferring that information to a register and ends by putting it back into RAM. The Java Language Rules And Tools 3-17

18 Java Components Variables and Constants (Continued) There are two ways to treat the values stored in RAM: Variables The values put into variables can be changed at any time. Constants The values put into constants cannot be changed (values such as pi, for example). Registers are numbered by the CPU. Bytes within the RAM area are also numbered or addressed. You can give variables and constants identifiers to make them more meaningful and memorable in code, rather than using numeric addresses everywhere Java Programming for Non-Programmers

19 Java Components Java Primitive And Reference Types This section covers Java technology primitive types ( Java primitive types ) and Java technology reference types ( Java reference types ). The Java programming language rules dictate that you give each variable and constant a type. A variable s type restricts the values you can put into that variable. Some can only store whole numbers (integers) while others can store decimal places as well (floating point numbers). There are others for storing character information and true/false logical values. These are all primitives and make up the simple data parts of the Java programming language. When you create objects you store them in a separate part of memory, but you need to remember the address of where they were created. Reference variables are used to hold the addresses of objects. The Java Language Rules And Tools 3-19

20 Java Components Java Primitive And Reference Types (Continued) The eight primitive types (plus the reference type) are listed below and are explained in the rest of this module: byte short int long float double char boolean reference The reference type will be explained in more detail in References on page 29 in this module. To assign a type to a variable you declare the variable. A declaration statement has the form: int myfirstvariable; You can put a value into the variable using the = (assignment) operator: myfirstvariable = 27; Now you can use the variable name anywhere that you need to use the value you have stored there Java Programming for Non-Programmers

21 Java Primitive Types Integral Types There are four integral Java programming language types ( Java types ), with the corresponding keywords byte, short, int and long. The characteristics of each are as follows: Each type comprises a whole numbers of bytes; a byte is one byte long, a short is two bytes long, int is four bytes long, and a long is eight bytes long. That means that a short can hold numbers twice as long as a byte, anint can hold numbers twice as long as a short, and so on. Whole numbers can be either positive or negative. The sign of a value is held in the left-most bit; a 1 in this bit suggests a negative number while a 0 suggests a positive value. The Java Language Rules And Tools 3-21

22 Java Primitive Types Integral Types Continued) This explains why there isn t a number range of +/ There is more to making a number negative than putting a 1 in the leftmost bit; the computer uses a format called 2 s-complement that permits simple arithmetic of positive and negative values. With seven bits for the number there are 2 to the power of 7 (128) values in the range for both positive and negative numbers. Zero is counted as positive so the range is -128 through So, if you need to count up to 100, for example, a variable of type byte would suffice because we know from the specification that it can cope with values in that range. Table 3-2 lists all the integral types, their sizes and the range of possible values Table 3-2 Integral Types Integer Length Name or Type Range 8 bits byte bits short bits int bits long Note The most efficient of these is the int. This will be explained better in the section in this module titled Literal Values on page 32. You should use int for integer types during this course Java Programming for Non-Programmers

23 Java Primitive Types Floating Point Types There are two types for floating point numbers, float and double. As with the different integer types, these share functionality but differ in size. Table 3-3 Floating Point Types Float Length Name or Type 32 bits float 64 bits double The Java Language Rules And Tools 3-23

24 Java Primitive Types Floating Point Types (Continued) It is not possible to state the largest or smallest value that each of these can hold as they conform to a standard that allows variable accuracy depending on the magnitude of the number. The Java programming language has two pre-defined constants to denote the extents of the types, called POSITIVE_INFINITY and NEGATIVE_INFINITY. You can create floating point variables by using the type name in a declaration: double myfirstfloatingpoint; Now you can store values in this variable using the assignment operator again: myfirstfloatingpoint = ; You can also use the engineering notation for very large numbers, where the E can be either upper- or lowercase. myfirstfloatingpoint = E10; Note The double type is the most efficient of these. This will be explained better in the section in this module titled Literal Values on page 32. During this course you should use the double type for all floating point values Java Programming for Non-Programmers

25 Java Primitive Types Textual Types Another data type you need to be able to store and manipulate is character information. The primitive type used for storing a single character is char. Please note that you can only store one character in a char variable. If you want to store whole words or phrases you use an object type called String. This will be discussed later. Character variables are declared as shown in this example: char myfirstcharacter; The Java Language Rules And Tools 3-25

26 Java Primitive Types Textual Types (Continued) You can store values in such variables with the assignment operator. The values you store must be single characters and must be placed within single quotes ( ). These quotes convert what would be considered a one-character identifier such as g into the character value g. myfirstcharacter = g ; Variables of the char type can store any value from the Java technology character set ( Java character set ). Most computer languages use ASCII (the American Standard Code for Information Interchange), an 8-bit character set that has an entry for every English character and punctuation mark, numbers, and so on. The Java programming language uses a 16-bit character set called Unicode that can store all the necessary displayable characters from the vast majority of languages used in the modern world. Your programs can therefore be written so they will work and display the correct language for almost any country in the world Java Programming for Non-Programmers

27 Java Primitive Types Logical Types One of the things you will need to do most often in your programs is to make a decision. These decisions must equate to one of two values: yes/no, on/off, true/false, and so on. The type used to store such values is the boolean, named after the Irish mathematician George Boole who is considered the early computer pioneer responsible for formalizing the decision-based logic for computing. The two values that boolean variables can store in the Java programming language are true and false. These are keywords and therefore have special meaning to the JVM. You do not need to know what the values actually are, just that a boolean variable can hold one of the two values. For example: boolean myfirstboolean; myfirstboolean = true; The Java Language Rules And Tools 3-27

28 Java Primitive Types Logical Types (Continued) This is perhaps the most difficult type of variable to understand, or at least understand the need for it. Remember that the CPU only stores information for the statement it is currently working on, so everything relating to a previous statement has been lost. If you know that you will need the outcome of some choice later then you must store that decision using the boolean type Java Programming for Non-Programmers

29 References Overview Use reference variables to store the addresses of objects. Remember that objects are large pieces of memory that hold functionality as well as data. Objects represent discrete items from the problem you are attempting to solve. The rules of the integer type state that they cannot hold values that have anything after the decimal point. The rules of references state that they can store only the address of objects of their own type. A reference declared to store the address of a Computer object could not be used to hold the address of a User. For example, the declaration of a Computer reference variable would be: Computer laptop; The Java Language Rules And Tools 3-29

30 References Overview (Continued) You use the name of the class as the type in the declaration. You now have a variable called laptop that can store the address of a Computer object. To create objects, use the new keyword: laptop = new Computer(); Reference variables act the same as the eight primitive types when you assign values to them. For example: int first = 9; int second = first; Computer laptop = new Computer(); Computer anotherreferencetolaptop = laptop; The first two lines create an integer called first and use it to store the number 9, then create another integer called second and use it to store a copy of first. If the contents of first are later changed this does not automatically change second. The third line creates a reference called laptop and stores the address of a new Computer object in it. The last line creates another reference, called anotherreferencetolaptop, and gives it a copy of the address of the Computer object as stored in laptop. It does not duplicate the object but copies the address; there are now two references to one Computer Java Programming for Non-Programmers

31 References Strings You now know how to store single characters in char variables, but what if you want to store words or sentences instead? For this you use the String class. You also know now how to create objects from classes, using the new keyword. For a String this would look like the following example: String animal = new String("walrus"); Strings are unique among all object classes because they are the only class you can build objects from without needing to use the new keyword. The syntax for this version is: String variable = "string_value"; Example: String animal = "walrus"; The Java Language Rules And Tools 3-31

32 Literal Values All the types mentioned so far in this module have literal values; that is, values that are typed directly into programs and used immediately by the compiler. In fact, when the compiler does find a literal value, it puts it into the class file with a note to the JVM that the value should be treated as an unnamed constant. Given that the compiler is storing these values as unnamed constants, then they must all have a type. The type governs what you can and cannot do with literals Java Programming for Non-Programmers

33 Literal Values Integer Literals The following line: int num32 = 27; involves a literal value (27). Whenever the compiler finds a wholenumber literal such as 27 it creates an anonymous constant of type int to store it in. The assignment operator above is therefore putting an int value into an int variable, which is permitted. Consider the following statement, however: byte num8 = 27; The Java Language Rules And Tools 3-33

34 Literal Values Integer Literals (Continued) The compiler creates a variable called num8 which is of type byte (that is, one byte long). It then creates an anonymous int variable (4 bytes long) and gives it the value 27. When the compiler attempts to squeeze the 32-bit value into 8 bits of space it checks to see if the 3 bytes it is about to discard are important (that is, if they contain anything other than 0s). In this case they are all 0s, so the assignment will work. Now consider the following statement: byte num8 = 128; This time the 3 bytes of the literal int 128 which have to be discarded do contain a 1, so the compiler will declare an error. The code is attempting what is called demotion, implicitly assuming the compiler would permit you to reduce the size of a value from int to byte. Demotion is not allowed under any circumstances. A similar error is created when assigning literal values to short variables and the value is outside the range for a short. You can explicitly request that the compiler reduce the size of a literal value using the cast syntax. If you put a type keyword in parentheses immediately in front of a value, that value is converted to the type. For example: byte num8 = (byte)27; int num32 = 27; byte num8a = (byte)num32; There are problems with casting down to bytes and shorts, however. Consider the following lines int num32 = 257; byte num8 = (byte)num32; 3-34 Java Programming for Non-Programmers

35 Literal Values Integer Literals (Continued) You may be surprised that num8 now contains the value 1. A demoting cast simply cuts off the left end of the value until it is the right size to fit into the variable, as the following binary images show: 257 as 32 bits: cast to 8 bits: Promotion takes a value and makes it larger. Promotion does not need a cast, it is automatic and pads out the beginning of a value with zeros. Promotion permits you to store literal values in variables of type long. For example: long num64 = 27; Alternatively you can append an L to the end of the number, forcing the compiler to store it as an unnamed 64 bit constant. You can use either an upper- or lowercase letter for this but uppercase is preferred because a lowercase L looks very much like a 1 (one) in most fonts. long num64 = 27L; The Java Language Rules And Tools 3-35

36 Literal Values Floating Point Literals Floating point numbers also have literal values. These values can be written in one of a number of ways, including engineering notation. For example, the following are all valid floating point literal values: E5 27.9E6 It is valid to use integer literals when assigning values to floating point numbers and is considered another form of promotion: float fp32 = 27; double fp64a = 27; double fp64b = 27L; 3-36 Java Programming for Non-Programmers

37 Literal Values Floating Point Literals (Continued) Just as integer literals default in size to int, floating point literals default to double. For example, the following line will cause a compiler error: float fpoint32 = 27.9; Creating a 32-bit variable and then demoting a 64-bit value into it is not possible under any circumstances. Either cast the literal or immediately append it with an f or F character to suggest float-size: float fpoint32a = (float)27.9; float fpoint32b = 27.9F; The Java Language Rules And Tools 3-37

38 Literal Values Character Literals A character literal is a single character within single quotes. For example: a Any character that can be typed at the keyboard can be stored in a char variable using a character literal. But what about formatting characters such as carriage-return or tab? If you type either of those in a text editor, the text editor responds to them rather than making them a literal within the file itself. There is a series of special character literals in the Java programming language for the usual formatting characters of the Unicode set. They are all formatted as a backslash character ( \ ) plus one other character, both inside one set of single quotes. Table 3-4 lists some of the more common formatting characters Java Programming for Non-Programmers

39 Literal Values Character Literals (Continued) Table 3-4 Common Formatting Character Literals \t \r \n tab carriage return newline Any printable character from the Unicode character set that does not appear on your keyboard can be specified using the \u1234 sequence, where 1234 is the hexadecimal Unicode value of the character. The Java Language Rules And Tools 3-39

40 Literal Values boolean Literals boolean variables have two literal values: true and false. These are keywords and must therefore be spelled using lowercase letters. Reference Literals Reference variables can only be set by using the new keyword: Computer laptop = new Computer(); or by assigning a value from another reference variable: Computer anotherlaptopreference = laptop; You cannot specify an absolute address for an object in the Java programming language Java Programming for Non-Programmers

41 Literal Values Reference Literals (Continued) There is one literal reference value. It is often necessary to make an existing reference variable stop pointing to an object. The reference to use when a variable must point to nothing is null. Computer noobject = null; The Java Language Rules And Tools 3-41

42 Literal Values String Literals Strings are objects, not primitives. Objects do not have associated literal values, except for String objects. String animal = "walrus"; Anything in double quotes is a String object literal. One character in double quotes is a short String ("a"). The shortest String of all is just a pair of double quotes (""). If you need to state that a String reference does not refer to a String object, you assign it the null reference Java Programming for Non-Programmers

43 Naming Conventions Sun has devised a set of naming conventions that help to standardize the look and feel of Java code. They are based on the fact that an identifier must be an unbroken stream of characters that may include several words to give them more meaning. The following list describes the conventions for the four most common identifiers: Class names Class names are written as a sequence of descriptive words (usually nouns and adjectives) where each word joins onto the next, and each word starts with an uppercase letter and continues in lowercase: class ClassOne {} class MyPetRhinoceros {} Variable Names Variable names follow the same rules as class names but the phrase begins with a lowercase letter: int variableone; String myfirstreferencevariable; The Java Language Rules And Tools 3-43

44 Naming Conventions Constant Names Constant names have uppercase letters for all the words in the phrase and underscore characters ( _ ) between each word: final int CONSTANT_ONE = 27; final double PI = ; Note Constants are declared in the same way as variables but preceded by the final keyword. Method Names Methods follow the same format and style as variables except the phrase usually contains a verb structure and always ends with a pair of parentheses. The parentheses are not part of the name but part of the method-calling mechanism. int methodone() {} void printtheresults() {} 3-44 Java Programming for Non-Programmers

45 Check Your Progress Before continuing on to the next module, check that you are able to accomplish or answer the following: Use comments to document your code Use the Java primitive data storage types Use primitive literal values The Java Language Rules And Tools 3-45

46 Think Beyond If you want your program to run intelligently, how do you get it to make decisions to take different actions depending on the outcome of different tests? 3-46 Java Programming for Non-Programmers

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

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

2 rd class Department of Programming. OOP with Java Programming

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

More information

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

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

More information

Programming Lecture 3

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

More information

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

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

More information

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

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

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

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

CS112 Lecture: Primitive Types, Operators, Strings

CS112 Lecture: Primitive Types, Operators, Strings CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive

More information

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

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

More information

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

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

More information

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

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

More information

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

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

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

More information

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

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

The MaSH Programming Language At the Statements Level

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

More information

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

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. Today! Build HelloWorld yourself in BlueJ and Eclipse. Look at all the Java keywords. Primitive Types. HelloWorld in BlueJ 1. Find BlueJ in the start menu, but start the Select VM program instead (you

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output

CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output CS112 Lecture: Variables, Expressions, Computation, Constants, Numeric Input-Output Last revised January 12, 2006 Objectives: 1. To introduce arithmetic operators and expressions 2. To introduce variables

More information

Visual C# Instructor s Manual Table of Contents

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

More information

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

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

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

More information

COMP 202 Java in one week

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

More information

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

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS122 Lecture: From Python to Java last revised January 4, Objectives: Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

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

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Data Types and Variables in C language

Data Types and Variables in C language Data Types and Variables in C language Basic structure of C programming To write a C program, we first create functions and then put them together. A C program may contain one or more sections. They are

More information

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

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

More information

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

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

More information

Maciej Sobieraj. Lecture 1

Maciej Sobieraj. Lecture 1 Maciej Sobieraj Lecture 1 Outline 1. Introduction to computer programming 2. Advanced flow control and data aggregates Your first program First we need to define our expectations for the program. They

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 2-3 Edgardo Molina Fall 2013 City College of New York 1 C++ for Engineers and Scientists Third Edition Chapter 2 Problem Solving Using C++ 2 Objectives In this

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

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

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

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

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

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

More information

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on: Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions

More information

INTRODUCTION 1 AND REVIEW

INTRODUCTION 1 AND REVIEW INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

More information

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

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

More information

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

The C++ Language. Arizona State University 1

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

More information

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points) Standard 11 Lesson 9 Introduction to C++( Up to Operators) 2MARKS 1. Why C++ is called hybrid language? C++ supports both procedural and Object Oriented Programming paradigms. Thus, C++ is called as a

More information

Exercise: Using Numbers

Exercise: Using Numbers Exercise: Using Numbers Problem: You are a spy going into an evil party to find the super-secret code phrase (made up of letters and spaces), which you will immediately send via text message to your team

More information

printf( Please enter another number: ); scanf( %d, &num2);

printf( Please enter another number: ); scanf( %d, &num2); CIT 593 Intro to Computer Systems Lecture #13 (11/1/12) Now that we've looked at how an assembly language program runs on a computer, we're ready to move up a level and start working with more powerful

More information

CPS122 Lecture: From Python to Java

CPS122 Lecture: From Python to Java Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

Accelerating Information Technology Innovation

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

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

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

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program? Intro to Programming & C++ Unit 1 Sections 1.1-4 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2019 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program a set

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

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

Language Fundamentals Summary

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

More information

LECTURE 02 INTRODUCTION TO C++

LECTURE 02 INTRODUCTION TO C++ PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

More information

An overview of Java, Data types and variables

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

More information

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

BASIC ELEMENTS OF A COMPUTER PROGRAM

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

More information

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

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

More information

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes. 10th ICSE. Saravanan Ganesh Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

Basic data types. Building blocks of computation

Basic data types. Building blocks of computation Basic data types Building blocks of computation Goals By the end of this lesson you will be able to: Understand the commonly used basic data types of C++ including Characters Integers Floating-point values

More information

Programming in C++ 4. The lexical basis of C++

Programming in C++ 4. The lexical basis of C++ Programming in C++ 4. The lexical basis of C++! Characters and tokens! Permissible characters! Comments & white spaces! Identifiers! Keywords! Constants! Operators! Summary 1 Characters and tokens A C++

More information

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

IT 374 C# and Applications/ IT695 C# Data Structures IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

More information

FRAC: Language Reference Manual

FRAC: Language Reference Manual FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

More information

Language Reference Manual

Language Reference Manual ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents

More information

ARG! Language Reference Manual

ARG! Language Reference Manual ARG! Language Reference Manual Ryan Eagan, Mike Goldin, River Keefer, Shivangi Saxena 1. Introduction ARG is a language to be used to make programming a less frustrating experience. It is similar to C

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

Basic Types, Variables, Literals, Constants

Basic Types, Variables, Literals, Constants Basic Types, Variables, Literals, Constants What is in a Word? A byte is the basic addressable unit of memory in RAM Typically it is 8 bits (octet) But some machines had 7, or 9, or... A word is the basic

More information

REVIEW. The C++ Programming Language. CS 151 Review #2

REVIEW. The C++ Programming Language. CS 151 Review #2 REVIEW The C++ Programming Language Computer programming courses generally concentrate on program design that can be applied to any number of programming languages on the market. It is imperative, however,

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

CS112 Lecture: Working with Numbers

CS112 Lecture: Working with Numbers CS112 Lecture: Working with Numbers Last revised January 30, 2008 Objectives: 1. To introduce arithmetic operators and expressions 2. To expand on accessor methods 3. To expand on variables, declarations

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

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

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

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

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types ME240 Computation for Mechanical Engineering Lecture 4 C++ Data Types Introduction In this lecture we will learn some fundamental elements of C++: Introduction Data Types Identifiers Variables Constants

More information

Lesson 2A Data. Data Types, Variables, Constants, Naming Rules, Limits. A Lesson in Java Programming

Lesson 2A Data. Data Types, Variables, Constants, Naming Rules, Limits. A Lesson in Java Programming Lesson 2A Data Data Types, Variables, Constants, Naming Rules, Limits A Lesson in Java Programming Based on the O(N)CS Lesson Series License for use granted by John Owen to the University of Texas at Austin,

More information

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

More information

Program Elements -- Introduction

Program Elements -- Introduction Program Elements -- Introduction We can now examine the core elements of programming Chapter 3 focuses on: data types variable declaration and use operators and expressions decisions and loops input and

More information

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Copyright 2009 Publishing Pearson as Pearson Education, Addison-Wesley Inc. Publishing as Pearson Addison-Wesley

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

Java Basic Datatypees

Java Basic Datatypees Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,

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

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

Sprite an animation manipulation language Language Reference Manual

Sprite an animation manipulation language Language Reference Manual Sprite an animation manipulation language Language Reference Manual Team Leader Dave Smith Team Members Dan Benamy John Morales Monica Ranadive Table of Contents A. Introduction...3 B. Lexical Conventions...3

More information

Creating a C++ Program

Creating a C++ Program Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer. 1 Creating a C++ Program created using an

More information

Chapter 2: Programming Concepts

Chapter 2: Programming Concepts Chapter 2: Programming Concepts Objectives Students should Know the steps required to create programs using a programming language and related terminology. Be familiar with the basic structure of a Java

More information

2 nd Week Lecture Notes

2 nd Week Lecture Notes 2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

More information

COMP6700/2140 Data and Types

COMP6700/2140 Data and Types COMP6700/2140 Data and Types Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU February 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February

More information

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

More information

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

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing Introduction 1 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Focus of the Course Object-Oriented Software Development

More information

3. Simple Types, Variables, and Constants

3. Simple Types, Variables, and Constants 3. Simple Types, Variables, and Constants This section of the lectures will look at simple containers in which you can storing single values in the programming language C++. You might find it interesting

More information