Professional Documents
Culture Documents
Lect 2
Lect 2
James Burns
Recitation
Name some characteristics of objects
Chemical Bank
Describe the differences between interpreters
and compilers
Applets—interpreted or compiled?
JAVA Apps—
What is a namespace?
Is it supported by JAVA?
A using keyword brings a namespace into scope
Four common namespaces (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Mean???
Which of these do we usually use in
connection with a class?
Which of these do we use in connection
with the declaration of a main?
What is concatenation?
Consider the following:
Public class NumbersPrintln
{
public static void main(String[] args)
{
int billingDate = 5;
System.out.print(“Bills are sent on the “);
System.out.print(billingDate);
System.out.println(“th”);
System.out.println(“Next bill: October “ + billingDate);
}
}
The above produces the following
output
C:\Java>_
C:\Java>Java NumbersPrintln
Bills are sent on the 5th
Next bill: October 5
C:\Java>_
This program would produce the
same output
Public class NumbersPrintln
{
public static void main(String[] args)
{
int billingDate = 5;
System.out.println(“Bills are sent on the “ +
billingDate + “th\nNext bill: October “ +
billingDate);
}
}
Simple Arithmetic Operators
• * / % (multiplication, division, modulus)
• + - (addition, subtraction—on a lower
level of the precedence hierarchy)
• int result = 2 + 3 * 4;
• Is result 14 or 20??
• int result = (2 + 3) * 4
Binary Operators
The simple arithmetic operators are also
called binary operators because they have
two operands exactly
Never three
Never one
Using the Boolean data type
•Boolean variables can hold only one of
two values—true or false
Boolean isItPayday = false;
Boolean areYouBroke = true;
Comparison operators
The result is boolean, always
< less than
> greater than
== equal to
<= less than or equal to
>= greater than or equal to
!= not equal to
Boolean examples
boolean is SixBigger = (6 > 5);
// value stored in is SixBigger is true
Boolean is SevenSmaller = (7 <= 4);
// value stored in is SevenSmaller is false
Data formats
The character format—uses an assigned
decimal value
The integer format
The floating point format—consists of an
exponent part and a mantissa part—for
example the 4-byte floating point word
might have a 1-byte exponent and a 3-
byte mantissa.
What happens when you try to do
arithmetic with different data types?
The lower-level data type is converted to
the higher-level data type before the
binary operation is performed
1. double
2. float
3. long
4. int
Example
int hoursWorked = 37;
Double payRate = 6.73;
Double grossPay = hoursWorked * payRate;