LESSON 3 - Identifiers JAVA PROGRAMMING. Identifiers All the Java components —classes, variables, and methods— need names. In Java these names are called.

Slides:



Advertisements
Similar presentations
Chapter 1: Computer Systems
Advertisements

Programming with Java. Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: –Understand the.
1 Java Programming Basics SE-1011 Dr. Mark L. Hornick.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
The Java Programming Language
Outline Java program structure Basic program elements
LESSON 4 - Variables JAVA PROGRAMMING. Variables Variable is a named storage location that stores data and the value of the data may change while the.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
1. 2 Chapter 1 Introduction to Computers, Programs, and Java.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
© 2006 Pearson Education Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition.
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Programming Style and Documentation Objective(s) F To become familiar with Java Style and Documentation Guidelines.
1 Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example  The MyInput class F Identifiers, Variables, and Constants F Primitive.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Language and SW Dev’t
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
C Derived Languages C is the base upon which many build C++ conventions also influence others *SmallTalk is where most OOP comes Java and Javascript have.
Java Syntax and Style JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin,
Chapter 2: Java Fundamentals
Chapter 1: Introduction Java Programming Language How the Java Virtual Machine Works (compiling, etc…) Update by: Dan Fleck Coming up: The Java Programming.
Java The Java programming language was created by Sun Microsystems, Inc. It was introduced in 1995 and it's popularity has grown quickly since A programming.
Lecture 2 Software Concepts Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 1 Introduction to Computers, Programs,
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Primitive Data Types and Operations F Introduce Programming with an Example F Identifiers, Variables, and Constants F Primitive Data Types –byte, short,
The Essentials of a Java Program JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin,
1.  Algorithm: 1. Read in the radius 2. Compute the area using the following formula: area = radius x radius x PI 3. Display the area 2.
DEFINITION Java IDE created by Xinox Software JCreator is a powerful interactive development environment (IDE) for Java technologies. A Java compiler.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Working with Java.
Chapter 1 Introduction to Computers, Programs, and Java
Lecture 3: Operators, Expressions and Type Conversion
Lecture 2: Data Types, Variables, Operators, and Expressions
CS180 – Week 1 Lecture 3: Foundation Ismail abumuhfouz.
Variables and Arithmetic Operators in JavaScript
University of Central Florida COP 3330 Object Oriented Programming
Statements, Comments & Simple Arithmetic
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Chapter 2: Java Fundamentals
Units with – James tedder
Units with – James tedder
JavaScript Reserved Words
elementary programming
Documentation and Style
Anatomy of a Java Program
Focus of the Course Object-Oriented Software Development
Instructor: Alexander Stoytchev
Chap 2. Identifiers, Keywords, and Types
Chapter 2 Primitive Data Types and Operations
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

LESSON 3 - Identifiers JAVA PROGRAMMING

Identifiers All the Java components —classes, variables, and methods— need names. In Java these names are called identifiers, and, there are rules for what constitutes a legal Java identifier. Beyond what's legal, Java programmers (and Sun) have created conventions for naming methods, variables, and classes.

Rules for naming Identifiers 1. Identifiers must start with a letter, a currency character ($), or a connecting character such as the underscore ( _ ). Identifiers cannot start with a number! 2. After the first character, identifiers can contain any combination of letters, currency characters, connecting characters, or numbers. 3. Identifier can be any length. In practice, there is no limit to the number of characters an identifier can contain. 4. You can't use a Java keyword as an identifier. (See “Java Keywords,” for a list of reserved words). 5. Identifiers in Java are case ‐ sensitive; amoud and Amoud are two different identifiers. 6. Identifier cannot be true, false or null.

Java keywords abstract elselongsynchronizedboolean breakbytecaseextendsfinal finallynative newpackageprivate thisthrow throws transient catch char class float forGoto if protected publicreturn try void volatileconst continue default doimplements import instanceof intShort static strictfp super while double Interface switch

Self Test 1 (Ex 6 Ques 1 pg 29) Which of the following are valid Java identifiers? If invalid, give reason: i. Double ii. 2CS iii. Big_N iv. $67 v. Boolean vi. _number

Which of the following are valid Java identifiers? If invalid, give reason: i. Int ii. public iii. private iv. AMOUD v. 2*K vi. var one

Sun's Java Code Conventions The naming standards that Sun recommends: Classes and interfaces The first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase (a format that's sometimes called "camelCase"). – For classes, the names should typically be nouns. For example: Animal Account PrintWriter – For interfaces, the names should typically be adjectives like Runnable Serializable

Sun's Java Code Conventions Methods The first letter should be lowercase, and then normal camelCase rules should be used. – In addition, the names should typically be verbnoun pairs. For example: getBalance doCalculation setCustomerName calcArea

Sun's Java Code Conventions Variables Like methods, the camelCase format should be used, starting with a lowercase letter. Sun recommends short, meaningful names, which sounds good to us. Some examples: – nama – buttonWidth – accountBalance – myString

Sun's Java Code Conventions Constants Java constants are created by marking variables static and final. They should be named using uppercase letters with underscore characters as separators: MIN_HEIGHT

Self Test 2 (Ex 6 Ques 4 pg 30) Which of these identifiers violate the naming convention for class name? i. m2t5 ii. BigCircle iii. smallTriangle iv. CPA v. mylittleprogram

Self Test 2 (Ex 6 Ques 4 pg 30) Which of these identifiers violate the naming convention for class name? i. Sample Program ii. Customer iii. 3Circles iv. Lab1Ex6 v. ThisIsLongProgramName

Programming Style and Documentation Appropriate Comments Naming Conventions Proper Indentation and Spacing Lines Block Styles

Appropriate Comments Include a summary at the beginning of the program to explain what the program does, its key features, its supporting data structures, and any unique techniques it uses. Include your name, class section, instructor, date, and a brief description at the beginning of the program.

Proper Indentation and Spacing Indentation – Indent two spaces. Spacing – Use blank line to separate segments of the code.

Block Styles Use next-line style for braces. public class Test { public static void main(String[] args) { System.out.println("Block Styles"); }

Block Styles Use end-of-line for braces. public class Test { public static void main(String[] args) { System.out.println("Block Styles"); }

Self Test 3 Given the following program. Reformat the program according to the programming style and documentation guidelines. 1. public class Cubaan 2. {public static void main (String[] args) 3. {double value1 = ; 4. System.out.print("Testing :"); 5. System.out.printf("%6.3f", value1);}}

END OF LESSON 3 THE END