Академический Документы
Профессиональный Документы
Культура Документы
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;
Name them
Boolean, byte, char, double, float, int,
long, short
In bytes, how long is the short data type?
The int data type, the long data type?
In bytes, how long is the float data type?
The double data type?
How long is the char data type?
Primitives sizes and Ranges
PRIMITIVE SIZE IN BITS RANGE
int 32 -2 to the 31st to 2 to the 31st
int 4 bytes 2147483648
long 64 -- 8 bytes -2 to the 63rd to 2 to the 63rd
float 32 +- 1.5 x 10^45
double 64 +- 5.0 x 10^324
decimal (C# only) 128 28 significant figures
string 16 bits per char Not applicable
char 16 One character
bool (boolean in Java) 8 True or false
The assignment operator =
A = 36;
Sets a = to the constant 36 at execution time
Int A =36;
Sets A = to the constant 36 at compile time
Initializes A to 36 at the time memory is set
aside for it
Name a Method that many Java
classes have
TheMain method
Why??
Itis used as an entry point to the program for
some types of programs.
What do the keywords
Public
Static
Void
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;