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

Similar documents
Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

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

An overview of Java, Data types and variables

Program Fundamentals

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

3. Java - Language Constructs I

Computer Components. Software{ User Programs. Operating System. Hardware

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

COMP 202 Java in one week

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

Computer Components. Software{ User Programs. Operating System. Hardware

Expressions and Data Types CSC 121 Spring 2017 Howard Rosenthal

CSC 1214: Object-Oriented Programming

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

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

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

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

The MaSH Programming Language At the Statements Level

Java Programming Language Mr.Rungrote Phonkam

Welcome to CSE 142! Zorah Fung University of Washington, Spring Building Java Programs Chapter 1 Lecture 1: Introduction; Basic Java Programs

2 rd class Department of Programming. OOP with Java Programming

Language Fundamentals Summary

Welcome to CSE 142! Whitaker Brand. University of Washington, Winter 2018

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

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

Java Notes. 10th ICSE. Saravanan Ganesh

ECE 122 Engineering Problem Solving with Java

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

Building Java Programs. Introduction to Programming and Simple Java Programs

Java Bytecode (binary file)

Basics of Java Programming

JAVA Programming Fundamentals

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

The Java Language Rules And Tools 3

Pace University. Fundamental Concepts of CS121 1

CSCI 2101 Java Style Guide

CompSci 125 Lecture 02

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

4 Programming Fundamentals. Introduction to Programming 1 1

Getting started with Java

Java Programming. Atul Prakash

Key Differences Between Python and Java

3. Java - Language Constructs I

Accelerating Information Technology Innovation

CS 106 Introduction to Computer Science I

Introduction to Programming Using Java (98-388)

Full file at

Imports. Lexicon. Java/Lespérance 1. PROF. Y. LESPÉRANCE Dept. of Electrical Engineering & Computer Science

Array. Prepared By - Rifat Shahriyar

VARIABLES AND CONSTANTS

Getting started with Java

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

Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

DM550 Introduction to Programming part 2. Jan Baumbach.

Lexical Considerations

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

PROGRAMMING FUNDAMENTALS

Computational Expression

Games Course, summer Introduction to Java. Frédéric Haziza

JAVA Ch. 4. Variables and Constants Lawrenceville Press

Introduction to Java

A.A. 2008/09. Why introduce JavaScript. G. Cecchetti Internet Software Technologies

Syntax and Variables

The C++ Language. Arizona State University 1

Basic Types, Variables, Literals, Constants

Chapter 2. Elementary Programming

Lexical Considerations

DM503 Programming B. Peter Schneider-Kamp.

: Primitive data types Variables Operators if, if-else do-while, while, for. // // First Java Program. public class Hello {

1 Lexical Considerations

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

Lecture 1: Basic Java Syntax

CMPT 125: Lecture 3 Data and Expressions

Tony Valderrama, SIPB IAP 2009

Binghamton University. CS-211 Fall Syntax. What the Compiler needs to understand your program

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Lecture 2 Tao Wang 1

Tokens, Expressions and Control Structures

BASIC ELEMENTS OF A COMPUTER PROGRAM

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

Introduction to Java. Java Programs Classes, Methods, and Statements Comments Strings Escape Sequences Identifiers Keywords

Programming Lecture 3

Java language. Part 1. Java fundamentals. Yevhen Berkunskyi, NUoS

CS11 Java. Fall Lecture 1

Lecture Notes. System.out.println( Circle radius: + radius + area: + area); radius radius area area value

The Warhol Language Reference Manual

Variables. Data Types.

Software Practice 1 Basic Grammar

Object-Oriented Programming

Software and Programming 1

CHAPTER 2 Java Fundamentals

Lecture Set 2: Starting Java

6.096 Introduction to C++ January (IAP) 2009

Java Identifiers, Data Types & Variables

Lecture Set 2: Starting Java

Contents. Figures. Tables. Examples. Foreword. Preface. 1 Basics of Java Programming 1. xix. xxi. xxiii. xxvii. xxix

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

Entering the world of Javatar

Fundamentals of Programming CS-110. Lecture 2

Tools : The Java Compiler. The Java Interpreter. The Java Debugger

Transcription:

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 and coding standards use arithmetic operator and expressions in code use different types of conditional & loop structures

Overview Structure of Java program Identifiers Java Keywords Arithmetic/Expression Control flow/structures

Structure of Java Program Example 2.1 //HelloWorld.java program class HelloWorld { } public static void main(string[] args) { System.out.println( Hello World! );}

Structure of Java Program Consist of two main parts : 1) class All the program is enclosed in class definition (e.g: in Example 2.1, a class called HelloWorld). class is keyword, HelloWorld is class name. Programmer-defined class/ user-defined class. The name of the class is called identifier.

Structure of Java Program 2) main() The body of the program is contained in a method (function) called main(). main() method begins the execution of Java application. public means the method can be called anywhere in the program. static means the method is same for all objects of class. void means the main() does not return value. String args[] represents command-line arguments

Structure of Java Program Other components: Comments Block and scope Identifiers Java Keyword Statement

Comment To documentation purpose To increase program readibility Use three permissible styles: //This is a comment /*This is a comment*/ /** This is a comment*/

Block and scope Sometimes called as compound statement A group of statements bound by braces ({ }) A block must be used in a class definition Block statement can be nested

Block and scope A block is a section of code The concept of scope is tightly linked to blocks Scope refers to how sections of a program (blocks) affect the lifetime of variables Scope is determined by blocks

Identifiers Names given to a variable, class or method A series of characters consisting of letters, digits, underscores and dollar sign ($) Are case-sensitive and have no maximum length

Variable Definition: An item of data named by an identifier. An object stores its state in variables. You must explicitly provide a name and a type for each variable you want to use in your program. Variable name is used to refer to the data that the variable contains. The variable's type determines what values it can hold and what operations can be performed on it.

Variable Three types of variables in Java : instance variable, class variable and local variable. Instance variable define attribute or state for the particular object Class variable define attribute/state for all class s object/instance. Local variable declared and used inside method definitions.

Variable: DO & DON T It must be a legal identifier and begins with a letter. It must not be a keyword, a boolean literal (true or false), or the reserved word null. It must be unique within its scope. Variable names begin with a lowercase letter, and class names begin with an uppercase letter.

Variable: DO & DON T If a variable name consists of more than one word, the words are joined together, and each word after the first begins with an uppercase letter, like this: isvisible. The underscore character (_) is acceptable anywhere in a name, but by convention is used only to separate words in constants (because constants are all caps by convention and thus cannot be case-delimited)

Variable Operation Declaring variable : Consists of a type & variable name Format : type variable name Example : int number; Assigning/Initializing value to variable int number = 5; number = nombor; MyDate my_birth = new MyDate; Accessing variable (input statement,object invocation)

Data Types Define the storage methods available for storing Every variable must have a data type. A variable's data type determines the values that the variable can contain and the operations that can be performed on it. Java data types : simple and composite Simple data types: integer, floating point, boolean, character types Composite : string, arrays, classes.

Data type :Integer Can be both positive, negative and value 0. Type byte short int long Size 8 bits 16 bits 32 bits 64 bits Example declaration: int i; short rocketfuel; long angle, magnitude; byte red, green, blue;

Data type :Floating point Represent numbers with both whole numbers and fractional part. Types of floating point : double and float Type float double Example declaration: double number; float number; Size 32 bits 64 bits

Data type :Character Symbol that is used in text. char data types is 16 bits. Declare a char value like this: char alphabet or char alpha = a ; Stores only single character

Data type :Character Special character literals Character Backslash Backspace Line feed Tab Symbol \\ \b \n \t Example: char backspace = \b ;

Data type :Boolean A way to define if specific condition has been met. Represented in Java by boolean data type Two possible values : true /false Example : boolean value; boolean value = true;

String:data type & literal String a combination of characters Consists of a series of characters inside double quotes Handled by special class calls String Example : Hi! I am a string literals Can contains character constant "A string with a \t tab in it"

Constant constant data that has value which never change Used final to represent constant value Example : final float SALESTAX = 0.06;

Java Language Keywords Predefined identifiers reserved by Java for specific purpose. Java has richer set of keywords than C or C++ Keywords are reserved words. Cannot use any of these words as names in Java programs. true, false, and null are reserved words, so cannot use them as names in programs either.

Java Language Keywords while while while while static static static static instanceof instanceof instanceof instanceof do do do do volatile volatile volatile volatile short short short short import import import import default default default default void void void void return return return return implements implements implements implements continue continue continue continue try try try try public public public public if if if if const const const const * transient transient transient transient protected protected protected protected goto goto goto goto * class class class class throws throws throws throws private private private private for for for for char char char char throw throw throw throw package package package package float float float float catch catch catch catch this this this this new new new new finally finally finally finally case case case case synchronized synchronized synchronized synchronized native native native native final final final final byte byte byte byte switch switch switch switch long long long long extends extends extends extends break break break break super super super super interface interface interface interface else else else else boolean boolean boolean boolean strictfp strictfp strictfp strictfp ** int int int int double double double double abstract abstract abstract abstract

Valid/Invalid Identifiers Valid HelloWorld Hi_Mom tall poundage Invalid Hello World (uses a space) Hi Mom! (uses a space and punctuation mark) short (this is a Java keyword) #age (cannot begin with a letter)

Statement Input and output statement Output statement : System.out.println ( Hello World! ); System.out.print( Hello World! );