JAVA PROGRAMMING PART II.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Chapter 1: Computer Systems
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.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Review… Yong Choi BPA CSUB. Access Modifier public class HelloWorldApp –More detailes of Java key (reserved) wordJava key (reserved) word –The keyword,
Outline Java program structure Basic program elements
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Copyright 2013 by Pearson Education Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
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 (
***** SWTJC STEM ***** Chapter 2-2 cg Identifiers - Naming Identifier, the name of a Java programming component. Identifier naming rules... Must.
General Features of Java Programming Language Variables and Data Types Operators Expressions Control Flow Statements.
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.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
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.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 2: Java Fundamentals
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
1 Primitive data types, expressions, and variables.
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.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Java Programming The Language of Now & the Future* Lecture 0 An Introduction to Java Syntax for Non-C Programmers John Morris Department of Electrical.
Copyright Curt Hill Variables What are they? Why do we need them?
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Operators in JAVA. Operator An operator is a symbol that operates on one or more arguments to produce a result. Java provides a rich set of operators.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
A Introduction to Computing II Lecture 1: Java Review Fall Session 2000.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Object Oriented Programming Lecture 2: BallWorld.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Introduction to Java Programming by Laurie Murphy Revised 09/08/2016.
Copyright 2010 by Pearson Education APCS Building Java Programs Chapter 1 Lecture 1-1: Introduction; Basic Java Programs reading:
25-October-2002cse JavaFundamentals © 2002 University of Washington1 Java Fundamentals CSE 413, Autumn 2002 Programming Languages
Key Words / Reserved Words
JAVA MULTIPLE CHOICE QUESTION.
Working with Java.
Chapter 4 Assignment Statement
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Sachin Malhotra Saurabh Choudhary
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
Chapter 3 Assignment Statement
Starting JavaProgramming
null, true, and false are also reserved.
Introduction to Java Programming
Basics of ‘C’.
An overview of Java, Data types and variables
Instructor: Alexander Stoytchev
Chapter 1: Computer Systems
Units with – James tedder
Units with – James tedder
JavaScript Reserved Words
Focus of the Course Object-Oriented Software Development
Module 2 - Part 1 Variables, Assignment, and Data Types
Instructor: Alexander Stoytchev
Chap 2. Identifiers, Keywords, and Types
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

JAVA PROGRAMMING PART II

CONSTANT Integer constant Real constant Boolean constant Constant is input data for machine get to calculate following our instructions Integer constant Real constant Boolean constant Character constant String constant

Integer Constants Integer -(231+1) to 231-1 Decimal Oct Hex Long Integer -(263+1) to 231-1 Example -897, 356, 0 Example 0700, 0356, 00 Example 0x89A, 0x356, 0x0 Example 50000000000L,23145l,-13L

Integer Constants 12 10 18 //IntegerLiteral.java //Represent integer : Decimal, Octagonal and Hexagonal public class IntegerLiteral { public static void main(String args[]) { System.out.println(12); //Show Decimal constant System.out.println(012); //Show Octagonal constant System.out.println(0x12);//Show Hexagonal constant } 12 10 18

Integer Constants 1942892530 12345678901234 //LongConstant.java //Represent Normal Integer and Long Integer Public class LongConstant { public static void main (String args[]) { System.out.println(12345678901234); System.out.println(12345678901234L); } 1942892530 12345678901234

Real Constants Float -1.4 x 1045 and +3.4 x 1038 Double -4.9 x 10-324 and 1.7 x 10308 Suffix ‘F’ or ‘f’ Example 10.2F, 3.14f, 2.35E5F, -3.14e45F Suffix ‘D’ or ‘d’ Example 10.2D, -1.89d, 2.35E5D, -1.4e309D

Boolean Constant 2 value true false Note: all character in word is small.

Character Constants All character represent in Unicode 16 bits represent between ‘’ single quote Represent special character Represent in unicode ‘a’ ‘A’ ‘z’ ‘Z’ ‘0’ ‘9’ ‘β’ ‘\t’ ‘\b’ ‘\n’ ‘\f’ ‘\r’ ‘\’’ ‘\”’ ‘\\’ \u0061 \u0041 \u007a \u005a \u0030 \u0039 \u00a7 ‘a’ ‘A’ ‘z’ ‘Z’ ‘0’ ‘9’ ‘β’

Escape sequence //CtrlChar.java Public class CtrlChar { public static void main(String args[]) { System.out.println(“backspace = <\b>”); System.out.println(“new line = <\n>”); System.out.println(“return = <\r>”); System.out.println(“formfeed = <\f>”); System.out.println(“tab = <\t>”); System.out.println(“backslash = <\\>”); System.out.println(“single quote = <\’>”); System.out.println(“double quote = <\”>”); System.out.println(“null = <\0>”); }

String Constants It is sequence of characters Represent between “” (double quote) Example “Hello World” Hello World “Good Morning.\n Sir.” Good Morning. Sir. “a and \u0061” a and a “I said \”yes\”.” I said “yes”.

Variables type size Default Contains byte 8 bits Signed integer short Signed integer short 16 bits int 32 bits long 64 bits float 0.0 IEEE754 floating point double boolean 1 bits false (true,false) char \u0000 Unicode Character

Identifiers Not allow Allow follow symbol Keywords Blank space Upper Case (‘A’..’Z’) Lower Case (‘a’..’z’) Number (‘0’..’9’) Other symbol ‘$’:dollar-sign ‘_’:underscore

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

Type variables Declaration form <Type> <identifier>[=<value>][,<identifier>[=<value>]…] Example int x; float a,b; double half=0.5;

Type wrapper classes Each primitive data type has a corresponding class in package java.lang public class IntegerConstants { public static void main(String args[]) { System.out.println(Byte.MAX_VALUE); System.out.println(Byte.MIN_VALUE); System.out.println(Short.MAX_VALUE); System.out.println(Short.MIN_VALUE); System.out.println(Integer.MAX_VALUE); System.out.println(Integer.MIN_VALUE); System.out.println(Long.MAX_VALUE); System.out.println(Long.MIN_VALUE); }

Operators Assignment Operators Bitwise Operators Ralational Operators Arithmatic Operators (Integer&Float) Arithmatic Assignment Operators Increment and Decrement Operators Bitwise Operators Ralational Operators Logical Operators

Arithmatic Operators (Integer&Float) Opt Integer Float + 1+2 3 1.0 + 2.0 3.0 - 2 - 3 -1 2.0 – 3.0 -1.0 * 3 * 4 12 3.0 * 4.0 12.0 / 24/5 4 24.0 / 5.0 4.8 % 16%7 16.0 % 7.0

Arithmatic Assignment Operators Form Meaning += x+=y x = x + y -= x-=y x = x – y *= x*=y x = x * y /= x/=y x = x / y %= x%=y x = x % y

Increment and Decrement Operators Increment Operator is ++ Decrement Operator is – x++ and ++x have different in meaning int x = 10; int y; y = ++x; System.out.println(x); System.out.println(y); int x = 10; int y; y = x++; System.out.println(x); System.out.println(y); 11 11 10

Overflow and Underflow public class FloatRange { public static void main(String args[]){ float pMax = Float.MAX_VALUE; float pMin = Float.MIN_VALUE; System.out.println(pMin + “ to ” + pMax); System.out.println(“Overflow ” + pMax*10); System.out.println(“Underflow ” + pMin/10); }

Bitwise Operators & A & B &= A&=B A = A&B | A | B |= A|=B A = A|B ^ ^= A^=B A = A^B >> A >> B >>= A>>=B A = A>>B << A << B <<= A<<=B A = A<<B ~ ~A >>> A >>> B >>>= A>>>=B A = A>>>B

Ralational Operators Result is either “true” or “false” Operator Example Meaning > A > B more than < A < B Less then >= A >= B More than and equal <= A <= B Less than and equal == A == B Equal != A != B Not equal

Logical Operators Boolean Logical Operator & b = false & (++i<10) int i = 0; boolean b; Boolean Logical Operator & b = false & (++i<10) false i = 1 | b = false | (++i<10) true ^ b = false ^ (++i<10) ! b = !(++i<10) Short-circuit logical Operator && b = false && (++i<10) i = 0 || b = true || (++i<10)

Condition Operator If condition is true do expression 1 Conditional Operator (<condition>) ? <expression 1> : <expression 2> If condition is true do expression 1 If condition is false do expression 2 Example System.out.println(x==0?’0’:’1’)

Statement Simple Statement Condition Statement Loop Statement Assignment Condition Statement If Switch Loop Statement While for

Assignment Statement Assignment expression <variable> = <expression> Example X = ( a * a + 4.0 * b ) / 2.0;

Condition Statement If Statement formula if (<boolean expression>) <statements>; [else <statements>;] If (<expression>) <statement1>; <statement2>; If (<expression>) <statement1>; else <statement2>; <statement3>;

Condition Statement Switch Statement formula Switch (<integer expression>){ case <value> : <statements>; . . . . . . . . . . . . . . default: <statements>; }

Loop Statement While statement formula while (<boolean expression>) <statements>; public class LoopWhileFac { public static void main (String args[]) { int n = Integer.parseInt(args[0]); int i = 1, f = 1; while (i++ < n) f *= i; System.out.println(n+”!=”+f); }

Loop Statement Do statement formula do{ (< statements >) }while < boolean expression >; public class LoopDoFac { public static void main (String args[]) { int n = Integer.parseInt(args[0]); int i = 1, f = 1; do { f *= i; }while (i++ < n) System.out.println(n+”!=”+f); }

Loop Statement for statement formula for (<initial exp>;<condition exp>;<update exp>) (< statements >) public class LoopForFac { public static void main (String args[]) { int n = Integer.parseInt(args[0]); int i = 1, f = 1; for (i = 1; f = 1; i <= n; i++) f *= i; System.out.println(n+”!=”+f); }