SlideShare a Scribd company logo
Chapter 7
Java Basics
(Part 1)
Presented by nuzhat memon
Presented by Nuzhat Memon
Introduction to Java
 Java is an object-oriented programming language
developed at Sun Microsystems, a company a best
known for its high-end Unix workstations, in 1991.
 Modeled after c++, the java language was designed to
be small, simple, fast, efficient and portable across
platform and operating systems.
 Java is considered as one of the ideal language for
distributing executable programs via the WWW and also
general purpose programming language for developing
programs that are easily usable and portable across
different platforms.
2
1991
Small
Efficient
fast
Portable
Simple
Bytecode
(Class file)
Windows
JVM
Linux
JVM
MAc
JVM
Presented by Nuzhat Memon
Introduction to Java (continue) | JDK
 JDK is used to develop and run Java program
 Java includes a set of class libraries that provide basic data types, system
input and output capabilities, and other utility functions.
 These Basic classes are part of the Java Development Kit (JDK).
 JDK has classes to support networking, common internet protocols and user
interface toolkit functions.
3
Class libraries
Basic data types,
System input & output capabilities
and other utility functions
Development
tools
JDK (Java Development Kit)
Compiler
Presented by Nuzhat Memon
Java is Platform Indedpendent
 Platform independence is a program’s capability of being moved easily from one
computer system to another.
 Java is platform independent at both the source and the binary level..
 At the source level, java’s primitive data types have consistent sizes across all
development platforms.
 At binary level, platform independence is possible due to bytecode interpreter.
4
Bytecode
(Class file)
Windows
JVM
Linux
JVM
MAc
JVM
Presented by Nuzhat Memon 5
LINUX JVM
Windows JVM
Java Platform Independent
Java
source code
(*.java)
Java
compiler
(javac)
Java
bytecode
(*.class)
JVM - Java
Interpreter
(java)
HelloWorld.java After compilation HelloWorld.class
(class file is our
bytecode)
JVM understand
only bytecode
MAC JVM
Presented by Nuzhat Memon
JVM (Java Virtual Machine) | Bytecode
 Program written in java are compiled into machine language for a computer that
doesn’t really exist. This is so-called “virtual” computer is known as the Java Virtual
Machine (JVM).
 The machine language for the java virtual machine is called java bytecode.
 Different java bytecode interpreter is needed for each type of computer.
 Advantage - Platform independent - Java binary files are actually in a form
called bytecodes that is not specific to any one processor or any operating
system.
 The only disadvantage of using bytecodes is its slow execution speed.
 There are tools available to convert java bytecodes into native code. Native code is
faster to execute, but then it does not remain machine independent.
6
Compiler
Faster Execution Speed
Platform Dependent
Interpreter
Slow Execution Speed
Platform Independent
JVM Java Bytecode
Presented by Nuzhat Memon
Which of the following is missing from compilation process to
execute java application ?
7
JVM - Java Interpreter(Java)
Java Compiler (Javac)
Java Source File (usually have
extension.java)
When we create a Java Program File, we usually save it as
filename.java which is called source code
And then we will Compile our source code using the
java compiler javac
Compiler will translate the whole program into machine
language known as bytecode in java and creates a file
with extension .class
Java Interpreter or JVM will read the bytecode line by
line and Run the class file on different OS or hardware
Java Bytecode file (*.class)
When java program created java source file using text
editor, which file extension should be given? .java
When the program gets compiled without error, compiler
creates a file with which extension ?.class
By using which extension file java interpreter bytecode
executes? java
Which of the following way user can run “abc.java”
source program through the application using java
interpreter? Java abc
To compile the java program we have to type what in
front of source filename? javac filename.java
Presented by Nuzhat Memon
Create Java application using SciTE editor
 Start SciTE application.
 Select File  New and type the java program.
 To save the file, select File Save with filename.java
 Compile source program using Tools Compile (Ctrl+F7)
 If the program is compiled without any error, execute it using
Tools  Go (F5)
8
Presented by Nuzhat Memon
Structure Of A Java Program
+ In Java program, text in angle bracket < and > is used as a place holder.
+ Java consists of function header and the sequence of statements enclosed
between braces { and }
public class <class-name>
{
<optional – variable – declarations – and –methods>
public static void main(String [ ] args)
{
<statements>
}
<optional – variable – declarations – and – methods>
}
Java source file & class name must be same
System.out.print() and System.out.println() both methods are used to display results
9
Presented by Nuzhat Memon
Overview
10
byte age = 10
short number = 20
int count = 30
long area = 1234567
float pi = 3.14
double rate = 100.75
char ch = ‘n’
boolean Check = true
Data Type Variable Literal
Expression
A + B * C
//Comments
Presented by Nuzhat Memon
Data Types
+ Java supports 8 primitive data types.
+ Data Types – byte (1 byte), short (2 bytes), int (4 bytes), long (8 bytes),
float (4 bytes), double (8 bytes), char (2 bytes), Boolean (1 byte)
11
byte, short, int, long Integer Store integer value
float, double Float Store floating point value
Char Character Single Unicode character
boolean Boolean Store true/false logical value
Presented by Nuzhat Memon 12
Data type
numbers character
2 bytes
char c=‘A’
integers
Eg 17,-38488,0
byte
1 byte
short
2 bytes
int
4 bytes
long
8 bytes
long num=4l
real numbers
Eg 5.8 ,-129.35, 3.14
Real numbers in Java are
compliant with IEEE 754
float
4 bytes
float Pi=3.14f
double
8 bytes
double var=0.1234567
boolean
1 byte
boolean b=true
I
n
t
e
g
e
r
byte 1 -128 to 127
short
2
-32768 to
32767
int
4
-2147483648
to 2147483647
long
8
-263 to 263-1
R
e
a
l
float
4
Upto 7
significant
digits
double
8
Upto 15
significant
digits
char 2
16 bit unicode
character
boolean 1
True , false
Default value
is false
(default data type of
floating point literal)
Signed values : -2 b-1-1 to 2 b-1 -2 b-1 to 2 b-1-1
Unsigned values: 0 to 2 b-1 0 to 2 b-1 -1
byte :
-2 8-1 to 2 8-1-1
-2 7 to 2 7-1
-128 to 127
short :
-2 16-1 to 2 16-1-1
-2 15 to 2 15-1
-32768 to 32767
int :
-2 32-1 to 2 32-1-1
-2 31to 2 31-1
-2147483648 to
2147483647
long:
-2 64-1 to 2 64-1-1
-2 63 to 2 63-1
-9223372036854775808
to 9223372036854775807
char :
0 to 2 16-1-1
0 to 215-1
0 to 65535
boolean:
True, false
Presented by Nuzhat Memon
Variable
+ A name used to refer to the data stored in memory is called a variable
+ Syntax <datatype-name> {variable-names};
+ Example int marks; | float rate; | char grade;
RULES TO DEFINE VARIABLE NAME
• It must begin with an alphabet, underscore (_) or dollar sign ($).
• No spaces are allowed in variables : birth date, my school project
• It cannot be a reserved word : class, public, static,void if etc
• Legal variable names : birth_date, result, CallCost, top5students, date, $price
• Illegal variable names : 4me, %discount, birth date
13
Presented by Nuzhat Memon
Guidelines For Naming Variables
+ Choose meaningful variable names. (calculateArea, calculateCallCost)
+ Java allows variable name of any length.
+ Separate words with underscore. Ex : birth_date
+ Java is case-sensitive. So upper case and lower case are considered to
be different. Example variable X is different from the variable x and
a nuzhat is not a Nuzhat or NUZHAT.
+ Names of classes to begin with upper case.
+ Names of variables and of methods begin with lower case. Referred to
as camel case. Ex : birthDate, callCost
14
Presented by Nuzhat Memon
Variable Types
There are 3 kinds of variables :
1) Instance variables
2) Class/Static variables
3) Local variables
15
class Demo{
public static void main(String args[]){
int age=15;
float pi=3.14;
static int count=0;
void display(){
int total=50;
System.out.println(“Hello”);
}
}
}
Instance variables
local variable
Class variable
Presented by Nuzhat Memon
Literals- A name used for a constant value is known as literal. Different
kinds of literals in java for number, character, string and boolean values.
16
Numeric Literals Boolean Literals
True and False
default value is False
Character Literals
16-bit Unicode characters
enclosed in ‘ ‘
Example ‘a’, ‘#’, ‘3’
String Literals
sequence of characters
enclosed in “”
Example “hello”,
Literals
Integer literals
Whole numbers
Real number literal
Floating point literals
standard
12.37
scientific
0.1237 x 102
0.1237e2
Escape character :
n : New Line
t : Tab
f : Form Feed
b : Backspace
r : Carriage return
decimal
Base 10
(0 to 9)
75,75L,-75
octal
Base 8
(0 to 7)
075
hexadecimal
Base 16
(0 to 9, A to F)
0x45 or 0X45
Unicode
integer
literals
u000
ufff
Binary
number
Digits 0 or 1
0b or 0B
Presented by Nuzhat Memon
Comments
Comments in a program are for human readers only
Comments are entirely ignored by the computer. They are not compiled or interpreted
in java
Java supports 3 types of comments :
1) Single line comment //
All the text up to the end of the line is ignored.
2) Multi line comment /* ..... */
Comments cannot be nested (comment inside a comment)
3) Documentation comment /** ..... */
(creating API documentation from the code, javadoc system)
17
Presented by Nuzhat Memon
Expression
+ The basic building blocks of expressions are literals, variables and function calls.
+ More complex expressions can be built up by using operators to combine simpler
expression.
+ Operators include arithmetic operators (+, -, *, /, %), comparison operators (>, <, =,
…), logical operators (and, or, not…)
A + B * C (A + B) * C
18
Presented by Nuzhat Memon
calculate simple and compound interest
class CalculateInterest
{
public static void main(String args[])
{
double p=10000;
double r=4.5;
double n=10;
double si,ci;
si = (p*r*n)/100;
ci= si + p;
System.out.println(“Simple interest is “ + si);
System.out.println(“Compound interest is “ + ci);
}
}
19
1)Save the file as CalculateInterest.java on desktop
2) Open command prompt and type
cd desktop
javac CalculateInterest.java
java CalculateInterest
Presented by Nuzhat Memon
Operators
+ Operators are special symbols used to build an expression.
20
Operators
1.
Arithmetic
Operators
2.
Comparison
operators
3. Logical
Operators
4,
Conditional
operators
5,
Assignment
operator
Presented by Nuzhat Memon 21
Basic arithmetic
operators are +, – ,
* , / , % (Modulus)
All these operators are
binary, they take 2
operands.
Used for byte, short,
int, long, float, double
Arithmetic Operators
Operator Meaning Eg
+ Addition 2+8
– Subtraction 2-8
* Multiplication 2*8
/ Division 8/2
% Reminder 8%3
++ is increment
operator, which
adds 1.
-- is decrement
operator, which
subtracts 1.
Increment/Decrement
Operators
++x
pre-increment
x++
post-increment
--x
pre-decrement
x-- post-decrement
Comparison
operators are
known as
relational
operators.
Comparison Operators
Operator Meaning
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to
Logical operators
known as boolean
operators.
Logical operators :
AND, OR, XOR
(Exclusive OR),
NOT
Operator Sign Use
AND && Used to combine two
values – AND
OR || Used to combine two
values – OR
XOR ^ It returns true only if
operands are different
NOT ! Operant is true, result
is false & vice versa
Also known as ternary
operator.
Conditional operator
uses 3 operands.
It uses two symbols ?
and : in the expression.
Syntax : (boolean-expr)
? (expr1) : (expr2)
To assign a value
to variable by
using the
assignment
operator ‘=’
Syntax:
<variable> =
<expression>;
Conditional
Operator
Operators
Arithmetic
Operator
Increment and
Decrement
Operator
Comparison
Operator
Logical
Operator
Assignment
Operator
Presented by Nuzhat Memon
Looping
Java supports 3 types of looping constructs:
(1) for loop
+ Entry controlled or pre-test loop constructs.
+ for loop are executed if condition is true.
+ It is used when numbers of iterations are pre-defined.
(2) while loop
+ Entry controlled or pre-test loop constructs.
+ Loop are executed if condition is true.
+ It is used when number of iterations are not pre-determined.
(3) do...while loop
+ Exit controlled or post-test loop constructs.
+ It repeats the loop if the test condition is true.
+ Here, statements of loop are executed at least once.
22
Presented by Nuzhat Memon
Statement
(1) IF STATEMENT
+ Used in a program to take one of two alternative coursed of action,
depending upon Boolean valued expression.
(2) SWITCH STATEMENT
+ Used when there are many alternative actions to be taken depending
upon the value of a variable or expression.
+ Test expression should be of the type byte, char, short or int or enum
23
Presented by Nuzhat Memon
Statement
BREAK STATEMENT
+ Used to transfer the control outside switch/loop structure.
+ It is used to exit the loop.
+ It is jumps outside the nearest loop containing this statement.
CONTINUE STATEMENT
+ It is used to skip the following statement in a loop and continue
with the next iteration.
24
Presented by Nuzhat Memon
Thanks!
Any questions?
You can find me at:
+ nuzhatmemon.com
+ Nuzhat.memon@gmail.com
25
Ad

Recommended

Std 12 computer chapter 8 classes and object in java (part 2)
Std 12 computer chapter 8 classes and object in java (part 2)
Nuzhat Memon
 
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
Std 12 Computer Chapter 2 Cascading Style Sheet and Javascript (Part-2)
Nuzhat Memon
 
Std 12 Computer Chapter 3 Designing Simple Website using KompoZer
Std 12 Computer Chapter 3 Designing Simple Website using KompoZer
Nuzhat Memon
 
Std 12 computer chapter 6 object oriented concepts (part 1)
Std 12 computer chapter 6 object oriented concepts (part 1)
Nuzhat Memon
 
Std 12 Computer Chapter 2 Cascading Style Sheets and Javascript(Part 1 CSS)
Std 12 Computer Chapter 2 Cascading Style Sheets and Javascript(Part 1 CSS)
Nuzhat Memon
 
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Std 12 Computer Chapter 1 Creating Html Forms Using KompoZer
Nuzhat Memon
 
Basics of JavaScript
Basics of JavaScript
Bala Narayanan
 
Lab #2: Introduction to Javascript
Lab #2: Introduction to Javascript
Walid Ashraf
 
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 1)
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 1)
Nuzhat Memon
 
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 2)
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 2)
Nuzhat Memon
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Java script
Java script
Abhishek Kesharwani
 
JavaScript
JavaScript
Vidyut Singhania
 
Introduction to vb.net
Introduction to vb.net
Jaya Kumari
 
Datatype in JavaScript
Datatype in JavaScript
Rajat Saxena
 
Visual Basic Controls ppt
Visual Basic Controls ppt
Ranjuma Shubhangi
 
Js ppt
Js ppt
Rakhi Thota
 
Introduction to JAVA
Introduction to JAVA
ParminderKundu
 
Data Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Javascript 101
Javascript 101
Shlomi Komemi
 
Java Programming
Java Programming
Elizabeth alexander
 
Java script
Java script
Shyam Khant
 
Loops in java script
Loops in java script
Ravi Bhadauria
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
JavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Event In JavaScript
Event In JavaScript
ShahDhruv21
 
Introduction to CSS3
Introduction to CSS3
Doris Chen
 
Introduction to java
Introduction to java
Java Lover
 
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
eraqhuzay69
 
Core Java
Core Java
christ university
 

More Related Content

What's hot (20)

Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 1)
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 1)
Nuzhat Memon
 
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 2)
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 2)
Nuzhat Memon
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Java script
Java script
Abhishek Kesharwani
 
JavaScript
JavaScript
Vidyut Singhania
 
Introduction to vb.net
Introduction to vb.net
Jaya Kumari
 
Datatype in JavaScript
Datatype in JavaScript
Rajat Saxena
 
Visual Basic Controls ppt
Visual Basic Controls ppt
Ranjuma Shubhangi
 
Js ppt
Js ppt
Rakhi Thota
 
Introduction to JAVA
Introduction to JAVA
ParminderKundu
 
Data Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Javascript 101
Javascript 101
Shlomi Komemi
 
Java Programming
Java Programming
Elizabeth alexander
 
Java script
Java script
Shyam Khant
 
Loops in java script
Loops in java script
Ravi Bhadauria
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
JavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Event In JavaScript
Event In JavaScript
ShahDhruv21
 
Introduction to CSS3
Introduction to CSS3
Doris Chen
 
Introduction to java
Introduction to java
Java Lover
 
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 1)
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 1)
Nuzhat Memon
 
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 2)
Std 12 Computer Chapter 5 Introduction to Mcommerce (Part 2)
Nuzhat Memon
 
Introduction to vb.net
Introduction to vb.net
Jaya Kumari
 
Datatype in JavaScript
Datatype in JavaScript
Rajat Saxena
 
Data Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
Laurence Svekis ✔
 
JavaScript - An Introduction
JavaScript - An Introduction
Manvendra Singh
 
Event In JavaScript
Event In JavaScript
ShahDhruv21
 
Introduction to CSS3
Introduction to CSS3
Doris Chen
 
Introduction to java
Introduction to java
Java Lover
 

Similar to Std 12 Computer Chapter 7 Java Basics (Part 1) (20)

javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
eraqhuzay69
 
Core Java
Core Java
christ university
 
OOP-Chap2.docx
OOP-Chap2.docx
NaorinHalim
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
Class 8 - Java.pptx
Class 8 - Java.pptx
sreedevi143432
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
sunny khan
 
Unit 1
Unit 1
LOVELY PROFESSIONAL UNIVERSITY
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
 
Full CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java language
ssuser2963071
 
Java (1).ppt seminar topics engineering
Java (1).ppt seminar topics engineering
4MU21CS023
 
Modern_2.pptx for java
Modern_2.pptx for java
MayaTofik
 
basic_java.ppt
basic_java.ppt
sujatha629799
 
Java programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 
Hello Java-First Level
Hello Java-First Level
Dr. Raaid Alubady
 
Hello java
Hello java
University of Babylon
 
Hello java
Hello java
University of Babylon
 
Core java part1
Core java part1
VenkataBolagani
 
Bt0074 oops with java
Bt0074 oops with java
Techglyphs
 
2013 bookmatter learn_javaforandroiddevelopment
2013 bookmatter learn_javaforandroiddevelopment
CarlosPineda729332
 
Introduction to Java Basics Programming Java Basics-I.pptx
Introduction to Java Basics Programming Java Basics-I.pptx
SANDHYAP32
 
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
javaeanjjisjejrehurfhjhjfeauojksfjdi.ppt
eraqhuzay69
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - Description
Ganesh Samarthyam
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
sunny khan
 
Core Java Tutorials by Mahika Tutorials
Core Java Tutorials by Mahika Tutorials
Mahika Tutorials
 
Full CSE 310 Unit 1 PPT.pptx for java language
Full CSE 310 Unit 1 PPT.pptx for java language
ssuser2963071
 
Java (1).ppt seminar topics engineering
Java (1).ppt seminar topics engineering
4MU21CS023
 
Modern_2.pptx for java
Modern_2.pptx for java
MayaTofik
 
Java programing language unit 1 introduction
Java programing language unit 1 introduction
chnrketan
 
Bt0074 oops with java
Bt0074 oops with java
Techglyphs
 
2013 bookmatter learn_javaforandroiddevelopment
2013 bookmatter learn_javaforandroiddevelopment
CarlosPineda729332
 
Introduction to Java Basics Programming Java Basics-I.pptx
Introduction to Java Basics Programming Java Basics-I.pptx
SANDHYAP32
 
Ad

More from Nuzhat Memon (20)

Std 10 chapter 11 data type, expression and operators important MCQs
Std 10 chapter 11 data type, expression and operators important MCQs
Nuzhat Memon
 
Std 10 Chapter 10 Introduction to C Language Important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQs
Nuzhat Memon
 
Std 12 chapter 7 Java Basics Important MCQs
Std 12 chapter 7 Java Basics Important MCQs
Nuzhat Memon
 
Std 12 computer chapter 8 classes and objects in java important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQs
Nuzhat Memon
 
Std 12 Computer Chapter 6 object oriented concept important mcqs
Std 12 Computer Chapter 6 object oriented concept important mcqs
Nuzhat Memon
 
Std 12 computer chapter 6 object oriented concepts (part 2)
Std 12 computer chapter 6 object oriented concepts (part 2)
Nuzhat Memon
 
Std 12 computer java basics part 3 control structure
Std 12 computer java basics part 3 control structure
Nuzhat Memon
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)
Nuzhat Memon
 
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Nuzhat Memon
 
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Nuzhat Memon
 
Std 10 computer chapter 10 introduction to c language (part2)
Std 10 computer chapter 10 introduction to c language (part2)
Nuzhat Memon
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)
Nuzhat Memon
 
Std 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem Solving
Nuzhat Memon
 
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Nuzhat Memon
 
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Nuzhat Memon
 
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers
Std 11 Computer Chapter 4 Introduction to Layers
Nuzhat Memon
 
Std 11 Computer Chapter 3 Creating Animation using Synfig (Part 3) [practica...
Std 11 Computer Chapter 3 Creating Animation using Synfig (Part 3) [practica...
Nuzhat Memon
 
Std 10 chapter 11 data type, expression and operators important MCQs
Std 10 chapter 11 data type, expression and operators important MCQs
Nuzhat Memon
 
Std 10 Chapter 10 Introduction to C Language Important MCQs
Std 10 Chapter 10 Introduction to C Language Important MCQs
Nuzhat Memon
 
Std 12 chapter 7 Java Basics Important MCQs
Std 12 chapter 7 Java Basics Important MCQs
Nuzhat Memon
 
Std 12 computer chapter 8 classes and objects in java important MCQs
Std 12 computer chapter 8 classes and objects in java important MCQs
Nuzhat Memon
 
Std 12 Computer Chapter 6 object oriented concept important mcqs
Std 12 Computer Chapter 6 object oriented concept important mcqs
Nuzhat Memon
 
Std 12 computer chapter 6 object oriented concepts (part 2)
Std 12 computer chapter 6 object oriented concepts (part 2)
Nuzhat Memon
 
Std 12 computer java basics part 3 control structure
Std 12 computer java basics part 3 control structure
Nuzhat Memon
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)
Nuzhat Memon
 
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Std 12 Computer Chapter 13 other useful free tools and services important MCQs
Nuzhat Memon
 
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Std 12 Computer Chapter 9 Working with Array and String in Java important MCQs
Nuzhat Memon
 
Std 10 computer chapter 10 introduction to c language (part2)
Std 10 computer chapter 10 introduction to c language (part2)
Nuzhat Memon
 
Std 10 computer chapter 10 introduction to c language (part1)
Std 10 computer chapter 10 introduction to c language (part1)
Nuzhat Memon
 
Std 10 computer chapter 9 Problems and Problem Solving
Std 10 computer chapter 9 Problems and Problem Solving
Nuzhat Memon
 
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 3: Masking to R...
Nuzhat Memon
 
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Chapter 5 Using Pictures in Synfig (Practical 2: Masking to hide area in synfig)
Nuzhat Memon
 
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Std 11 Computer Chapter 5 Using Pictures in Synfig (Practical 1 Basics Opera...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Std 11 Computer Chapter 4 Introduction to Layers (Part 3 Solving Textual Exe...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Std 11 Computer Chapter 4 Introduction to Layers (Part 2 Practical :Rotation ...
Nuzhat Memon
 
Std 11 Computer Chapter 4 Introduction to Layers
Std 11 Computer Chapter 4 Introduction to Layers
Nuzhat Memon
 
Std 11 Computer Chapter 3 Creating Animation using Synfig (Part 3) [practica...
Std 11 Computer Chapter 3 Creating Animation using Synfig (Part 3) [practica...
Nuzhat Memon
 
Ad

Recently uploaded (20)

INVESTMENT ANALYSIS AND PORTFOLIO MANAGEMENT-1.pptx
INVESTMENT ANALYSIS AND PORTFOLIO MANAGEMENT-1.pptx
Ankush Upadhyay
 
The Impact of Blockchain Technology on India’s Financial Sector
The Impact of Blockchain Technology on India’s Financial Sector
realtaxindia07
 
RENE-ANSOFF-MATRIX-CAPITAL-STRUCTURE.pptx
RENE-ANSOFF-MATRIX-CAPITAL-STRUCTURE.pptx
zeriannebochorno
 
How Abhay Bhutada Foundation Strengthens Cultural Education at Shivsrushti.pdf
How Abhay Bhutada Foundation Strengthens Cultural Education at Shivsrushti.pdf
Swapnil Pednekar
 
Macroeconomic Study of the country - Vietnam.pptx
Macroeconomic Study of the country - Vietnam.pptx
Ankush Upadhyay
 
HUMAN BEHAVIOR cultural intelligence and global leadeership.pptx
HUMAN BEHAVIOR cultural intelligence and global leadeership.pptx
zeriannebochorno
 
Who is required to file form 10B/10BB – Rule 16CC and Rule 17B
Who is required to file form 10B/10BB – Rule 16CC and Rule 17B
imccci
 
原版西班牙维克大学-加泰罗尼亚中央大学毕业证(UVIC毕业证书)如何办理
原版西班牙维克大学-加泰罗尼亚中央大学毕业证(UVIC毕业证书)如何办理
taqyed
 
Business sentiment stabilized in May, but exporters’ anxiety and labor shorta...
Business sentiment stabilized in May, but exporters’ anxiety and labor shorta...
Інститут економічних досліджень та політичних консультацій
 
最新版美国威斯康星大学密尔沃基分校毕业证(UWM毕业证书)原版定制
最新版美国威斯康星大学密尔沃基分校毕业证(UWM毕业证书)原版定制
taqyea
 
Union Budget 2025-26: Consumption boost!
Union Budget 2025-26: Consumption boost!
imccci
 
Issues pertaining to Penalty, Prosecution and Compounding procedures under TD...
Issues pertaining to Penalty, Prosecution and Compounding procedures under TD...
imccci
 
Panel 2 - Panel discussion - Demystifying key critical & practical issues und...
Panel 2 - Panel discussion - Demystifying key critical & practical issues und...
imccci
 
2025 RWA Report: When Crypto Gets Real | CoinGecko
2025 RWA Report: When Crypto Gets Real | CoinGecko
CoinGecko Research
 
RECENT DEVELOPMENT IN TAXATION OF CHARITABLE TRUST
RECENT DEVELOPMENT IN TAXATION OF CHARITABLE TRUST
imccci
 
最新版意大利布雷西亚大学毕业证(BRESCIA毕业证书)原版定制
最新版意大利布雷西亚大学毕业证(BRESCIA毕业证书)原版定制
taqyea
 
STOCK TRADING COURSE BY FINANCEWORLD.IO (PDF)
STOCK TRADING COURSE BY FINANCEWORLD.IO (PDF)
AndrewBorisenko3
 
Principles of Procurment in Nepal for public sector
Principles of Procurment in Nepal for public sector
AnandAdhikari6
 
Shocks and Inequality An Empirical Exploration
Shocks and Inequality An Empirical Exploration
GRAPE
 
Booklet_WCY_2025IMDIMDIMDIMDIMDIMDIMDIMDIMD
Booklet_WCY_2025IMDIMDIMDIMDIMDIMDIMDIMDIMD
中 央社
 
INVESTMENT ANALYSIS AND PORTFOLIO MANAGEMENT-1.pptx
INVESTMENT ANALYSIS AND PORTFOLIO MANAGEMENT-1.pptx
Ankush Upadhyay
 
The Impact of Blockchain Technology on India’s Financial Sector
The Impact of Blockchain Technology on India’s Financial Sector
realtaxindia07
 
RENE-ANSOFF-MATRIX-CAPITAL-STRUCTURE.pptx
RENE-ANSOFF-MATRIX-CAPITAL-STRUCTURE.pptx
zeriannebochorno
 
How Abhay Bhutada Foundation Strengthens Cultural Education at Shivsrushti.pdf
How Abhay Bhutada Foundation Strengthens Cultural Education at Shivsrushti.pdf
Swapnil Pednekar
 
Macroeconomic Study of the country - Vietnam.pptx
Macroeconomic Study of the country - Vietnam.pptx
Ankush Upadhyay
 
HUMAN BEHAVIOR cultural intelligence and global leadeership.pptx
HUMAN BEHAVIOR cultural intelligence and global leadeership.pptx
zeriannebochorno
 
Who is required to file form 10B/10BB – Rule 16CC and Rule 17B
Who is required to file form 10B/10BB – Rule 16CC and Rule 17B
imccci
 
原版西班牙维克大学-加泰罗尼亚中央大学毕业证(UVIC毕业证书)如何办理
原版西班牙维克大学-加泰罗尼亚中央大学毕业证(UVIC毕业证书)如何办理
taqyed
 
最新版美国威斯康星大学密尔沃基分校毕业证(UWM毕业证书)原版定制
最新版美国威斯康星大学密尔沃基分校毕业证(UWM毕业证书)原版定制
taqyea
 
Union Budget 2025-26: Consumption boost!
Union Budget 2025-26: Consumption boost!
imccci
 
Issues pertaining to Penalty, Prosecution and Compounding procedures under TD...
Issues pertaining to Penalty, Prosecution and Compounding procedures under TD...
imccci
 
Panel 2 - Panel discussion - Demystifying key critical & practical issues und...
Panel 2 - Panel discussion - Demystifying key critical & practical issues und...
imccci
 
2025 RWA Report: When Crypto Gets Real | CoinGecko
2025 RWA Report: When Crypto Gets Real | CoinGecko
CoinGecko Research
 
RECENT DEVELOPMENT IN TAXATION OF CHARITABLE TRUST
RECENT DEVELOPMENT IN TAXATION OF CHARITABLE TRUST
imccci
 
最新版意大利布雷西亚大学毕业证(BRESCIA毕业证书)原版定制
最新版意大利布雷西亚大学毕业证(BRESCIA毕业证书)原版定制
taqyea
 
STOCK TRADING COURSE BY FINANCEWORLD.IO (PDF)
STOCK TRADING COURSE BY FINANCEWORLD.IO (PDF)
AndrewBorisenko3
 
Principles of Procurment in Nepal for public sector
Principles of Procurment in Nepal for public sector
AnandAdhikari6
 
Shocks and Inequality An Empirical Exploration
Shocks and Inequality An Empirical Exploration
GRAPE
 
Booklet_WCY_2025IMDIMDIMDIMDIMDIMDIMDIMDIMD
Booklet_WCY_2025IMDIMDIMDIMDIMDIMDIMDIMDIMD
中 央社
 

Std 12 Computer Chapter 7 Java Basics (Part 1)

  • 1. Chapter 7 Java Basics (Part 1) Presented by nuzhat memon
  • 2. Presented by Nuzhat Memon Introduction to Java  Java is an object-oriented programming language developed at Sun Microsystems, a company a best known for its high-end Unix workstations, in 1991.  Modeled after c++, the java language was designed to be small, simple, fast, efficient and portable across platform and operating systems.  Java is considered as one of the ideal language for distributing executable programs via the WWW and also general purpose programming language for developing programs that are easily usable and portable across different platforms. 2 1991 Small Efficient fast Portable Simple Bytecode (Class file) Windows JVM Linux JVM MAc JVM
  • 3. Presented by Nuzhat Memon Introduction to Java (continue) | JDK  JDK is used to develop and run Java program  Java includes a set of class libraries that provide basic data types, system input and output capabilities, and other utility functions.  These Basic classes are part of the Java Development Kit (JDK).  JDK has classes to support networking, common internet protocols and user interface toolkit functions. 3 Class libraries Basic data types, System input & output capabilities and other utility functions Development tools JDK (Java Development Kit) Compiler
  • 4. Presented by Nuzhat Memon Java is Platform Indedpendent  Platform independence is a program’s capability of being moved easily from one computer system to another.  Java is platform independent at both the source and the binary level..  At the source level, java’s primitive data types have consistent sizes across all development platforms.  At binary level, platform independence is possible due to bytecode interpreter. 4 Bytecode (Class file) Windows JVM Linux JVM MAc JVM
  • 5. Presented by Nuzhat Memon 5 LINUX JVM Windows JVM Java Platform Independent Java source code (*.java) Java compiler (javac) Java bytecode (*.class) JVM - Java Interpreter (java) HelloWorld.java After compilation HelloWorld.class (class file is our bytecode) JVM understand only bytecode MAC JVM
  • 6. Presented by Nuzhat Memon JVM (Java Virtual Machine) | Bytecode  Program written in java are compiled into machine language for a computer that doesn’t really exist. This is so-called “virtual” computer is known as the Java Virtual Machine (JVM).  The machine language for the java virtual machine is called java bytecode.  Different java bytecode interpreter is needed for each type of computer.  Advantage - Platform independent - Java binary files are actually in a form called bytecodes that is not specific to any one processor or any operating system.  The only disadvantage of using bytecodes is its slow execution speed.  There are tools available to convert java bytecodes into native code. Native code is faster to execute, but then it does not remain machine independent. 6 Compiler Faster Execution Speed Platform Dependent Interpreter Slow Execution Speed Platform Independent JVM Java Bytecode
  • 7. Presented by Nuzhat Memon Which of the following is missing from compilation process to execute java application ? 7 JVM - Java Interpreter(Java) Java Compiler (Javac) Java Source File (usually have extension.java) When we create a Java Program File, we usually save it as filename.java which is called source code And then we will Compile our source code using the java compiler javac Compiler will translate the whole program into machine language known as bytecode in java and creates a file with extension .class Java Interpreter or JVM will read the bytecode line by line and Run the class file on different OS or hardware Java Bytecode file (*.class) When java program created java source file using text editor, which file extension should be given? .java When the program gets compiled without error, compiler creates a file with which extension ?.class By using which extension file java interpreter bytecode executes? java Which of the following way user can run “abc.java” source program through the application using java interpreter? Java abc To compile the java program we have to type what in front of source filename? javac filename.java
  • 8. Presented by Nuzhat Memon Create Java application using SciTE editor  Start SciTE application.  Select File  New and type the java program.  To save the file, select File Save with filename.java  Compile source program using Tools Compile (Ctrl+F7)  If the program is compiled without any error, execute it using Tools  Go (F5) 8
  • 9. Presented by Nuzhat Memon Structure Of A Java Program + In Java program, text in angle bracket < and > is used as a place holder. + Java consists of function header and the sequence of statements enclosed between braces { and } public class <class-name> { <optional – variable – declarations – and –methods> public static void main(String [ ] args) { <statements> } <optional – variable – declarations – and – methods> } Java source file & class name must be same System.out.print() and System.out.println() both methods are used to display results 9
  • 10. Presented by Nuzhat Memon Overview 10 byte age = 10 short number = 20 int count = 30 long area = 1234567 float pi = 3.14 double rate = 100.75 char ch = ‘n’ boolean Check = true Data Type Variable Literal Expression A + B * C //Comments
  • 11. Presented by Nuzhat Memon Data Types + Java supports 8 primitive data types. + Data Types – byte (1 byte), short (2 bytes), int (4 bytes), long (8 bytes), float (4 bytes), double (8 bytes), char (2 bytes), Boolean (1 byte) 11 byte, short, int, long Integer Store integer value float, double Float Store floating point value Char Character Single Unicode character boolean Boolean Store true/false logical value
  • 12. Presented by Nuzhat Memon 12 Data type numbers character 2 bytes char c=‘A’ integers Eg 17,-38488,0 byte 1 byte short 2 bytes int 4 bytes long 8 bytes long num=4l real numbers Eg 5.8 ,-129.35, 3.14 Real numbers in Java are compliant with IEEE 754 float 4 bytes float Pi=3.14f double 8 bytes double var=0.1234567 boolean 1 byte boolean b=true I n t e g e r byte 1 -128 to 127 short 2 -32768 to 32767 int 4 -2147483648 to 2147483647 long 8 -263 to 263-1 R e a l float 4 Upto 7 significant digits double 8 Upto 15 significant digits char 2 16 bit unicode character boolean 1 True , false Default value is false (default data type of floating point literal) Signed values : -2 b-1-1 to 2 b-1 -2 b-1 to 2 b-1-1 Unsigned values: 0 to 2 b-1 0 to 2 b-1 -1 byte : -2 8-1 to 2 8-1-1 -2 7 to 2 7-1 -128 to 127 short : -2 16-1 to 2 16-1-1 -2 15 to 2 15-1 -32768 to 32767 int : -2 32-1 to 2 32-1-1 -2 31to 2 31-1 -2147483648 to 2147483647 long: -2 64-1 to 2 64-1-1 -2 63 to 2 63-1 -9223372036854775808 to 9223372036854775807 char : 0 to 2 16-1-1 0 to 215-1 0 to 65535 boolean: True, false
  • 13. Presented by Nuzhat Memon Variable + A name used to refer to the data stored in memory is called a variable + Syntax <datatype-name> {variable-names}; + Example int marks; | float rate; | char grade; RULES TO DEFINE VARIABLE NAME • It must begin with an alphabet, underscore (_) or dollar sign ($). • No spaces are allowed in variables : birth date, my school project • It cannot be a reserved word : class, public, static,void if etc • Legal variable names : birth_date, result, CallCost, top5students, date, $price • Illegal variable names : 4me, %discount, birth date 13
  • 14. Presented by Nuzhat Memon Guidelines For Naming Variables + Choose meaningful variable names. (calculateArea, calculateCallCost) + Java allows variable name of any length. + Separate words with underscore. Ex : birth_date + Java is case-sensitive. So upper case and lower case are considered to be different. Example variable X is different from the variable x and a nuzhat is not a Nuzhat or NUZHAT. + Names of classes to begin with upper case. + Names of variables and of methods begin with lower case. Referred to as camel case. Ex : birthDate, callCost 14
  • 15. Presented by Nuzhat Memon Variable Types There are 3 kinds of variables : 1) Instance variables 2) Class/Static variables 3) Local variables 15 class Demo{ public static void main(String args[]){ int age=15; float pi=3.14; static int count=0; void display(){ int total=50; System.out.println(“Hello”); } } } Instance variables local variable Class variable
  • 16. Presented by Nuzhat Memon Literals- A name used for a constant value is known as literal. Different kinds of literals in java for number, character, string and boolean values. 16 Numeric Literals Boolean Literals True and False default value is False Character Literals 16-bit Unicode characters enclosed in ‘ ‘ Example ‘a’, ‘#’, ‘3’ String Literals sequence of characters enclosed in “” Example “hello”, Literals Integer literals Whole numbers Real number literal Floating point literals standard 12.37 scientific 0.1237 x 102 0.1237e2 Escape character : n : New Line t : Tab f : Form Feed b : Backspace r : Carriage return decimal Base 10 (0 to 9) 75,75L,-75 octal Base 8 (0 to 7) 075 hexadecimal Base 16 (0 to 9, A to F) 0x45 or 0X45 Unicode integer literals u000 ufff Binary number Digits 0 or 1 0b or 0B
  • 17. Presented by Nuzhat Memon Comments Comments in a program are for human readers only Comments are entirely ignored by the computer. They are not compiled or interpreted in java Java supports 3 types of comments : 1) Single line comment // All the text up to the end of the line is ignored. 2) Multi line comment /* ..... */ Comments cannot be nested (comment inside a comment) 3) Documentation comment /** ..... */ (creating API documentation from the code, javadoc system) 17
  • 18. Presented by Nuzhat Memon Expression + The basic building blocks of expressions are literals, variables and function calls. + More complex expressions can be built up by using operators to combine simpler expression. + Operators include arithmetic operators (+, -, *, /, %), comparison operators (>, <, =, …), logical operators (and, or, not…) A + B * C (A + B) * C 18
  • 19. Presented by Nuzhat Memon calculate simple and compound interest class CalculateInterest { public static void main(String args[]) { double p=10000; double r=4.5; double n=10; double si,ci; si = (p*r*n)/100; ci= si + p; System.out.println(“Simple interest is “ + si); System.out.println(“Compound interest is “ + ci); } } 19 1)Save the file as CalculateInterest.java on desktop 2) Open command prompt and type cd desktop javac CalculateInterest.java java CalculateInterest
  • 20. Presented by Nuzhat Memon Operators + Operators are special symbols used to build an expression. 20 Operators 1. Arithmetic Operators 2. Comparison operators 3. Logical Operators 4, Conditional operators 5, Assignment operator
  • 21. Presented by Nuzhat Memon 21 Basic arithmetic operators are +, – , * , / , % (Modulus) All these operators are binary, they take 2 operands. Used for byte, short, int, long, float, double Arithmetic Operators Operator Meaning Eg + Addition 2+8 – Subtraction 2-8 * Multiplication 2*8 / Division 8/2 % Reminder 8%3 ++ is increment operator, which adds 1. -- is decrement operator, which subtracts 1. Increment/Decrement Operators ++x pre-increment x++ post-increment --x pre-decrement x-- post-decrement Comparison operators are known as relational operators. Comparison Operators Operator Meaning > Greater than < Less than >= Greater than or equal to <= Less than or equal to == Equal to != Not equal to Logical operators known as boolean operators. Logical operators : AND, OR, XOR (Exclusive OR), NOT Operator Sign Use AND && Used to combine two values – AND OR || Used to combine two values – OR XOR ^ It returns true only if operands are different NOT ! Operant is true, result is false & vice versa Also known as ternary operator. Conditional operator uses 3 operands. It uses two symbols ? and : in the expression. Syntax : (boolean-expr) ? (expr1) : (expr2) To assign a value to variable by using the assignment operator ‘=’ Syntax: <variable> = <expression>; Conditional Operator Operators Arithmetic Operator Increment and Decrement Operator Comparison Operator Logical Operator Assignment Operator
  • 22. Presented by Nuzhat Memon Looping Java supports 3 types of looping constructs: (1) for loop + Entry controlled or pre-test loop constructs. + for loop are executed if condition is true. + It is used when numbers of iterations are pre-defined. (2) while loop + Entry controlled or pre-test loop constructs. + Loop are executed if condition is true. + It is used when number of iterations are not pre-determined. (3) do...while loop + Exit controlled or post-test loop constructs. + It repeats the loop if the test condition is true. + Here, statements of loop are executed at least once. 22
  • 23. Presented by Nuzhat Memon Statement (1) IF STATEMENT + Used in a program to take one of two alternative coursed of action, depending upon Boolean valued expression. (2) SWITCH STATEMENT + Used when there are many alternative actions to be taken depending upon the value of a variable or expression. + Test expression should be of the type byte, char, short or int or enum 23
  • 24. Presented by Nuzhat Memon Statement BREAK STATEMENT + Used to transfer the control outside switch/loop structure. + It is used to exit the loop. + It is jumps outside the nearest loop containing this statement. CONTINUE STATEMENT + It is used to skip the following statement in a loop and continue with the next iteration. 24
  • 25. Presented by Nuzhat Memon Thanks! Any questions? You can find me at: + nuzhatmemon.com + [email protected] 25