SlideShare a Scribd company logo
Some Java Fundamentals
Chapter 2
Chapter Contents
Chapter Objectives
2.1 Example: A Payroll Program
2.2 Types, Variables, and Constants
Part of the Picture: Data Representation
2.3 Some Basic Program Features
2.4 Java Documentation
2.5 Introduction to GUIs: A GUI Greeter
Chapter Objectives
 Observe Java primitive types and their
literals
 Explain Java syntax rules
 Contrast primitive types and reference
types
 Study variables and constants
 Investigate internal representation of
primitive types
Chapter Objectives
 Observe the structure and declaration
of classes
 Discover need for import statements
 Note how to use methods
 Study Java API organization
 Look at designing and building simple
GUI applications
2.1 Example: A Payroll
Program
 Computerize the calculation of employee
wages.
 Employees are paid a fixed hourly rate
 They can work any number of hours
 No overtime is paid
 Use object-oriented design
 Describe behavior
 Identify objects
 Identify operations
 Organize objects & operations in an algorithm
Behavior
 Display on the screen a prompt for …
 hours worked
 hourly rate
 Enter values via keyboard
 Compute wages
 Display calculations with descriptive
label
Objects
Description of Object Type Kind Name
the program ?? ?? ??
screen
Screen
variable
theScreen
prompt for hrs & rate
String
constant none
number hrs worked
double
variable
hoursWorked
hourly pay rate
double
variable
hourlyRate
keyboard
Keyboard
variable
theKeyboard
wages variable
Operations
 Display strings (prompts) on screen
 Read numbers for hours and rate
(restrict to non negatives)
 Compute wages
 Display real value (wages) and a string
on screen
Algorithm
1. Construct theScreen and theKeyboard
objects
2. Ask theScreen to display prompt for hours
3. Ask theKeyboard to read value and store in
hoursWorked
4. Ask theScreen to display prompt for rate
5. Ask theKeyboard to read value and store in
hourlyRate
6. Compute wages = hoursWorked x
hourlyRate
7. Ask theScreen to display wages and
descriptive label
Coding, Testing, Maintenance
 Note Figure 2.1
 Code
 Sample runs
 Maintenance
 Enhance to include overtime wages
 Display output using $999.99 style format
 Note revision Figure 2.2
2.2 Types, Variables, and
Constants
 Types of objects must be declared
before they are used
 Declaration of variables requires a
certain syntax
 In declaration, the name of a variable is
associated with a type
Types
 void
 denotes the absence of any type
 String [ ]
 in general, a sequence of characters
 Keyboard, Screen
 associated to the Input and Output (I/O) devices
normally used
 double
 associated with real (numbers with fractions)
values
Primitive Types
 byte, short, int, and long
 for integer values of various sizes
 float and double
 for real (rational) values of differing accuracy
 boolean
 for logical (true/false) values
 char
 for individual characters
Reference Types
 Built of other types
 Example: String, Screen, Keyboard
 Also considered “class types”
 Reference types
 begin with uppercase letter
 not known to Java compiler, must be explained
 Contrast primitive types
 begin with lower case letter
 are known to Java compiler
Literals – Examples
 Integers
 4, 19, -5, 0, 1000
 Doubles
 3.14, 0.0, -16.123
 Strings
 “Hi Mom” “Enter the number : “
 Character
 'A' 'X' '9' '$' 'n'
 Boolean
 true, false
Identifiers
 Names given to variables, objects, methods
 Must not be a Java keyword
 See Appendix B for list of keywords
 May begin with a letter or the underline
character _
 Followed by any number of characters, digits,
or _ (note, no blanks)
 Identifiers should be well chosen
 use complete words (even phrases)
 this helps program documentation
Conventions for Identifiers
 Classes
 Names given in lowercase except for first letter of
each word in the name
 Variables
 Same as classes, except first letter is lowercase
 Constants
 All caps with _ between words
 Methods
 like variable names but followed by parentheses
Declaration Statements
 Purpose is to provide compiler with meaning
of an identifier
 Accomplished in declaration statement
 Some declarations (classes and methods)
are provided and must be imported
import ann.easyio.*;
 Variables to store values must be declared
 they can be initialized at time of declaration
 initialized with a literal or even with keyboard input
 if not explicitly initialized, the default initial value is
zero
Values Held by Variables
 Primitive-type variables
 store a value of the specified type (int,
double)
 Reference-type variables
 store an address of memory location where
value is stored
 thought of as a handle for the object that
actually stores the values
Variable Declaration Syntax
 Syntax:
type variable_name;
or
type variable_name = expression;
 Note
 type must be known to the compiler
 variable_name must be a valid identifier
 expression is evaluated and assigned to
variable_name location
 In the first form, a default value is given (0, false,
or null, depending on type)
Constants
 Value of object cannot be changed
 for oft used math values such as PI
 for values which will not change for a given
program
 improve readability of program
 facilitate program maintenance
 Declaration syntax:
final type CONSTANT_NAME = expression;
 final is a Java keyword, makes a constant
 type must be known by compiler
 CONSTANT_NAME must be valid identifier
 expression evaluated
 should be placed at beginning of class or method
Part of the Picture: Data
Representation
How literals of the primitive types
are represented and stored in
memory.
Representing Integers
 Binary digits used to represent base 10
numbers
58 ten = 111010two
 The 1s and 0s are stored as binary digits in
specified number of bits (32 shown in text)
 Negative numbers often stored in "two's
complement" representation
 All opposite values, switch 1s for 0s and 0s for 1s
 Leading bit specifies the sign (0 for +, 1 for -)
 If a number is too large for the number of bits
allocated, the condition is overflow
Representing Reals
 Consider 22.625ten = 10110.101two
= 1.0110101two x 24
 The 1.0110101 is stored as the "mantissa"
 The 4 is stored as the exponent or "characteristic"
 IEEE format
 Leftmost bit is sign for mantissa
 8 bits for exponent
 Rightmost 23 bits store mantissa
 Problems include
 Overflow – number too large for exponent
 Underflow – number too small for exponent
 Roundoff error – conversion between decimal &
binary
Representing Characters
 A numeric code is assigned to each
symbol to be represented
 ASCII uses 8 bits
 Very common for programming languages
 Limited to 128 characters
 Unicode uses 16 bits
 newer, used by Java
 Allows 65,536 different symbols
Representing Booleans
 Only two possible values
 true and false
 Only need two possible numbers,
0 and 1
 Single bit is all that is needed
2.3 Some Basic Program
Features
 Comments and documentation
 Classes
 Importing packages
 Using Methods
Comments and Opening
Documentation
 Opening documentation should include:
 description of what program does
 input needed, resulting output
 special techniques, algorithms used
 instructions for use of program
 Name of programmer, date, modification history
 Opening documentation is multiline
 between /* */ character pairs
 Inline comments
 following // double slashes
 Comments ignored by compiler
Classes
 Classes built for real world objects that
cannot be represented using available types
 A class is an "extension" of Java
 Definition of class: "a group or category of
things that have a set of attributes in
common."
 In programming: a pattern, blueprint, or
template for modeling real world objects
which have similar attributes
Class Declaration
 Syntax:
class className extends existingClassName
{
// Attributes (variables & constants)
// and behaviors (methods)
}
 Where
 className is the name of a new reference type
 existingClassName is any class name known to
the compiler
 { and } mark the boundaries of the declaration
Purpose of Class Declaration
 Creates a new type that the compiler can use to
create objects
 This new type inherits all attributes and
behaviors of existingClassName
 Note:
 Object is often used for existingClassName
 in this case the extends object may be omitted
Importing Packages
 Related classes grouped together into a
container called a "package"
 program specifies where to find a desired class
 Fully-qualified name
package_name1.ClassName or
package_name1.package_name2.ClassName
 By using the import package_name1 the prefixes
using the dot notation can be omitted
 Syntax
import package_name.* ; or
import package_name.ClassName;
 where ClassName is any class stored with
package_name
Using Methods
 Call, invoke, or send a message to the
method of an existing object
theScreen.print(" … ");
theScreen is the object
print ( ) is the method being called
 Syntax of the call
name of the object
the dot .
the name of the method
any required parameters
or arguments
Value Returning Methods
 Some methods return a value
 Programmer must also do something with
the value to be returned
 assign the value to a variable
variable_name = objectName.methodName(arguments);
 send the value to another method as the
parameter
2.4 Java Documentation – API
 Note the sample programs so far …
 For several tasks, we found a Java method to
solve it
 Other times the programmer writes the class and
methods required
 Java designers have provided over 1600
classes
 Called the Java Application Programmer's
Interface or API
 Each class provides variety of useful methods
 Classes grouped into packages
API Documentation
 Finding needed package or class
 Hypertext-based documentation
system, accessible on World Wide Web
 First page of web site has 3 frames
 Alphabetical list of packages
 Alphabetical list of classes
 A "main" frame that initially lists the Java
packages
Web Based Documentation
 Clicking on the name of the package in the
"main" frame produces a list of the classes in
that package
 Click on name of a class displays information
about that class
 List of fields (variables, constants)
 List of methods for the class
 Click on a method for a detailed description of
the methods
This is an important reference source and
you should learn to use it effectively
2.5 Introduction to GUIs:
A GUI Greeter
 Problem Scenario
Write a program with graphical user interface
that
 displays a window with prompt for name
 box to enter name
 OK and Cancel buttons
 User enters name, clicks OK
 Second window gives greeting, uses name,
displays a button for terminating program
Objects
Description of
Problem's Objects
Type Kind Name
the program GUIGreeter
window for prompt
input-
dialog
prompt for user's name String constant
window to display message
Operations
 Display a window containing a prompt
and a text box
 Read a String from the window's text
box
 Hide the window
 Display second window with
personalized greeting
 Terminate program
Coding in Java
 Note source code in Figure 2.3
Application GUIGreeter
 Note run of program
 Window for prompt and input
 Window for Greeting
 Note improved version, Figure 2.4
Input Dialog
 Input dialogs are GUI widgets
 used to get text input from user
 Example
showInputDialog(prompt);
 prompt can be
 a string
 a graphic image
 another Java Object
Message Dialog
 A GUI widget for displaying information
 Example
showMessageDialog(null, message, title, messageKind);
 Message kind
 can be: error, information, warning, question,
or plain
 used by interface manager to display proper
icon
Ad

More Related Content

What's hot (20)

Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
arnold 7490
 
Java platform
Java platformJava platform
Java platform
BG Java EE Course
 
Chapter 2 c#
Chapter 2 c#Chapter 2 c#
Chapter 2 c#
megersaoljira
 
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)
Nuzhat Memon
 
Oops
OopsOops
Oops
Gayathri Ganesh
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part III
Ajit Nayak
 
Learn Java Part 2
Learn Java Part 2Learn Java Part 2
Learn Java Part 2
Gurpreet singh
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
Salahaddin University-Erbil
 
C0 review core java1
C0 review core java1C0 review core java1
C0 review core java1
tam53pm1
 
Application package
Application packageApplication package
Application package
JAYAARC
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
Ahmad Idrees
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
Raghu nath
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
M Hussnain Ali
 
Md03 - part3
Md03 - part3Md03 - part3
Md03 - part3
Rakesh Madugula
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
J. C.
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1
İbrahim Kürce
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
sajjad ali khan
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentals
megharajk
 
Java Notes
Java NotesJava Notes
Java Notes
Abhishek Khune
 
Introduction of C# BY Adarsh Singh
Introduction of C# BY Adarsh SinghIntroduction of C# BY Adarsh Singh
Introduction of C# BY Adarsh Singh
singhadarsh
 
Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)Std 12 Computer Chapter 7 Java Basics (Part 1)
Std 12 Computer Chapter 7 Java Basics (Part 1)
Nuzhat Memon
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part III
Ajit Nayak
 
C0 review core java1
C0 review core java1C0 review core java1
C0 review core java1
tam53pm1
 
Application package
Application packageApplication package
Application package
JAYAARC
 
Basic elements of java
Basic elements of java Basic elements of java
Basic elements of java
Ahmad Idrees
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
Raghu nath
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
M Hussnain Ali
 
Chapter1pp
Chapter1ppChapter1pp
Chapter1pp
J. C.
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1
İbrahim Kürce
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
sajjad ali khan
 
Java se 8 fundamentals
Java se 8 fundamentalsJava se 8 fundamentals
Java se 8 fundamentals
megharajk
 
Introduction of C# BY Adarsh Singh
Introduction of C# BY Adarsh SinghIntroduction of C# BY Adarsh Singh
Introduction of C# BY Adarsh Singh
singhadarsh
 

Similar to presentation of java fundamental (20)

Notes(1).pptx
Notes(1).pptxNotes(1).pptx
Notes(1).pptx
InfinityWorld3
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptx
SaqlainYaqub1
 
Java_Identifiers_keywords_data_types.ppt
Java_Identifiers_keywords_data_types.pptJava_Identifiers_keywords_data_types.ppt
Java_Identifiers_keywords_data_types.ppt
JyothiAmpally
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
Ali Raza Jilani
 
program fundamentals using python1 2 3 4.pptx
program fundamentals using python1 2 3 4.pptxprogram fundamentals using python1 2 3 4.pptx
program fundamentals using python1 2 3 4.pptx
ibrahimsoryjalloh91
 
Structured Languages
Structured LanguagesStructured Languages
Structured Languages
Mufaddal Nullwala
 
programming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptxprogramming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptx
BamaSivasubramanianP
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming concept
sandeshjadhav28
 
Lecture02 java
Lecture02 javaLecture02 java
Lecture02 java
jawidAhmadRohani
 
Introduction to C#
Introduction to C#Introduction to C#
Introduction to C#
Raghuveer Guthikonda
 
c & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptxc & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptx
rawatsatish0327
 
Introduction to-programming
Introduction to-programmingIntroduction to-programming
Introduction to-programming
BG Java EE Course
 
comp 122 Chapter 2.pptx,language semantics
comp 122 Chapter 2.pptx,language semanticscomp 122 Chapter 2.pptx,language semantics
comp 122 Chapter 2.pptx,language semantics
floraaluoch3
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
dplunkett
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
dplunkett
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
abdulhalimnapiah
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
Jayfee Ramos
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdf
AbrehamKassa
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java
MayaTofik
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptx
SaqlainYaqub1
 
Java_Identifiers_keywords_data_types.ppt
Java_Identifiers_keywords_data_types.pptJava_Identifiers_keywords_data_types.ppt
Java_Identifiers_keywords_data_types.ppt
JyothiAmpally
 
C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1C++ Basics introduction to typecasting Webinar Slides 1
C++ Basics introduction to typecasting Webinar Slides 1
Ali Raza Jilani
 
program fundamentals using python1 2 3 4.pptx
program fundamentals using python1 2 3 4.pptxprogram fundamentals using python1 2 3 4.pptx
program fundamentals using python1 2 3 4.pptx
ibrahimsoryjalloh91
 
programming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptxprogramming for problem solving in C and C++.pptx
programming for problem solving in C and C++.pptx
BamaSivasubramanianP
 
Dot net programming concept
Dot net  programming conceptDot net  programming concept
Dot net programming concept
sandeshjadhav28
 
c & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptxc & c++ logic building concepts practice.pptx
c & c++ logic building concepts practice.pptx
rawatsatish0327
 
comp 122 Chapter 2.pptx,language semantics
comp 122 Chapter 2.pptx,language semanticscomp 122 Chapter 2.pptx,language semantics
comp 122 Chapter 2.pptx,language semantics
floraaluoch3
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
dplunkett
 
Ap Power Point Chpt2
Ap Power Point Chpt2Ap Power Point Chpt2
Ap Power Point Chpt2
dplunkett
 
04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx04. WORKING WITH FUNCTIONS-2 (1).pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
Manas40552
 
Introduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdfIntroduction to Programming Fundamentals 3.pdf
Introduction to Programming Fundamentals 3.pdf
AbrehamKassa
 
Modern_2.pptx for java
Modern_2.pptx for java Modern_2.pptx for java
Modern_2.pptx for java
MayaTofik
 
Ad

Recently uploaded (20)

Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
Resistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff modelResistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff model
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdffive-year-soluhhhhhhhhhhhhhhhhhtions.pdf
five-year-soluhhhhhhhhhhhhhhhhhtions.pdf
AdityaSharma944496
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Smart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineeringSmart Storage Solutions.pptx for production engineering
Smart Storage Solutions.pptx for production engineering
rushikeshnavghare94
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
DATA-DRIVEN SHOULDER INVERSE KINEMATICS YoungBeom Kim1 , Byung-Ha Park1 , Kwa...
charlesdick1345
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
Ad

presentation of java fundamental

  • 2. Chapter Contents Chapter Objectives 2.1 Example: A Payroll Program 2.2 Types, Variables, and Constants Part of the Picture: Data Representation 2.3 Some Basic Program Features 2.4 Java Documentation 2.5 Introduction to GUIs: A GUI Greeter
  • 3. Chapter Objectives  Observe Java primitive types and their literals  Explain Java syntax rules  Contrast primitive types and reference types  Study variables and constants  Investigate internal representation of primitive types
  • 4. Chapter Objectives  Observe the structure and declaration of classes  Discover need for import statements  Note how to use methods  Study Java API organization  Look at designing and building simple GUI applications
  • 5. 2.1 Example: A Payroll Program  Computerize the calculation of employee wages.  Employees are paid a fixed hourly rate  They can work any number of hours  No overtime is paid  Use object-oriented design  Describe behavior  Identify objects  Identify operations  Organize objects & operations in an algorithm
  • 6. Behavior  Display on the screen a prompt for …  hours worked  hourly rate  Enter values via keyboard  Compute wages  Display calculations with descriptive label
  • 7. Objects Description of Object Type Kind Name the program ?? ?? ?? screen Screen variable theScreen prompt for hrs & rate String constant none number hrs worked double variable hoursWorked hourly pay rate double variable hourlyRate keyboard Keyboard variable theKeyboard wages variable
  • 8. Operations  Display strings (prompts) on screen  Read numbers for hours and rate (restrict to non negatives)  Compute wages  Display real value (wages) and a string on screen
  • 9. Algorithm 1. Construct theScreen and theKeyboard objects 2. Ask theScreen to display prompt for hours 3. Ask theKeyboard to read value and store in hoursWorked 4. Ask theScreen to display prompt for rate 5. Ask theKeyboard to read value and store in hourlyRate 6. Compute wages = hoursWorked x hourlyRate 7. Ask theScreen to display wages and descriptive label
  • 10. Coding, Testing, Maintenance  Note Figure 2.1  Code  Sample runs  Maintenance  Enhance to include overtime wages  Display output using $999.99 style format  Note revision Figure 2.2
  • 11. 2.2 Types, Variables, and Constants  Types of objects must be declared before they are used  Declaration of variables requires a certain syntax  In declaration, the name of a variable is associated with a type
  • 12. Types  void  denotes the absence of any type  String [ ]  in general, a sequence of characters  Keyboard, Screen  associated to the Input and Output (I/O) devices normally used  double  associated with real (numbers with fractions) values
  • 13. Primitive Types  byte, short, int, and long  for integer values of various sizes  float and double  for real (rational) values of differing accuracy  boolean  for logical (true/false) values  char  for individual characters
  • 14. Reference Types  Built of other types  Example: String, Screen, Keyboard  Also considered “class types”  Reference types  begin with uppercase letter  not known to Java compiler, must be explained  Contrast primitive types  begin with lower case letter  are known to Java compiler
  • 15. Literals – Examples  Integers  4, 19, -5, 0, 1000  Doubles  3.14, 0.0, -16.123  Strings  “Hi Mom” “Enter the number : “  Character  'A' 'X' '9' '$' 'n'  Boolean  true, false
  • 16. Identifiers  Names given to variables, objects, methods  Must not be a Java keyword  See Appendix B for list of keywords  May begin with a letter or the underline character _  Followed by any number of characters, digits, or _ (note, no blanks)  Identifiers should be well chosen  use complete words (even phrases)  this helps program documentation
  • 17. Conventions for Identifiers  Classes  Names given in lowercase except for first letter of each word in the name  Variables  Same as classes, except first letter is lowercase  Constants  All caps with _ between words  Methods  like variable names but followed by parentheses
  • 18. Declaration Statements  Purpose is to provide compiler with meaning of an identifier  Accomplished in declaration statement  Some declarations (classes and methods) are provided and must be imported import ann.easyio.*;  Variables to store values must be declared  they can be initialized at time of declaration  initialized with a literal or even with keyboard input  if not explicitly initialized, the default initial value is zero
  • 19. Values Held by Variables  Primitive-type variables  store a value of the specified type (int, double)  Reference-type variables  store an address of memory location where value is stored  thought of as a handle for the object that actually stores the values
  • 20. Variable Declaration Syntax  Syntax: type variable_name; or type variable_name = expression;  Note  type must be known to the compiler  variable_name must be a valid identifier  expression is evaluated and assigned to variable_name location  In the first form, a default value is given (0, false, or null, depending on type)
  • 21. Constants  Value of object cannot be changed  for oft used math values such as PI  for values which will not change for a given program  improve readability of program  facilitate program maintenance  Declaration syntax: final type CONSTANT_NAME = expression;  final is a Java keyword, makes a constant  type must be known by compiler  CONSTANT_NAME must be valid identifier  expression evaluated  should be placed at beginning of class or method
  • 22. Part of the Picture: Data Representation How literals of the primitive types are represented and stored in memory.
  • 23. Representing Integers  Binary digits used to represent base 10 numbers 58 ten = 111010two  The 1s and 0s are stored as binary digits in specified number of bits (32 shown in text)  Negative numbers often stored in "two's complement" representation  All opposite values, switch 1s for 0s and 0s for 1s  Leading bit specifies the sign (0 for +, 1 for -)  If a number is too large for the number of bits allocated, the condition is overflow
  • 24. Representing Reals  Consider 22.625ten = 10110.101two = 1.0110101two x 24  The 1.0110101 is stored as the "mantissa"  The 4 is stored as the exponent or "characteristic"  IEEE format  Leftmost bit is sign for mantissa  8 bits for exponent  Rightmost 23 bits store mantissa  Problems include  Overflow – number too large for exponent  Underflow – number too small for exponent  Roundoff error – conversion between decimal & binary
  • 25. Representing Characters  A numeric code is assigned to each symbol to be represented  ASCII uses 8 bits  Very common for programming languages  Limited to 128 characters  Unicode uses 16 bits  newer, used by Java  Allows 65,536 different symbols
  • 26. Representing Booleans  Only two possible values  true and false  Only need two possible numbers, 0 and 1  Single bit is all that is needed
  • 27. 2.3 Some Basic Program Features  Comments and documentation  Classes  Importing packages  Using Methods
  • 28. Comments and Opening Documentation  Opening documentation should include:  description of what program does  input needed, resulting output  special techniques, algorithms used  instructions for use of program  Name of programmer, date, modification history  Opening documentation is multiline  between /* */ character pairs  Inline comments  following // double slashes  Comments ignored by compiler
  • 29. Classes  Classes built for real world objects that cannot be represented using available types  A class is an "extension" of Java  Definition of class: "a group or category of things that have a set of attributes in common."  In programming: a pattern, blueprint, or template for modeling real world objects which have similar attributes
  • 30. Class Declaration  Syntax: class className extends existingClassName { // Attributes (variables & constants) // and behaviors (methods) }  Where  className is the name of a new reference type  existingClassName is any class name known to the compiler  { and } mark the boundaries of the declaration
  • 31. Purpose of Class Declaration  Creates a new type that the compiler can use to create objects  This new type inherits all attributes and behaviors of existingClassName  Note:  Object is often used for existingClassName  in this case the extends object may be omitted
  • 32. Importing Packages  Related classes grouped together into a container called a "package"  program specifies where to find a desired class  Fully-qualified name package_name1.ClassName or package_name1.package_name2.ClassName  By using the import package_name1 the prefixes using the dot notation can be omitted  Syntax import package_name.* ; or import package_name.ClassName;  where ClassName is any class stored with package_name
  • 33. Using Methods  Call, invoke, or send a message to the method of an existing object theScreen.print(" … "); theScreen is the object print ( ) is the method being called  Syntax of the call name of the object the dot . the name of the method any required parameters or arguments
  • 34. Value Returning Methods  Some methods return a value  Programmer must also do something with the value to be returned  assign the value to a variable variable_name = objectName.methodName(arguments);  send the value to another method as the parameter
  • 35. 2.4 Java Documentation – API  Note the sample programs so far …  For several tasks, we found a Java method to solve it  Other times the programmer writes the class and methods required  Java designers have provided over 1600 classes  Called the Java Application Programmer's Interface or API  Each class provides variety of useful methods  Classes grouped into packages
  • 36. API Documentation  Finding needed package or class  Hypertext-based documentation system, accessible on World Wide Web  First page of web site has 3 frames  Alphabetical list of packages  Alphabetical list of classes  A "main" frame that initially lists the Java packages
  • 37. Web Based Documentation  Clicking on the name of the package in the "main" frame produces a list of the classes in that package  Click on name of a class displays information about that class  List of fields (variables, constants)  List of methods for the class  Click on a method for a detailed description of the methods This is an important reference source and you should learn to use it effectively
  • 38. 2.5 Introduction to GUIs: A GUI Greeter  Problem Scenario Write a program with graphical user interface that  displays a window with prompt for name  box to enter name  OK and Cancel buttons  User enters name, clicks OK  Second window gives greeting, uses name, displays a button for terminating program
  • 39. Objects Description of Problem's Objects Type Kind Name the program GUIGreeter window for prompt input- dialog prompt for user's name String constant window to display message
  • 40. Operations  Display a window containing a prompt and a text box  Read a String from the window's text box  Hide the window  Display second window with personalized greeting  Terminate program
  • 41. Coding in Java  Note source code in Figure 2.3 Application GUIGreeter  Note run of program  Window for prompt and input  Window for Greeting  Note improved version, Figure 2.4
  • 42. Input Dialog  Input dialogs are GUI widgets  used to get text input from user  Example showInputDialog(prompt);  prompt can be  a string  a graphic image  another Java Object
  • 43. Message Dialog  A GUI widget for displaying information  Example showMessageDialog(null, message, title, messageKind);  Message kind  can be: error, information, warning, question, or plain  used by interface manager to display proper icon