Basic Java structural components

Slides:



Advertisements
Similar presentations
Chapter 3 Basic Java structural components. This chapter discusses n Some Java fundamentals. n The high-level structure of a system written in Java. u.
Advertisements

Chapter 1: Computer Systems
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
The Java Programming Language
1 Lexical Elements Chapter 2 in ABC. 2 Tokens Token = word / symbol, does not contain white spaces. Tokens in C are either: –keywords –identifiers –constants.
Outline Java program structure Basic program elements
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc.
Chapter 2: Introduction to C++.
1 Lecture 3  Lexical elements  Some operators:  /, %, =, +=, ++, --  precedence and associativity  #define  Readings: Chapter 2 Section 1 to 10.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
1 Workshop Topics - Outline Workshop 1 - Introduction Workshop 2 - module instantiation Workshop 3 - Lexical conventions Workshop 4 - Value Logic System.
A Variable is symbolic name that can be given different values. Variables are stored in particular places in the computer ‘s memory. When a variable is.
Primitive Data Types and Operations Identifiers, Variables, and Constants Primitive Data Types Byte, short, int, long, float, double, char, boolean Casting.
Java Language and SW Dev’t
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
The Java Programming Language
CSC204 – Programming I Lecture 4 August 28, 2002.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 2: Java Fundamentals
The Fundamentals of C++ Chapter 2: Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Characters and tokens Characters are the basic building blocks in C program, equivalent to ‘letters’ in English language Includes every printable character.
 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 the.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
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.
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Copyright Curt Hill Variables What are they? Why do we need them?
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Ajmer Singh PGT(IP) Programming Fundamentals. Ajmer Singh PGT(IP) Java Character Set Character set is a set of valid characters that a language can recognize.
1 Comments Allow prose or commentary to be included in program Importance Programs are read far more often than they are written Programs need to be understood.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Agenda Comments Identifiers Keywords Syntax and Symentics Indentation Variables Datatype Operator.
Tokens in C  Keywords  These are reserved words of the C language. For example int, float, if, else, for, while etc.  Identifiers  An Identifier is.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
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.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
C++ First Steps.
Definition of the Programming Language CPRL
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Working with Java.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Wel come.
Variables and Primative Types
University of Central Florida COP 3330 Object Oriented Programming
Section 3.2c Strings and Method Signatures
Chapter 2: Introduction to C++
Introduction to Python
null, true, and false are also reserved.
2.1 Parts of a C++ Program.
Introduction to Java Programming
An overview of Java, Data types and variables
Chapter 1: Computer Systems
Chapter 2: Java Fundamentals
Units with – James tedder
Anatomy of a Java Program
Focus of the Course Object-Oriented Software Development
Chapter 2: Introduction to C++.
Fundamental Programming
Chap 2. Identifiers, Keywords, and Types
Lexical Elements & Operators
Chapter 2 Primitive Data Types and Operations
The Fundamentals of C++
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

Basic Java structural components Chapter 3 Basic Java structural components

This chapter discusses Some Java fundamentals. The high-level structure of a system written in Java. packages compilation units Some fundamental elements that make up a Java program. identifiers literals

Creating a Software System Define the classes that will provide the objects. A class definition determines the features and behavior of the objects that are instances of the class. A program source is a collection of class definitions.

Packages A system definition is composed of a number of modules called packages. A package is a collection of one or more closely related classes. public class: a class that is accessible throughout the entire system.

Compilation unit A source file containing the definition of one or more classes of a package. It can contain the definition of at most one public class.

Identifiers Sequences of characters that can be used to name things in a Java program. packages classes objects properties features

Identifiers (cont.) A sequence of letters, digits, ‘$’s, and/or ‘_’s. Cannot begin with a digit. Case sensitive: ‘A’ and ‘a’ are considered different!!!

Identifiers (cont.) Legal: Illegal: X Abc A_a_x b$2 aVeryLongIdentifier b29 a2b $_ $$$ IXLR8 Illegal: 2BRnot2B a.b Hello! A-a A+a All different identifiers: total Total TOTAL tOtAl

Identifiers already in “use” Called reserved or key words For example: package if class else public for int float interface abstract private boolean char import implements extends

Choosing identifiers Choose descriptive names. Student or Textbook not S or Thing Avoid overly long identifiers. HoldsTheNumberOfIterationsOfLoop Avoid abbreviations; if you abbreviate, be consistent. Wrong: clientRec and studentRecord

Choosing identifiers (cont.) Be as specific as possible. Take particular care to distinguish closely related entities. Effective Less-Effective newMasterRecord masterRecord1 oldMasterRecord masterRecord2 Don’t incorporate the name of its syntactic category in its name. Not Recommended: StudentClass

Literals Sequences of characters that denote particular values. We include literals in our programs to denote specific values. They represent values in a “literal” sense

Type int Literals Whole numbers -- both positive and negative. Commas, periods, and leading zeros are not allowed in ‘int’s. Legal: 25 0 123456 -289765 7 Illegal: 123,456 25.0 014765

Type double Literals Numbers that involve decimal points. 0.5 -2.67 0.00123 2. .6 Digits before and after the decimal point are preferred.

Exponential Notation Used to represent double values. The “e” can be upper or lower case The mantissa need not contain a decimal point

Type char literals Single characters between apostrophes (single quotes). ‘A’ ‘a’ ‘2’ ‘;’ ‘ ’ 3 characters cannot be represented as themselves: ‘  ‘\’’ (apostrophe) “  ‘\”’ (quotation mark) \  ‘\\’ (backslash)

Type boolean literals Only 2 possible literals true (Not TRUE or True) false

General lexical rules A source file is made up of tokens: identifiers, keywords, literals, and punctuation marks. Spaces and line ends are somewhat arbitrary. “White” spaces (tabs, carriage returns, spaces) are required between words: Wrong: publicclass Student

General lexical rules (cont.) Spaces are not required, but are permitted, around punctuation. All correct examples: public class Student{ public class Student { a+b a + b Extra spaces and line endings are allowed: public class Student {

General lexical practices Be consistent in spacing and line endings to make your programs as readable as possible. Use uniform indentation levels to indicate logical levels in code. Adhere to accepted industry style conventions for added readability.

Comments Explanatory remarks are included in a program for the benefit of human readers, but are ignored by the compiler. Use // to treat the remainder of the line as a comment. Use /* and */ to begin and end a section or multi-line comment. /* This is a multi-line or section comment */

To recap Fundamental structure of a Java program. Packages Class definitions and compilation units Instances of classes Lexical structure Identifiers Literals Comments