SlideShare a Scribd company logo
1 of 57
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

Similar to Chapter-introduction about java programming

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Python-unit -I.pptx
Python-unit -I.pptxPython-unit -I.pptx
Python-unit -I.pptxcrAmth
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction Thapar Institute
 
Embedded programming Embedded programming (1).pptx
Embedded programming Embedded programming (1).pptxEmbedded programming Embedded programming (1).pptx
Embedded programming Embedded programming (1).pptxlematadese670
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & LanguagesGaditek
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to CompilersAkhil Kaushik
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1sumitbardhan
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction Sarmad Ali
 
Swift programming language
Swift programming languageSwift programming language
Swift programming languageNijo Job
 
week 2 - INTRO TO PROGRAMMING.pptx
week 2 - INTRO TO PROGRAMMING.pptxweek 2 - INTRO TO PROGRAMMING.pptx
week 2 - INTRO TO PROGRAMMING.pptxnuruddinnnaim
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptxchouguleamruta24
 

Similar to Chapter-introduction about java programming (20)

Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDYC LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
C LANGUAGE UNIT-1 PREPARED BY M V BRAHMANANDA REDDY
 
C languaGE UNIT-1
C languaGE UNIT-1C languaGE UNIT-1
C languaGE UNIT-1
 
Python-unit -I.pptx
Python-unit -I.pptxPython-unit -I.pptx
Python-unit -I.pptx
 
Ic lecture8
Ic lecture8 Ic lecture8
Ic lecture8
 
Compiler Design Introduction
Compiler Design Introduction Compiler Design Introduction
Compiler Design Introduction
 
Chapter1.pdf
Chapter1.pdfChapter1.pdf
Chapter1.pdf
 
Embedded programming Embedded programming (1).pptx
Embedded programming Embedded programming (1).pptxEmbedded programming Embedded programming (1).pptx
Embedded programming Embedded programming (1).pptx
 
E.s unit 6
E.s unit 6E.s unit 6
E.s unit 6
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 
C_Programming_Notes_ICE
C_Programming_Notes_ICEC_Programming_Notes_ICE
C_Programming_Notes_ICE
 
358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1358 33 powerpoint-slides_1-introduction-c_chapter-1
358 33 powerpoint-slides_1-introduction-c_chapter-1
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Swift programming language
Swift programming languageSwift programming language
Swift programming language
 
week 2 - INTRO TO PROGRAMMING.pptx
week 2 - INTRO TO PROGRAMMING.pptxweek 2 - INTRO TO PROGRAMMING.pptx
week 2 - INTRO TO PROGRAMMING.pptx
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptx
 
C programming
C programmingC programming
C programming
 

Recently uploaded

Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 

Recently uploaded (20)

POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 

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

  1. 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.
  2. 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