SlideShare a Scribd company logo
Unit-1
Introduction to Java and Elementary
Programming
Dr. Rajesh Patel
Department of Computer Engineering, SPCE
Machine Language
• A computer’s native language.
• Differs among different types of computers, is its
machine language—a set of built-in primitive
instructions.
• These instructions are in the form of binary code.
• To give a computer an instruction in its native
language, have to enter the instruction as binary
code.
Contd..
• For example, to add two numbers, you might
have to write an instruction in binary code,
like this:
• 1101101010011010
Assembly Language
• Programming in machine language is a tedious
process.
• Programs written in machine language are very
difficult to read and modify.
• Assembly language was created in the early days of
computing as an alternative to machine languages.
• Assembly language uses a short descriptive word,
known as a mnemonic, to represent each of the
machine-language instructions.
Assembly instruction
High-Level Language
• In the 1950s, a new generation of programming languages
known as high-level languages emerged.
• They are platform independent.
• User can write program in a high-level language and run it in
different types of machines.
• The instructions in a high-level programming language are
called statements.
• for example, is a high-level language statement that
computes the area of a circle with a radius of 5:
area = 5 * 5 * 3.14159;
Languages
High level languages
• A program written in a high-level language is
called a source program or source code.
• Because a computer cannot execute a source
program, a source program must be translated
into machine code for execution.
• The translation can be done using another
programming tool called an interpreter or a
compiler
Interpreter & Compiler
• An interpreter reads one statement from the
source code, translates it to the machine code
or virtual machine code, and then executes it
right away.
• Statements from the source code may be
translated into several machine instructions
Interpreter & Compiler
FIGURE (a) An interpreter translates and executes a program one statement at a
time. (b) A compiler translates the entire source program into a machine-
language file for execution.
(a)
(b)
Java, the World Wide Web, and
Beyond
• Java is a powerful and versatile programming language for
developing software running on mobile devices, desktop
computers, and servers.
• Java was developed by a team led by James Gosling at Sun
Microsystems.
• Sun Microsystems was purchased by Oracle in 2010.
• Originally called Oak, Java was designed in 1991 for use in
embedded chips in consumer electronic appliances.
• In 1995, renamed Java, it was redesigned for developing
Web applications.
Contd..
• Java is a full-featured, general-purpose programming
language that can be used to develop robust mission-
critical applications.
• Today, it is employed not only for Web programming
but also for developing standalone applications
across platforms on servers, desktop computers, and
mobile devices.
Contd..
• It was used to develop the code to communicate
with and control the robotic rover on Mars
• Distributed applications accessed by customers
and partners across the Internet
• For every new project being developed today,
companies are asking how they can use Java to
make their work easier
Java Applets
• Java initially became attractive because Java
programs can be run from a Web browser. Such
programs are called applets.
• Applets employ a modern graphical interface
with buttons, text fields, text areas, radio
buttons, and so on, to interact with users on the
Web and process their requests.
• Applets make the Web responsive, interactive,
and fun to use.
HTML
• Applets are embedded in an HTML file.
• HTML (Hypertext Markup Language) is a
simple scripting language for laying out
documents, linking documents on the
Internet, and bringing images, sound, and
video alive on the Web.
`
Contd..
• Java is now very popular for developing
applications on Web servers.
• These applications process data, perform
computations, and generate dynamic Web
pages.
Java API, JDK, IDE
• Java syntax is defined in the Java language
specification, and the Java library is defined in
the Java API.
• The JDK is the software for developing and
running Java programs.
• An IDE is an integrated development
environment for rapidly developing programs
Java Computing Platform
ď‚§ Java Standard Edition (Java SE) to develop client-side
applications. The applications can run standalone or as
applets running from a Web browser.
ď‚§ Java Enterprise Edition (Java EE) to develop server-side
applications, such as Java servlets, JavaServer Pages
(JSP), and JavaServer Faces (JSF).
ď‚§ Java Micro Edition (Java ME) to develop applications
for mobile devices, such as cell phones.
JDK & Java Development Tools
• The JDK consists of a set of separate programs, each
invoked from a command line, for developing and
testing Java programs.
• Instead of using the JDK, - Java development tool (e.g.,
NetBeans, Eclipse, and TextPad)—software that
provides an integrated development environment (IDE)
for developing Java programs quickly.
• Editing, compiling, building, debugging, and online
help are integrated in one graphical user interface.
A Simple Java Program
Contd..
• Reserved words, or keywords, have a specific meaning to the
compiler and cannot be used for other purposes in the
program.
C
Contd..
Contd..
C
Appropriate Comments and Comment Styles
• Line comments (beginning with //)
• Block comments (beginning with /*),
• Java supports comments of a special type,
referred to as javadoc comments.
• javadoc comments begin with /** and end with
*/.
• They can be extracted into an HTML file using the
JDK’s javadoc command.
Programming Errors
• Programming errors can be categorized into
three types: syntax errors, runtime errors, and
logic errors.
• Syntax errors result from errors in code
construction, such as mistyping a keyword,
omitting some
• Necessary punctuation, or using an opening
brace without a corresponding closing brace
Error
Runtime error
Runtime errors are errors that cause a program to terminate
abnormally. They occur while a program is running if the
environment detects an operation that is impossible to carry
out. Input mistakes typically cause runtime errors.
Logic Errors
• Logic errors occur when a program does not perform
the way it was intended to.
• Errors of this kind occur for many different reasons.
Reading Input from the Console
• Reading input from the console enables the
program to accept input from the user.
• Java uses System.out to refer to the standard
output device.
• System.in to the standard input device.
Read Input
• Console input is not directly supported in Java.
• Scanner class to create an object to read input
from System.in, as follows:
Scanner input = new Scanner(System.in);
double radius = input.nextDouble();
• The Scanner class is in the java.util package
• import java.util.Scanner;
Identifier
• Identifiers are the names that identify the
elements such as classes, methods, and
variables in a program.
Example:
• ComputeAverage, main, input, number1,
number2.
Rules
• An identifier is a sequence of characters that consists of
letters, digits, underscores(_), and dollar signs ($).
• An identifier must start with a letter, an underscore (_),
or a dollar sign ($). It cannot start with a digit.
• An identifier cannot be a reserved word.
• An identifier cannot be true, false, or null.
• An identifier can be of any length.
Variables
• Variables are used to represent values that
may be changed in the program.
int count;
double radius;
double interestRate;
Contd..
int i, j, k;
int count = 1;
This is equivalent to the next two statements:
int count;
count = 1;
int i = 1, j = 2;
C
Named Constants
• A named constant is an identifier that
represents a permanent value.
• The value of a variable may change during
the execution of a program, but a named
constant, or simply constant, represents
permanent data that never changes.
Contd..
final datatype CONSTANTNAME = value;
• A constant must be declared and initialized in
the same statement.
The word final is a Java keyword for declaring
a constant.
final double PI = 3.14159;
Cont
Naming Conventions
• Sticking with the Java naming conventions
makes your programs easy to read and avoids
errors.
Data types
Methods
Numeric Operator
Minutes and Second Program
Numeric Literals
• A literal is a constant value that appears
directly in a program.
• For example, 34 and 0.305 are literals in the
following statements:
• int numberOfYears = 34;
• double weight = 0.305;
Integer Literals
• An integer literal can be assigned to an integer
variable as long as it can fit into the variable.
• A compile error will occur if the literal is too large
for the variable to hold.
The statement byte b = 128,
• for example, will cause a compile error, because
128 cannot be stored in a variable of the byte
type.
Contd..
• An integer literal is assumed to be of the int
type, whose value is between
-231 (-2147483648) and 231 - 1 (2147483647).
C
Floating-Point Literals
• Floating-point literals are written with a
decimal point.
• By default, a floating-point literal is treated as
a double type value.
• For example, 5.0 is considered a double value,
not a float value.
Contd..
• For example, you can use 100.2f or
• 100.2F for a float number,
• 100.2d or 100.2D for a double number.
C
Double & Float
• The double type values are more accurate than
the float type values.
• System.out.println("1.0 / 3.0 is " + 1.0 / 3.0);
• displays 1.0 / 3.0 is 0.3333333333333333
• System.out.println("1.0F / 3.0F is " + 1.0F / 3.0F);
• 1.0F / 3.0F is 0.33333334
Evaluating Expressions and Operator
Precedence
• Java expressions are evaluated in the same
way as arithmetic expressions.
Arithmatic expression
Operator Precedence Rule
ď‚§ Operators within pairs of parentheses are evaluated first.
Parentheses can be nested, in which case the expression in
the inner parentheses is evaluated first. When more than
one operator is used in an expression, the following operator
precedence rule is used to determine the order of evaluation.
ď‚§ Multiplication, division, and remainder operators are
applied first. If an expression contains several multiplication,
division, and remainder operators, they are applied from left
to right.
ď‚§ Addition and subtraction operators are applied last. If an
expression contains several addition and subtraction
operators, they are applied from left to right.
Increment and Decrement Operators
• The increment operator (++) and decrement
operator (– –) are for incrementing and
decrementing a variable by 1.
int i = 3, j = 3;
i++; // i becomes 4
j——; // j becomes 2
Contd..
• int i = 3, j = 3;
• ++i; // i becomes 4
• ——j; // j becomes 2
• double x = 1.0;
• double y = 5.0;
• double z = x–– + (++y);
• After all three lines are executed, y becomes 6.0,
z becomes 7.0, and x becomes 0.0.
Cn
Contd..
Numeric Type Conversion
• Floating-point numbers can be converted into
integers using explicit casting.
System.out.println((int)1.7);
System.out.println((double)1 / 2);
Output : 0.5
Contd..
• System.out.println(1 / 2);
Output : 0
C
Data Type Conversion
Output

More Related Content

PPTX
01-PROGRAMMING introA of the class name. Pptx
simukondasankananji8
 
PDF
X-CS-8.0 Programming in C Language 2022-2023.pdf
Alefya1
 
PPTX
Introduction_to_Programming.pptx
PmarkNorcio
 
PPTX
Unit ii
sathisaran
 
PPTX
C programming
Jigarthacker
 
PPTX
Compilers.pptx
MohammedMohammed578197
 
PPT
C# Fundamental
Thilini munasinghe
 
PPT
Compiler Design Basics
Akhil Kaushik
 
01-PROGRAMMING introA of the class name. Pptx
simukondasankananji8
 
X-CS-8.0 Programming in C Language 2022-2023.pdf
Alefya1
 
Introduction_to_Programming.pptx
PmarkNorcio
 
Unit ii
sathisaran
 
C programming
Jigarthacker
 
Compilers.pptx
MohammedMohammed578197
 
C# Fundamental
Thilini munasinghe
 
Compiler Design Basics
Akhil Kaushik
 

Similar to Chapter-introduction about java programming (20)

PPTX
Fundamental programming Nota Topic 1.pptx
UmmuNazieha
 
PPT
8844632.ppt
SushmaG48
 
PPTX
UNIT - 1jhjhjbkjhkjhkjhkjhkjhhkkhhh.pptx
RoselinLourd
 
PPT
Compiler Design Basics
Akhil Kaushik
 
PPTX
Agro informatics centre up State of Lec 6.pptx
muddydevil2003
 
PPTX
C languaGE UNIT-1
Malikireddy Bramhananda Reddy
 
PPTX
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
PPTX
C language unit-1
Malikireddy Bramhananda Reddy
 
PPTX
Python Programming-Skill Course - unit-i.pptx
KavithaDonepudi
 
PPTX
Python-unit -I.pptx
crAmth
 
PPSX
Ic lecture8
AttaullahRahimoon
 
PPTX
Compiler Design Introduction
Thapar Institute
 
PDF
Chapter1.pdf
tharwatabdulhmed
 
PDF
Module4.pdf ,...................................
chetanreddy2212
 
PPTX
Embedded programming Embedded programming (1).pptx
lematadese670
 
PPT
E.s unit 6
Sneha Chopra
 
PPTX
Programming Paradigm & Languages
Gaditek
 
PPTX
Programming Paradigm & Languages
Gaditek
 
PPTX
JAVA Module 1______________________.pptx
Radhika Venkatesh
 
PPTX
Introduction to Compilers
Akhil Kaushik
 
Fundamental programming Nota Topic 1.pptx
UmmuNazieha
 
8844632.ppt
SushmaG48
 
UNIT - 1jhjhjbkjhkjhkjhkjhkjhhkkhhh.pptx
RoselinLourd
 
Compiler Design Basics
Akhil Kaushik
 
Agro informatics centre up State of Lec 6.pptx
muddydevil2003
 
C languaGE UNIT-1
Malikireddy Bramhananda Reddy
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
C language unit-1
Malikireddy Bramhananda Reddy
 
Python Programming-Skill Course - unit-i.pptx
KavithaDonepudi
 
Python-unit -I.pptx
crAmth
 
Ic lecture8
AttaullahRahimoon
 
Compiler Design Introduction
Thapar Institute
 
Chapter1.pdf
tharwatabdulhmed
 
Module4.pdf ,...................................
chetanreddy2212
 
Embedded programming Embedded programming (1).pptx
lematadese670
 
E.s unit 6
Sneha Chopra
 
Programming Paradigm & Languages
Gaditek
 
Programming Paradigm & Languages
Gaditek
 
JAVA Module 1______________________.pptx
Radhika Venkatesh
 
Introduction to Compilers
Akhil Kaushik
 
Ad

Recently uploaded (20)

PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PPTX
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PDF
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PDF
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
PDF
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
Software Testing Tools - names and explanation
shruti533256
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
Color Model in Textile ( RGB, CMYK).pptx
auladhossain191
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
Inventory management chapter in automation and robotics.
atisht0104
 
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
EVS+PRESENTATIONS EVS+PRESENTATIONS like
saiyedaqib429
 
settlement FOR FOUNDATION ENGINEERS.pdf
Endalkazene
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
Software Testing Tools - names and explanation
shruti533256
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
Ad

Chapter-introduction about java programming

  • 1. Unit-1 Introduction to Java and Elementary Programming Dr. Rajesh Patel Department of Computer Engineering, SPCE
  • 2. Machine Language • A computer’s native language. • Differs among different types of computers, is its machine language—a set of built-in primitive instructions. • These instructions are in the form of binary code. • To give a computer an instruction in its native language, have to enter the instruction as binary code.
  • 3. Contd.. • For example, to add two numbers, you might have to write an instruction in binary code, like this: • 1101101010011010
  • 4. Assembly Language • Programming in machine language is a tedious process. • Programs written in machine language are very difficult to read and modify. • Assembly language was created in the early days of computing as an alternative to machine languages. • Assembly language uses a short descriptive word, known as a mnemonic, to represent each of the machine-language instructions.
  • 6. High-Level Language • In the 1950s, a new generation of programming languages known as high-level languages emerged. • They are platform independent. • User can write program in a high-level language and run it in different types of machines. • The instructions in a high-level programming language are called statements. • for example, is a high-level language statement that computes the area of a circle with a radius of 5: area = 5 * 5 * 3.14159;
  • 8. High level languages • A program written in a high-level language is called a source program or source code. • Because a computer cannot execute a source program, a source program must be translated into machine code for execution. • The translation can be done using another programming tool called an interpreter or a compiler
  • 9. Interpreter & Compiler • An interpreter reads one statement from the source code, translates it to the machine code or virtual machine code, and then executes it right away. • Statements from the source code may be translated into several machine instructions
  • 10. Interpreter & Compiler FIGURE (a) An interpreter translates and executes a program one statement at a time. (b) A compiler translates the entire source program into a machine- language file for execution. (a) (b)
  • 11. Java, the World Wide Web, and Beyond • Java is a powerful and versatile programming language for developing software running on mobile devices, desktop computers, and servers. • Java was developed by a team led by James Gosling at Sun Microsystems. • Sun Microsystems was purchased by Oracle in 2010. • Originally called Oak, Java was designed in 1991 for use in embedded chips in consumer electronic appliances. • In 1995, renamed Java, it was redesigned for developing Web applications.
  • 12. Contd.. • Java is a full-featured, general-purpose programming language that can be used to develop robust mission- critical applications. • Today, it is employed not only for Web programming but also for developing standalone applications across platforms on servers, desktop computers, and mobile devices.
  • 13. Contd.. • It was used to develop the code to communicate with and control the robotic rover on Mars • Distributed applications accessed by customers and partners across the Internet • For every new project being developed today, companies are asking how they can use Java to make their work easier
  • 14. Java Applets • Java initially became attractive because Java programs can be run from a Web browser. Such programs are called applets. • Applets employ a modern graphical interface with buttons, text fields, text areas, radio buttons, and so on, to interact with users on the Web and process their requests. • Applets make the Web responsive, interactive, and fun to use.
  • 15. HTML • Applets are embedded in an HTML file. • HTML (Hypertext Markup Language) is a simple scripting language for laying out documents, linking documents on the Internet, and bringing images, sound, and video alive on the Web. `
  • 16. Contd.. • Java is now very popular for developing applications on Web servers. • These applications process data, perform computations, and generate dynamic Web pages.
  • 17. Java API, JDK, IDE • Java syntax is defined in the Java language specification, and the Java library is defined in the Java API. • The JDK is the software for developing and running Java programs. • An IDE is an integrated development environment for rapidly developing programs
  • 18. Java Computing Platform ď‚§ Java Standard Edition (Java SE) to develop client-side applications. The applications can run standalone or as applets running from a Web browser. ď‚§ Java Enterprise Edition (Java EE) to develop server-side applications, such as Java servlets, JavaServer Pages (JSP), and JavaServer Faces (JSF). ď‚§ Java Micro Edition (Java ME) to develop applications for mobile devices, such as cell phones.
  • 19. JDK & Java Development Tools • The JDK consists of a set of separate programs, each invoked from a command line, for developing and testing Java programs. • Instead of using the JDK, - Java development tool (e.g., NetBeans, Eclipse, and TextPad)—software that provides an integrated development environment (IDE) for developing Java programs quickly. • Editing, compiling, building, debugging, and online help are integrated in one graphical user interface.
  • 20. A Simple Java Program
  • 21. Contd.. • Reserved words, or keywords, have a specific meaning to the compiler and cannot be used for other purposes in the program. C
  • 24. Appropriate Comments and Comment Styles • Line comments (beginning with //) • Block comments (beginning with /*), • Java supports comments of a special type, referred to as javadoc comments. • javadoc comments begin with /** and end with */. • They can be extracted into an HTML file using the JDK’s javadoc command.
  • 25. Programming Errors • Programming errors can be categorized into three types: syntax errors, runtime errors, and logic errors. • Syntax errors result from errors in code construction, such as mistyping a keyword, omitting some • Necessary punctuation, or using an opening brace without a corresponding closing brace
  • 26. Error
  • 27. Runtime error Runtime errors are errors that cause a program to terminate abnormally. They occur while a program is running if the environment detects an operation that is impossible to carry out. Input mistakes typically cause runtime errors.
  • 28. Logic Errors • Logic errors occur when a program does not perform the way it was intended to. • Errors of this kind occur for many different reasons.
  • 29. Reading Input from the Console • Reading input from the console enables the program to accept input from the user. • Java uses System.out to refer to the standard output device. • System.in to the standard input device.
  • 30. Read Input • Console input is not directly supported in Java. • Scanner class to create an object to read input from System.in, as follows: Scanner input = new Scanner(System.in); double radius = input.nextDouble(); • The Scanner class is in the java.util package • import java.util.Scanner;
  • 31. Identifier • Identifiers are the names that identify the elements such as classes, methods, and variables in a program. Example: • ComputeAverage, main, input, number1, number2.
  • 32. Rules • An identifier is a sequence of characters that consists of letters, digits, underscores(_), and dollar signs ($). • An identifier must start with a letter, an underscore (_), or a dollar sign ($). It cannot start with a digit. • An identifier cannot be a reserved word. • An identifier cannot be true, false, or null. • An identifier can be of any length.
  • 33. Variables • Variables are used to represent values that may be changed in the program. int count; double radius; double interestRate;
  • 34. Contd.. int i, j, k; int count = 1; This is equivalent to the next two statements: int count; count = 1; int i = 1, j = 2; C
  • 35. Named Constants • A named constant is an identifier that represents a permanent value. • The value of a variable may change during the execution of a program, but a named constant, or simply constant, represents permanent data that never changes.
  • 36. Contd.. final datatype CONSTANTNAME = value; • A constant must be declared and initialized in the same statement. The word final is a Java keyword for declaring a constant. final double PI = 3.14159; Cont
  • 37. Naming Conventions • Sticking with the Java naming conventions makes your programs easy to read and avoids errors.
  • 42. Numeric Literals • A literal is a constant value that appears directly in a program. • For example, 34 and 0.305 are literals in the following statements: • int numberOfYears = 34; • double weight = 0.305;
  • 43. Integer Literals • An integer literal can be assigned to an integer variable as long as it can fit into the variable. • A compile error will occur if the literal is too large for the variable to hold. The statement byte b = 128, • for example, will cause a compile error, because 128 cannot be stored in a variable of the byte type.
  • 44. Contd.. • An integer literal is assumed to be of the int type, whose value is between -231 (-2147483648) and 231 - 1 (2147483647). C
  • 45. Floating-Point Literals • Floating-point literals are written with a decimal point. • By default, a floating-point literal is treated as a double type value. • For example, 5.0 is considered a double value, not a float value.
  • 46. Contd.. • For example, you can use 100.2f or • 100.2F for a float number, • 100.2d or 100.2D for a double number. C
  • 47. Double & Float • The double type values are more accurate than the float type values. • System.out.println("1.0 / 3.0 is " + 1.0 / 3.0); • displays 1.0 / 3.0 is 0.3333333333333333 • System.out.println("1.0F / 3.0F is " + 1.0F / 3.0F); • 1.0F / 3.0F is 0.33333334
  • 48. Evaluating Expressions and Operator Precedence • Java expressions are evaluated in the same way as arithmetic expressions.
  • 50. Operator Precedence Rule ď‚§ Operators within pairs of parentheses are evaluated first. Parentheses can be nested, in which case the expression in the inner parentheses is evaluated first. When more than one operator is used in an expression, the following operator precedence rule is used to determine the order of evaluation. ď‚§ Multiplication, division, and remainder operators are applied first. If an expression contains several multiplication, division, and remainder operators, they are applied from left to right. ď‚§ Addition and subtraction operators are applied last. If an expression contains several addition and subtraction operators, they are applied from left to right.
  • 51. Increment and Decrement Operators • The increment operator (++) and decrement operator (– –) are for incrementing and decrementing a variable by 1. int i = 3, j = 3; i++; // i becomes 4 j——; // j becomes 2
  • 52. Contd.. • int i = 3, j = 3; • ++i; // i becomes 4 • ——j; // j becomes 2 • double x = 1.0; • double y = 5.0; • double z = x–– + (++y); • After all three lines are executed, y becomes 6.0, z becomes 7.0, and x becomes 0.0. Cn
  • 54. Numeric Type Conversion • Floating-point numbers can be converted into integers using explicit casting. System.out.println((int)1.7); System.out.println((double)1 / 2); Output : 0.5

Editor's Notes

  • #19: avaServer Faces It is a server side component based user interface framework. It is used to develop web applications. It provides a well-defined programming model and consists of rich API and tag libraries. The latest version JSF 2 uses Facelets as its default templating system. It is written in Java. The JSF API provides components (inputText, commandButton etc) and helps to manage their states. It also provides server-side validation, data conversion, defining page navigation, provides extensibility, supports for internationalization, accessibility etc.
  • #21: System – is a final class in java.lang package out – is a static member of System class and is object of PrintStream println()- is a method of PrintStream which prints whatever is passed to it on the standard output or your screen. To print we need to call println() method, but we can't call this method directly, we need object of class to which this method belongs. Solution? There is a readymade object of PrintStream class 'out'. So, we should call it as out.print(). But wait a minute…this object is created