Chapter 2-Variables and their manipulationsSimple input and output3Programming Logic and Design, Ninth Edition
ObjectivesIn this chapter, you will learn about:•Declaring and using variables•Data types•Performing arithmetic operations•Declaring and using constants•Object Oriented Programming JAVA basics•Simple input and output4Programming Logic and Design, Ninth Edition
Working with Variables•Variable are named memory locations•Contents can vary or differ over time•Declarationis a statement that provides a variable's:•Data type- specify the type of data it will holds•Identifier - name of variable in memory•Optionally, an initial value5Programming Logic and Design, Ninth Edition
Declaring and Using Variables•What are data types?•Data type describes:•What values can be held by the item•How the item is stored in memory•What operations can be performed on the item•All programming languages support these data types:•Numericconsists of numbers that can be used in math•Stringis anything not used in math6Programming Logic and Design, Ninth Edition
Understanding a Declaration’s DataType•Numeric variable•Holds digits•Can perform mathematical operations on it•String variable•Can hold text•Letters of the alphabet•Special characters such as punctuation marks•Type-safety•Prevents assigning values of an incorrect data type7Programming Logic and Design, Ninth Edition
Data types in Java•Java has 8 primitive data types-Intfor integer numbers (26,645445)-floatfor floating point numbers (26.5f,6.2f)-doublefor floating point numbers (23.6547132654)-charfor characters (“a”,”b”)-Boolean(True or False)-longfor long integers-Shortfor short integers-Byte8Programming Logic and Design, Ninth Edition
Data Types in Java••Watch this video for understanding data types in better way9
Understanding a Declaration’sIdentifier•Anidentifieris a variable’s name•Programmer chooses reasonable and descriptive names for variables•Programming languages have rules for creating identifiers•Most languages allow letters and digits•Some languages allow hyphens•Reservedkeywordsare not allowed10Programming Logic and Design, Ninth Edition
Understanding a Declaration’sIdentifier(continued -1)•