Chapter 5 (10/22)

EX 5-1
1.) The different between a class and an object is an object is a runtime entity that contains data and responds to message and a class is a software package or template that describes the characteristics of similar objects.
2.) The object will then be deleat by memory stage.
3.) The three important characteristics of an objects are behavior, state amd identity.
4.) The client and server are the two objects that involved when messages are sent. The relationship between them are a client’s interactions with a server are limited to sending a message.
5.) The class’s interface remains the same thing as the class’s implementation details, both of them can be changed radically without affecting any of its clients.

EX 5-2
1.) Messages that change an object’s state are called mutators. The accessors is another messages to access the object’s state if the mutators worked correctly.
2.) Private; specify that data or method to only be used in certain cirtaintance, within {}.
Public: the data or imformation after such a modifier can be seen or used by anybody and anywhere.
3.) A constructor methods is one or more methods that indicate how to initialize a new object.
4.) It can returns a string containing the student’s name and test scores.
5.) First, assign the variables an initial values.
Then set the object’s data attributes by sending the same message.
Additionally, we must add a object will variable 2.
Last, the variable 1 and 2 is refer to the same object.
6.) The different between the primitive types and the reference types are in memory. The primitive type’s variable is best viewed as a box that contains a value of that primitive type. A variable of a reference type is thought of as a box that contains a pointer to an object.
The example for the primitive type is (int, double).
The example for the reference type is (allclasses, for instance).
7.) A special value that indicates that no objects can be accessed.
8.) When a program attempts to run a method with an object that is null, Java throws a null pointer exception.
=>String str = null;
System.out.println (str.length());
9.) Default Constructors is what we have been so far have had empty parameter lists, this constructor initializes numeric variables to zero and object variables to null, thus indicating that the object variables currently reference no objects.
10.) If a class tmplate contains no constructers, the JVM provides a primitive default constructor behind the scence, This constructor initializes numeric variables to zero and object variables to null, thus indicating the object variables currently reference no objects.
11.) A class can include more than one constructor, provided each has a unidue parameter list, but all the constructors must have the same name, that is , the name of the class.

EX 5-4
1.)Formal parameter is parameter that listed in a method’s definition. Actual parameter is values passed to a method when it is invoked.
2.) When a method is called, the value of the actual parameter is automatically transfered to the corresponding formal parameter immediately before the method is activated.
3.) public the Sum(){
int sum;
sum = (int) Math.round (a + b);
debug(“Sum; “average);
retirn sum;
}
4.) It is convenient to achive temporary working storage for data in a method.

EX 5-5
1.) The lifetime of a variable is the period during which it can be used. Local variable amd formal parameters exist during a single execution of a method, once the method stops executing, the formal parameters and local variables are no longer accessible. Instance variable are last for the lifetime of an object, it avaliable every time a message is sent to the object and serve as the object’s memory, when the object stops existing, the instancce variables dsiappear as well.
2.) Shadowing is considered a dangerous programming practice because it greatly increase the likelihood of making a coding error.
Example=>iAmAVariable = iAmAVeriable;
The local variablee iAmAVariable is said to shadow the global variable with the same name.

Published in: on October 22, 2007 at 4:12 pm  Leave a Comment  

Chapter 4 (10/11)

EX 4-7
1-a.) The variable devide by 2 will be equal to 0 if i is equal to 1, or equal or less then limit, i will be equal to limit.
b.) Using ramdom generator to operate the java file myNumber.
Variable x is equal to 0
Variable your number
If you guess a number between 1 and 10
“Which number is it?”
If your number is simller to my number then the program will show “that’s it”, if the number you guess is wrong, the peogram will show “Sorry, try again”.
2-a.)
b.)

EX 4-8
1. We use this to create a scanner object by opening it on a file object rather than the keyboard object. By running the cide new File (aFileName), we can object a file, where afileName is a pathname or the name of a file in the current working directory.

EX 4-9
1-a.) No odd number remainder when i%2.
b.) There are more then one operator in the opsitive odd number.

Published in: on October 12, 2007 at 2:43 pm  Leave a Comment  

Chapter 4 Exercise 3

EX 4-3
1.) Jill use while statement in her instruction to Jcak because she wants to let him do the repeatedly as long as the condiction holds is ture, if it is ture, do step 1, if it ia false, do step 2.
2-a.) if (a checker price is red){
put it on a red square;
}else{
put it on a black square;
}
b.) if (your shoes are muddy){
take them off;
leave them outside the door;
}
c.) pick up all the marbles on the floor;
put them into a bag;
}
3-a.) if x is larger than y, x = temp, x = y and y = temp; otherwise, y = temp, y=x and x = temp
b.) as long as conut is less than or equal to sum, then a n interger will continue read as x as sum = sum + Math.abs(x); otherwise, if the total is greater than 0, it will stop.

Published in: on October 1, 2007 at 3:04 pm  Leave a Comment  

Chapter 4 Exercise 1,2

EX 4-1
1-a.) x * = 2
b.) y % = 2
2-a.) x = x + 5
b.)x = x * 5

EX 4-2
1-a.) z = Math.sqrt(4) = 2
b.) z = Math.round=d(3.6) = 3
c.) z = Math.pow(4,3) = 64
d.) z = Math.roung(Math.sqrt(3.6)) = 1
2-a.) System.out.print(generator.nextInt(20)+1);
b.) System.out.print(generator.nextDouble(10));

Published in: on September 28, 2007 at 3:28 pm  Leave a Comment  

Chapter 3 Exercise

Chapter 3 Exercise
EX 3-1
1.)It is the set of all of the words and symbols in the language. The example, arithmetic operators–>+ – * /
2.) Left and right parentheses must occur in matching pairs.
3.) x+y first then *z
4.) The first difference is size, programming have small vocabularies and simple syntex and semantics copared to natural. Another difference is literalness, programming would only followed instraction in a very literal manner.

EX 3-2
1.) Double have 8 bytes srorage requirements and int have 4 bytes.
2.) Java’s syntex fro manipulating primitive data types differs distinctly from the syntex for manipulating objets. The primitive data types are combined in expressions involving operators, like additionand multiplication. Objects are sent message.
3-a.) 23.5=2.35*10E1
b.) 0.046=4.6*10E-3
4-a.) 322100
b.) 0.0556
5.) String “HarryPotter” or string “Rita”
6.) Because variable is an item whose value can change during the execution of a program.
7.) fahrenheit and celcius
8.) double payRate=35.67
9.) int a, b, c=4
10.) int q=1.234, int w=hellow
11.) final double KILOGRAM=2.2
12-a.) 25
b.) -15
c.) 30
d.) 0
13-a.) There are more than one arithmetic operators, in this case the subtraction and multiplication, appear together without a number in between.
b.) This equation lack of one left parenthesis.
c.) There is no actual commend but just a pair of parenthesis in the sentence.
14-a.) 2.25
b.) 0.44
c.) 0
15-a.) This is valid because z is a less inclusive data type than x is.
b.) his is valid because z’s int data type will be autimatically converted to the more inclusive double data type. Since x is in the double data type, it will be valid for it to hold the result.
c.) This is not valid since z is assigned to be in int data type, a less inclusive data type than double data type, so z can’t hole the result of x+y, a double data type.
16-a.) 8
b.) 9
17.) y=(int) x
18-a.) y + x=Wizard Java
b.) y + y.length + x = Java 4 Wizard
c.) y + “\n” + x + “\n”=
19.)
20.) A message is a symbol used by a client to ask an object to perform a service, and a method id a chunk of code that can be treated as a unit and invoked by name.
21.) First returns a double entered by the user at the keyboard–>double nextDouble(),
then writes n to the print stream–>void println (double n)
22-a.) valid
b.) valid
c.) invalid
d.) valid
23-a.) circle diameter
b.) income tax constant
c.) rectangle draw
24.) x is the overall name of the package, y is the name of a subsection within the package, z is the name of a particular class in the subsection.
25.) It is the subsection can import all the classes with a subsection at once.

EX 3-3
1-a.) System.out.print (“Enter your wage (a double): “);
wage = reader.nextDouble( );
b.) System.out.print (“Enter your Social Security Number (a string): “);
social security = reader.nextDouble( );
2.) Returns the first interager in the input line. Leading and trailing apaces are igmored.
3.)

EX 3-4
1.) End of line comments include all of the text following a double slash (//) on any given line, this style is best for just one line of comment. Multiline comment include all of the tesxt between an opening /* and a closing /*.
2.) Accompany a variable declaration with a comment that explain their purpose.
Include comments to explain the workings of complex or tricky sections of code.

Published in: on September 21, 2007 at 1:45 pm  Leave a Comment  

Chapter 2 (9/13)

EX 2.1
1.) What is a portable program?
-It’s a program that can be used in every kind of computer, nometter it’s Apple or PC. For example, Java byte code is a highly protable program.
2.) Describe two features of java that make it a better language than C++?
-Enables the construction of virus-free, temper-free systems and suppores the development of programs that do not overwrite memory.
3.) What is a thread? Describe how threads might be used in a program.
-A thread is a process that can run concurrently with other processes. Threads may used to transfers an image from one machine to another across a network.

EX 2.2
1.) What does JVM stand for?
-Java Virtual Machine
2.) What is byte code? Describe how tha JVM uses byte code.
-It’s a machine language for an imaginary Java computer. You must instell JVM to tha computer if the computer is a particular computer.
3.) What is an applet? Describe how applets are used.
-An applet is a Java program that can be downloaded and run on a Web browser. These applets range from displaying a comical animated character on a Web page to displaying a continuous stream of stock market quotes.

EX 2.4
1.) Give a short definition of “program.”
-A program is a sequence of instructions for a computer.
2.) What is the effect of the message println?
-It is the name of the message being sent to the Syystem.out object.
3.) Describe how to use the System.out object.
-System.out.println.(“the thing you want println to do”)
4.) Write a sequence of statements to display your name, address, and phone number in the terminal window.
- public class HelloWorld{
public static void main(String[]args){
System.out.println.(“Nina Lu”);
System.out.println.(“81 Providence Street 01604″);
System.out.println.(“6174121461″);
}
}
EX 2.5
1.)
2.)
3.)
4.)

Published in: on September 13, 2007 at 12:48 pm  Leave a Comment  

Hellow World Quiz

1.) What is this platform-independent code called?
-Bytecode
2.) Which of the following is not a valid comment?
-c.
3.) What’s the first thing you should check if you see the following error at runtime?
-The classpath, if it is wrong, the class path would not be found.
4.) What is the correct signature of the main method?
-The correct signature of the main method is public static void main9String[] args)
5.) When declaring the main method, which modifier must come first, public or static?
-They can be in either public or static but the convention must be public static.
6.) What parameters does the main method define?
-It define a single parameter, it’s named args, the type of single parameter is an array
of string object.

Exercises-Change the HelloWorld.java program so that it displays Hola Mundo! instead of Hellow World!
Change System.out.println(“Hellow World!”); // Display the string, to System.out.println(“Hola Mundo!”); // Display the string.

Published in: on September 11, 2007 at 1:40 pm  Leave a Comment  

9/7 Homework

1.)
Abit is a smallest unit of information processed by a computer.
eight adjacent bits=1 byte
100 bytes= 1 mega
100000 bytes=1 giga
2.)
Input-monitor, pliuter
Output-keyboard, mouse, screem
3.)
4.)
Hardware consists of what you see on the desktop.
Software consists the programs that give the hardware useful funcionality.
5.)
Application software is use to get work done.
System software keep all hardware and software running.
6.)
The language useddirectly by the computer in all its calculations and processing.
7.)
Machine language, Assembly Language, High-level language
8.)

9.)
5-101
200-
1534-10111111110
10.)

Published in: on September 10, 2007 at 2:35 pm  Leave a Comment  

What is the program name?

This is a program for me to know more information about computer science.

Published in: on September 6, 2007 at 3:08 pm  Leave a Comment  

Hello world!

Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!

Published in: on September 6, 2007 at 2:56 pm  Leave a Comment  
Follow

Get every new post delivered to your Inbox.