JAVA PROGRAM Variable, Datatype & Operators. In this page, we will learn about the variable and java data types. Variable is a name of memory location.

Slides:



Advertisements
Similar presentations
Lecture 1 Introduction to Java Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Advertisements

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Constants and Data Types Constants Data Types Reading for this class: L&L,
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
1 Data types, operations, and expressions Overview l Primitive Data Types l Variable declaration l Arithmetical Operations l Expressions.
Java Syntax Primitive data types Operators Control statements.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
Intro to CS – Honors I Programming Basics GEORGIOS PORTOKALIDIS
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Chapter 2: Introducing Data Types and Operators.  Know Java’s primitive types  Use literals  Initialize variables  Know the scope rules of variables.
© 2001 by Ashby M. Woolf Revision 3 Using Java Operators The Basic Toolkit Pliers, Screwdriver, Hammer and Drill.
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
The character data type char
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
DAT602 Database Application Development Lecture 5 JAVA Review.
OperatorstMyn1 Operators The sequence in which different operators in an expression are executed is determined by the precedence of the operators. Operators.
Java Tutorial. Object-Oriented Programming Concepts Object –a representation of some item state  fields/members and should be encapsulated behavior 
Java Structure import java_packages; class JavaClass { member variables declarations; void otherMethod( ) { } public static void main(String[]
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
 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.
JAVA (something like C). Object Oriented Programming Process orientated – code acting on data Object oriented – data controls access to code Encapsulation.
Java operatoriai sandbolts/operators.html
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Основы языка. 1.Переменные 2.Операторы 3.Примитивные типы 4.Массивы 5.Выражения 6.Блоки 7.Управление циклами.
1 CS 007: Introduction to Computer Programming Ihsan Ayyub Qazi.
Java Programming Java Basics. Data Types Java has two main categories of data types: –Primitive data types Built in data types Many very similar to C++
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
Vladimir Misic: Characters and Strings1Tuesday, 9:39 AM Characters and Strings.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Java Data Types.
The assignment expressions. The assignment operator in an assignment statement We have seen the assignment statement: Effect: var = expr; Stores the value.
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.
Java Nuts and Bolts Variables and Data Types Operators Expressions Control Flow Statements Arrays and Strings.
Programming in java Lecture-3 (a). Java Data Type TypeDescription byte8 bit signed integer short16 but signed integer int32 bit signed integer long64.
Developed at Sun Microsystems in 1991 James Gosling, initially named “OAK” Formally announced java in 1995 Object oriented and cant write procedural.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Programming Principles Operators and Expressions.
Data Types References:  Data Type:  In computer science and computer programming, a data type or simply type is a.
Quick Summary C++/CLI Basics Data Types Controls Arrays In-class assignments.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
 Array ◦ Single & Multi-dimensional  Java Operators ◦ Assignment ◦ Arithmetic ◦ Relational ◦ Logical ◦ Bitwise & other.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Java Programming Language Lecture27- An Introduction.
Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Lecture 2: Data Types, Variables, Operators, and Expressions
Multiple variables can be created in one declaration
مفاهیم اولیه زبان جاوا Java Basic Concepts
Operators and Expressions
Escape Sequences What if we wanted to print the quote character?
Starting JavaProgramming
Introduction to Programming
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Java Tokens & Data types
Chapter 2: Java Fundamentals
Java Basics Data Types in Java.
Names of variables, functions, classes
Presentation transcript:

JAVA PROGRAM Variable, Datatype & Operators

In this page, we will learn about the variable and java data types. Variable is a name of memory location. There are three types of variables: local, instance and static. There are two types of datatypes in java, primitive and non-primitive.

Variable Variable is name of reserved area allocated in memory. int data=50;//Here data is variable

Types of Variable There are three types of variables in java – local variable – instance variable – static variable

Local Variable:A variable that is declared inside the method is called local variable. Instance Variable:A variable that is declared inside the class but outside the method is called instance variable. It is not declared as static. Static variable:A variable that is declared as static is called static variable. It cannot be local.

Example to understand the types of variables class A{ int data=50;//instance variable static int m=100;//static variable void method(){ int n=90;//local variable } }//end of class

Data Types in Java In java, there are two types of data types primitive data types non-primitive data types

Data Types in Java

Data TypeDefault ValueDefault size booleanfalse1 bit char'\u0000'2 byte byte01 byte short02 byte int04 byte long0L8 byte float0.0f4 byte double0.0d8 byte

Why char uses 2 byte in java and what is \u0000 ? because java uses unicode system rather than ASCII code system. \u0000 is the lowest range of unicode system.To get detail about Unicode see below.

Unicode System Before Unicode, there were many language standards: ASCII (American Standard Code for Information Interchange) for the United States. ISO for Western European Language. KOI-8 for Russian. GB18030 and BIG-5 for chinese, and so on.

This caused two problems: 1.A particular code value corresponds to different letters in the various language standards. 2.The encodings for languages with large character sets have variable length.Some common characters are encoded as single bytes, other require two or more byte. To solve these problems, a new language standard was developed i.e. Unicode System. In unicode, character holds 2 byte, so java also uses 2 byte for characters. lowest value:\u0000 highest value:\uFFFF

Operators in java Operator is a special symbol that is used to perform operations. There are many types of operators in java such as unary operator, arithmetic operator, relational operator, shift operator, bitwise operator, ternary operator and assignment operator.

OperatorsPrecedence postfixexpr++ expr-- unary++expr --expr +expr -expr ~ ! multiplicative* / % additive+ - shift > >>> relational = instanceof equality== !=

bitwise AND& bitwise exclusive OR^ bitwise inclusive OR| logical AND&& logical OR|| ternary? : assignment= += -= *= /= %= &= ^= |= >= >>>=

Useful Programs: There is given some useful programs such as factorial number, prime number, fibonacci series etc

1) Program of factorial number. class Operation{ static int fact(int number){ int f=1; for(int i=1;i<=number;i++) { f=f*i; } return f; } public static void main(String args[]){ int result=fact(5); System.out.println("Factorial of 5="+result); } }

2) Program of fibonacci series. class Fabnoci{ public static void main(String...args) { int n=10,i,f0=1,f1=1,f2=0; for(i=1;i<=n;i++) { f2=f0+f1; f0=f1; f1=f2; f2=f0; System.out.println(f2); } } }

3) Program of armstrong number. class ArmStrong{ public static void main(String...args) { int n=153,c=0,a,d; d=n; while(n>0) { a=n%10; n=n/10; c=c+(a*a*a); } if(d==c) System.out.println("armstrong number"); else System.out.println("it is not an armstrong number"); } }

4) Program of checking palindrome number class Palindrome { public static void main( String...args) { int a=242; int n=a,b=a,rev=0; while(n>0) { a=n%10; rev=rev*10+a; n=n/10; } if(rev==b) System.out.println("it is Palindrome"); else System.out.println("it is not palinedrome"); } }

5) Program of swapping two numbers without using third variable. class SwapTwoNumbers{ public static void main(String args[]){ int a=40,b=5; a=a*b; b=a/b; a=a/b; System.out.println("a= "+a); System.out.println("b= "+b); } }

6) Program of factorial number by recursion class FactRecursion{ static int fact(int n){ if(n==1) return 1; return n*=fact(n-1); } public static void main(String args[]){ int f=fact(5); System.out.println(f); } }