Introduction to Computer Science The secret of computer information storage and calculation is the binary system. Information is stored in a computer with combinations of base-2 ones and zeroes. Individual binary digits (bits) store a one or a zero. A one means true and a zero means false. A set of eight bits forms one byte.
A byte can store one character in memory with ASCII, which allows 256 different characters. The newer, international Unicode stores one character in two bytes for a total of 65536 different characters.
Operating systems change frequently, or at least operating system versions change to a new-and-improved model about every two or three years. A solid knowledge of your computer's operating system is vital. Writing a computer program requires knowledge of editing text, saving and loading files and moving around the hard drive's directory system efficiently.
Sun Microsystems created Java to be a programming language that is portable on many computer platforms, a so-called platform-independent language. They also wanted the language to be compatible with web page development.
Early computers were stand-alone work stations. The first networked computers used a "peer-to-peer" network. This was followed by LANs (Local Area Networks) that connected dedicated specialty servers with computers and printers for a common purpose. The Department of Defense developed the Internet as a means to provide communication at war time.
Individuals, schools and businesses can set up a LAN at their private location without paying a fee beyond the cost of the necessary hardware and software. Connection to the Internet requires an ISP (Internet Service Provider) and a monthly connection fee.
Many computers today, especially laptop computers, have wireless network connections. Such connections are convenient, but they are not as reliable and there is also a greater security risk.
Computers use hardware and software. Hardware peripheral devices are the visible computer components. There are external peripheral devices, such as monitors, keyboards, printers and scanners. There are also internal peripheral devices like disk drives, CD ROM drives, network interface cards and video cards.
Software falls into two categories of application software and operating system software. Application software includes the common applications of word processing and spreadsheets, but also tax return software and video games. Operating system software runs the computer and allows the user to personalize the computer to his or her needs and organize data.
1. What does ASCII stand for?
American Standard Code of Information Interchange
2. What ASCII range is used for the “standard set of characters”?
3. What ASCII range is used for the “extended set of characters”?
4. What is “bit” an abbreviation for?
5. How many bits are in a byte?
6. How is Unicode different from ASCII?
It uses two bytes and adds many characters
7. What is a “nibble”?
8. How many different combinations are possible with 2 bytes?
9. What number system is typically used to display memory addresses?
11. What kind of chip stores permanent information for the computer?
12. What does ROM stand for?
Read Only Memory
13. What kind of chip stores temporary information for the computer?
14. What does RAM stand for?
Random Access Memory
15. Which stores more information, gigabytes or terabytes?
16. Exactly how many bytes are in a kilobyte?
17. What does CPU stand for?
Central Processing Unit
18. The CPU is essentially the _______ of the computer.
19. Is a protractor digital or analog?
20. What type of information allows you to make a precise copy of the original?
21. Define the word “program”.
A set of instructions to achieve a specified goal.
22. Explain why programming in machine language is undesirable.
Programming is 1s and 0s is very tedious and problematic.
23. Explain the difference between an interpreter and a compiler.
Compilers translates the entire file and then execute.
Interpreters translate each line and execute each line.
24. What is a “low-level” language?
Close to computer language
25. What is a high-level language?
Close to human language
26. Why do we not simply use English, or any other human language, to program a computer?
English is too ambiguous
11. What does OOP stand for?
Object Oriented Programming
13. What does “platform independent” mean?
A program can execute on any computer
14. When was Java released… and by whom?
Sun Micro Systems in 1995
19. What does LAN stand for?
Local Area Networks
20. What is a server?
A server is a specialty computer that is connected to the LAN for one or more purposes.
Servers can be used for printing, logon authentications, permanent data storage and communication.
27. What does hardware involve?
Hardware involves all the computer components that can be seen, felt, picked up and dropped, like a monitor, a mouse, a jump drive.
28. What does software involve?
Software involves the set of computer instructions that are coded on a disk, a CD, or a hard drive.
34. What does computer software do?
Computer software provides instructions to a computer.
35. Spreadsheets and word processors are examples of what kind of software?
36. What does system software involve?
System software involves the instructions that the computer requires to operate properly.
37. List 3 major operating systems.
Windows XP/Vista/7, UNIX and MAC OS
Introduction to Java Sun Microsystems provides free software to compile and execute Java programs. The Java Development Kit (JDK) can be found on Sun's website at http://java.sun.com. The current version (June, 2007) finished by Sun is Version 1.6.0 update 1.
The Java program language is designed to create full-fledged program applications for industry, as well as applets that will operate inside a web page. Normally, an application is a larger program than an applet. However, an applet is not necessarily a small program.
The secret of Java's success is the use of both a compiler and an interpreter. First, the Java compiler is used to create an intermediate stage in program translation, called bytecode. Second an interpreter is used to translate and execute the bytecode. Sun created multiple interpreters for different platforms. The interpreter is called a Java Virtual Machine (JVM). There are three distinct steps in creating a Java program.
The Java compiler and Java interpreter translate and then execute existing programs. You still need some tools to write the Java source code. It is possible to write code with any text editor and then use the command prompt to provide commands for compiling and executing. It is easier to use an Integrated Development Environment (IDE) like JCreator to assist in program writing. JCreator can be downloaded for free if you use the light edition. JCreator can execute both application programs and applet programs. You need to a special web page that imports the Java bytecode applet file.
The different components of a program were explained and you saw that a program uses keywords in program statements. Keywords have special meaning to a program. In particular, you looked at the keywords System.out.print and System.out.println. Both keywords display text output. Keyword println adds a carriage-return/line-feed (crlf) to the output statement.
The Java compiler checks to see that every program statement is written with correct syntax before a bytecode file is created. When mistakes are made, the compiler generates error messages about these mistakes.
Computers must be used in a responsible manner. First, care must be taken that a computer is not harmed physically or stolen. Computers are vulnerable and can be easily damaged. Computer data is stored in areas that can be easily corrupted and all important data needs to be backed up in one or more storage areas, like hard drives, CDs or memory sticks. Computers also need up-to-date protection programs against viruses, spyware and SPAM.
Using copyrighted software may be simple, but it is unethical. All software has license agreements that state if the software is free, licensed for one user, multiple users or an entire site, like a school or company. Many people hack into computers, supposedly for fun, unaware that they are inflicting damage with unknown computer hacking programs.
1. Explain why the United Nations “2-step translation” process requires fewer translators than a “1-step translation” process.
You only need 1 translator for every language and English.
2. When is a programming language considered to be platform independent?
When a program created on one computer can execute on all other computers.
3. What type of code is created by a Java compiler?
4. What is bytecode?
The intermediate code generated by the Java compiler
5. If you were to compare the executing of a Java file with the UN, how would “bytecode” fit in with the UN analogy?
Bytecode is English
6. Does the computer understand bytecode?
7. What does Java use an interpreter for?
To translate and execute bytecode
8. What does JVM stand for?
Java Virtual Machine
9. Which program is larger, a compiler or an interpreter?
Compilers are much larger.
10. Java uses a _______ to translate the program source code created by the programmer into _______.
11. Refer to the previous question. Java then continues and uses an _______ to translate the _______ into executable _______ line by line.
interpreter bytecode machine code
12. What is the name for the interpreter that takes the bytecode and then executes the program?
13. List 2 benefits with using Java on a web page?
It is secure and it is interactive
14. What does HTML stand for?
Hyper Text Markup Language
15. What is an applet?
A java program that executes inside a web page.
16. What is an application?
A program that executes stand-alone
17. Can a website contain multiple applets?
18. Can a website be written entirely in Java?
19. What 3 things do you need to write a Java program?
Text editor, compiler and interpreter
20. Refer to the previous question. Some software packages combine all 3 of these things into an IDE.
What does IDE stand for?
Integrated Development Environment
21. Can Notepad be used to write a Java program?
22. All Java programs end with what suffix?
23. Can the Java compiler be accessed from the Command Prompt?
24. All bytecode files end with what suffix?
25-27. What are the 3 steps of a Java program? (This counts as 3 questions.)
Write the Java source in some text editor.
Translate the source code file with a Java compiler into an intermediate bytecode file that will end with .class.
Execute the bytecode file with a Java Virtual Machine (JVM) program, which is an interpreter.
28. What does URL stand for?
Universal Resource Locator
29. What does JDK stand for?
Java Development Kit
30. What does JRE stand for?
Java runtime Environment
31. Why is the JRE necessary?
Allows executing Java programs
32. How much does it cost to download Java from Sun Microsystems?
It is free
33. When downloading the JDK from Sun Microsystems, what is the difference between downloading the Offline or the Online installation file?
The Online choice downloads a very small file with instructions to download additional information during software installation. The Offline choice downloads all the necessary files required for installation. This means that you can then install the software and it is not necessary to be connected to the Internet.
34. Java is an island in what country?
1. What is the difference between the PRO version and the LE version of JCreator?
The PRO version includes sophisticated debugging tools for the professional programmer.
The LE version is free.
2. What does GUI stand for?
Graphics User Interface
3. Look at figure 2.39. The first 5 lines of program Java0201.java all begin with //.
What does that mean?
These are all comments.
4. Are comments compiled into bytecode?
5. Every application program has a _______________ segment.
6. What does the command System.out.println do?
It displays the characters placed between the double quotes that follow.
7. What is a Java keyword?
A word that has a special meaning to Java
8. Two or more keywords combine to make what?
a program statement
9. What does it mean when we say that keywords in Java are “case-sensitive”?
That means that print and Print are two different words to Java.
10. List 7 keywords.
public, class, static, void, main, String and System.out.println.
11. What does CRLF stand for?
Carriage return, line feed
12. Explain the difference between print and println.
The print keyword generates output without a carriage return and the println keyword does include a carriage return.
13. What does println() do when there is nothing between the (parentheses)?
Skip a line
14. Both print and println follow what Java keyword(s)?
15. If you see public class Jessica in your program, what name must the file have?
16. What punctuation symbols must be at the end of all Java program statements?
17. Physical damage to a computer happens, but it is not the biggest problem.
The number one source of grief for many people, especially students, is _______________________.
loss of data
18. What does RAM stand for?
Random Access Memory
19. What happens to the RAM if the computer loses power?
It is lost.
20. What does AVR stand for?
Automatic Voltage Regulation
21. What are the 2 parts of a computer virus?
The duplication part and the payload
22. What is spyware?
Special programs that snoop around your computer and try to record information
23. Why is it bad to leave your computer both logged in and unattended?
Anyone can go to your computer and copy, alter or erase anything.
24. What does USB stand for?
Universal Serial Bus
Java Simple Data Types This chapter introduced the Java simple data types. A simple data type is simple because it stores a single value in memory. Simple data types are also called primitive data types. Program examples were shown that declared variables of a specified data type. Declaring the data type allows the compiler to allocate memory for the value to be stored.
There are four different integer data types: byte-1, short-2, int-4 and long-8 each indicated with their respective number of bytes in memory. Java provides five operators for integers: addition, subtraction, multiplication, integer-division and modulus-division.
There are two different real number data types: float-4 and double-8. Float is short for floating point number and double indicates that this data type is twice the precision of a float data type. Java provides four operators for real numbers: addition, subtraction, multiplication and real number division.
The specified data type is good for memory efficiency, but stingy use of memory can result in memory overflow. If a value is larger than the space reserved in memory, the result is incorrect, even if the mathematics is flawless.
In Java there are many shortcut notations for both unary operators and binary operators. Every arithmetic operator can be expressed in a shortcut notation. Keep in mind that multiple shortcut operations in the same statement can create very ambiguous program statements that are difficult to predict.
Java can declare character and string variables. The plus operator is used for arithmetic addition with numbers and concatenation with strings. Concatenation means that a string is appended at the end of another string. The String data type is included with the simple data types because we treat it like a simple data type right now. A string does hold multiple character values, but we process the entire set of characters as a single unit. You will learn in a later chapter the true nature of the String data type.
This chapter also introduced the boolean data type. This data type can store the value true or the value false. Boolean is included with this chapter to make the chapter complete with all the available simple data types. The actual usage of boolean will be shown later.
Java has a peculiar variable, called a final variable that cannot change. I prefer to call this a constant. Declaring a constant is identical to declaring a variable with the reserved final in front of the data type.
It is important to document your programs. Start by selecting identifiers that are self-documenting. Single-character identifiers should be avoided in most cases. Programs should also make generous use of meaningful comments that help explain the purpose of program segments and certain program statements.
Java programs use the same mathematical precedence that is used in mathematical computation. Logically, there is no apparent difference between mathematics and computers science. Practically, there are some differences. In mathematics there are assumed operations, especially multiplication that needs to be explicitly shown in a Java program. It is sufficient to state AB + CD in mathematics. In Java such an expression needs to be A*B + C*D.
It is possible to alter data types with type casting. Integers can become doubles and characters. Doubles can become integers and characters. Characters can become integers and doubles. Type casting is achieved by placing the new, desired data type inside parentheses in front of the variable to be altered.
Literal strings will not always display literally. Certain special characters following a single slash like \n, \t will result in a carriage return, a tab or some other special output display. The slash-character combination is called an escape sequence.
1. A program is made up of words, which usually are called what?
2. What is the first Java syntax rule?
Use only keywords known by the Java compiler.
3. List the 3 categories of keywords.
Reserved words, pre-defined identifiers and user-defined identifiers
4. List 3 examples of Java Reserved Words.
public, static, void
5. Java has a large number of libraries that enhance the basic Java language. These libraries contain special program modules that perform a variety of tasks to simplify the life of a programmer. What are these modules called?
6. List 2 examples of Predefined Identifiers.
print and println
7. When you are creating User-Defined Identifiers, you must make sure your identifier is not one of what two things?
A reserved word or a pre-defined identifier
8. What are the rules for naming an identifier?
Use alpha-numeric characters and start with an alpha character.
9. Print the Java statement that will declare x as an integer.
10. Refer to the previous question. Print the statement that will assign the value of 7 to x.
x = 7;
11. In program Java0301.java, why does the statement: System.out.println(a); display the value of 10 and not a?
The letter is not between double quotes.
12. Why does program Java0302.java not compile?
There are no values assigned to the variables.
13. Print the Java statement that will declare x as an integer and assign the value of 7 to x in one single statement.
int x = 7;
14. List Java’s 4 integer types.
byte, short, int and long
15. How many bytes are used by an int?
16. What is the largest value of a byte?
17. Would a short be appropriate to store Zip Codes?
18. Explain your answer to the previous question.
A short cannot hold any number above 32,767. Many zip codes are larger than this.
19. What are the 5 integer operations?
20. What is the difference between the / and the % division operators?
/ is integer division and % is remainder division
1. In binary, what indicates if a number is positive or negative?
If the first bit is 0, the number is positive and if the first bit is 1, the number is negative
2. How is it possible for a computer to multiply 2 positive numbers, and get a negative product?
Memory flow, which alters the sign bit
3. Explain Memory Overflow.
A condition that occurs when the mathematical value is too large to be stored in the actual
computer memory space.
4. The Real Number data type that we will use is called double. Why is a double called a double?
It has double the bytes of a float
5. Which is more precise? A double, or a float?
Assume x is an int for the next several questions.
6. What does x++; or ++x; mean?
In both case variable x is incremented by 1.
7. What does x--; or –x; mean?
In both cases variable x is decremented by 1.
8. Should Java shortcuts be combined with other Java statements? Example: System.out.println(x++);
No, it causes confusion
9. What does x += 5; mean?
Increase x by 5
10. What does x -= 5; mean?
Decrease x by 5
11. What does x *= 5; mean?
Multiply x by 5
12. What does x /= 5; mean?
Divide x by 5
13. What does x %= 5; mean?
Compute the remainder or dividing x by 5
14. What is the difference between the char and String data types?
The char type store one character and the String data type store one or more characters.
15. In program Java0312.java, what is accomplished by the statement: c1 = c2 = c3 = 'Q'; ?
Every variable is assigned the value of Q.
16. What is the fancy name for using the plus ( + ) sign to join strings together?
17. The plus ( + ) sign can be used to add integers and real numbers. It can also be used to join strings.
What is it called when one operator can perform different functions.
18. What is “2” + “3” ?
19. Who invented a form of Algebra based on logical statements that are either true or false?
20. Today, in computer science, a data type that has only two values of true and false is a called a _______ data type.
21. What is Java’s formal language for the term simple data types.
22. Say you want to use PI in your program with value of 3.14159. This value will never change in your program. Print the proper way to define and initialize this constant.
final double PI = 3.14159;
23. What happens when you attempt to alter the value of a final variable?
It causes a compile error.
24. What is a self documenting identifier?
An identifier, such as grossPay, that explains the purpose of the variable.
25. What is the difference between double-slash ( // ) comments and slash-star star-slash comments (/* */) ?
// is a single line comment
/* */ is a multiple line comment
26. Does Java follow the same Order of Operations that you learned in your Math
27. Translate 7abc into Java source code.
7 * a * b * c
x + 7
28. Translate ————— into Java source code.
2x - 3
(x + 7) / (2 * x - 3)
29. Translate “one half” into Java source code.
1.0 / 2.0 or 0.5
30. What is the output of: System.out.println( 10 / 3 ); ?
31. What is the output of: System.out.println( (double) 10 / 3 ); ?
32. What is an escape sequence?
A special set of characters, starting with /, that means something to print, like \n
33. What does the escape sequence \n do?
carriage return, line feed
34. What escape sequence is used to generate a ?
35. Why do we need escape sequences to generate backslash ( \ ) and quote ( " ) characters?
It prevents confusion to the compiler
36. What are the 4 data types that will be tested on the AP Exam?
int, double, boolean and String
Java Program Organization Chapter IV introduced the fundamental program organization of Java. The organization of a program is similar to the organization of an English essay, story or book. Java keywords combine to form program statements. A group of program statements, which accomplish some specific purpose, are placed together in a container called a method. A set of methods with similar functions are placed inside a larger container, called a class.
A class also contains data, which is used by the methods. A class is a data type. One particular variable of a class is called an object.
The first methods introduced were methods of the Math class. Access to methods is done by using the class identifier, followed by a period and then the method identifier, like Math.sqrt(16). This approach is done with Math methods.
During this course you will be using a very large class, called Expo.
Things to Remember about the Expo class
The Expo class is not part of Java.
The class was created to simplify programming and allow students to focus on the logic of programming.
In order to use the Expo class, the file Expo.java must be in the same folder/directory as the .java file that calls the Expo class methods.
Students will NOT be required to memorize the methods of the Expo class. They will instead be provided with documentation to use during labs and tests.
1. Which programming language requires a very precise organization?
All of them 2. What spoken language is Java based on?
English 3. List 7 Java keyword.
public, main, System, int, double, print, void 4. Programming languages require special “containers” that their program statements are put in.
What are these containers called in Java?
Methods and classes 5. If a program has syntax errors, can it compile?
No 6. If a program does not compile, will a byte code file be created?
No 7. What must all program statements end with?
A semi-colon (;) 8. Are “method headings” and “class heading” program statements?
No 9. Which keywords in Java are case-sensitive?
All of them 10. What kind of operator is the equal sign (=) ?
An assignment operator 11. Why do computers exist?
To make life simpler 12. Modules that perform a related set of functions are grouped together in a special type of container.
What is this special container called?
A class 13. What do classes contain?
One or more methods 14. What do methods contain?
One or more program statements
15. What is the output of System.out.println(Math.sqrt(100)); ?
10 16. What is the output of System.out.println(Math.sqrt(64)); ?
8 17. What is the output of System.out.println(Math.sqrt(49)); ?
7 18. What is the output of System.out.println(Math.sqrt(25)); ?
5 19. What is the output of System.out.println(Math.sqrt(9)); ?
3 20. Refer to the previous question. What does Math signify?
The name of the class 21. Refer again to question 19. What does sqrt signify?
The name of the method 22. Refer yet again to question 19. What does 9 signify?
The argument/parameter/information being passed/sent to the method 23. What is a parameter used for?
It provides necessary information to the method. 24. Can Math.sqrt be used without a parameter?
No 25. List 4 different things that can be passed as a parameter.
a numerical constant,
an expression ,
or even another method
26. The information, which is passed to a method is called an _____________ or a _____________.
argument or a parameter 27. Where are parameters placed?
Parameters are placed between parentheses immediately following the method identifier. 28. What happens if you alter a program - no matter how slightly - and then execute without recompiling?
You will be using the bytecode file that was created with an older version of the program. 29. The floor, ceil, and round methods of the Math class all “round” in some way.
What is the difference among them?
floor always rounds down
ceil always rounds up
round rounds normally 30. What is the output of System.out.println(Math.round(7.5)); ?
8 31. What is the output of System.out.println(Math.round(7.499)); ?
7 32. What is the output of System.out.println(Math.ceil(7.999)); ?
8 33. What is the output of System.out.println(Math.ceil(7.001)); ?
8 34. What is the output of System.out.println(Math.floor(7.999)); ?
7 35. What is the output of System.out.println(Math.floor(7.001)); ?
7 36. What is the output of System.out.println(Math.max(100,50)); ?
100 37. What is the output of System.out.println(Math.min(100,50)); ?
50 38. What is the output of System.out.println(Math.abs(-3)); ?
3 39. What is the output of System.out.println(Math.abs(3)); ?
3 40. What is the output of System.out.println(Math.pow(3,4)); ?
81 41. What is the output of System.out.println(Math.pow(4,3)); ?
64 42. What is the output of System.out.println(Math.pow(2,5)); ?
25 43. What is the output of System.out.println(Math.pow(5,2)); ?
32 44. Are PI and E “attributes” or “methods” of the Math class?
1. Is the Expo class part of the Java programming language?
No 2. Which type of method has more parameters: Math methods or graphics methods?
Graphics 3. Graphics images are not solid pictures, but images created with hundreds or thousands of individual colored dots. What are these individual graphics dots called?
Pixels 4. What is the minimum requirement of any call to a graphics method?
information about the location or coordinates for the picture 5. What is the name of the coordinate system that has 4 quadrants and the point (0,0) in the center?
Cartesian 6. List 2 differences between a Cartesian graph and a computer graphics screen.
The (0,0) coordinate is located in the left-top corner of the applet window, instead of the middle.
In a Cartesian system Y-values increase from the bottom to the top.
An oval 26. The first 5 parameters of drawArc are identical to drawOval.
drawArc adds 2 more parameters at the end. What do these 2 parameters specify?
the starting degree value and the stopping degree value
In questions 1 through 10, you are using the Expo.drawArc method to draw each of the arcs that are displayed. You need to provide the last 2 parameters.
Arc to be drawn
Starting Degree Value
Stopping Degree Value
0 or 360
0 or 360
0 or 360
11. Does the order of the parameters matter ?
Yes 12. The parameters of drawSpiral are identical to which method?
drawCircle 13. What is meant by the radius of a star?
The distance from the center of a star to any point 14. The parameters of drawStar are very similar to drawCircle.
The difference is drawStar has an extra parameter at the end. What does it specify?
The number of points on the star.
15. If you want to draw solid rectangles, circles, ovals, and stars, what methods would you use?
fillRectangle, fillCircle, fillOval and fillStar 16. What happens when a small shape is drawn on top of a large shape that is the same color?
The small object will not show up.
17. What is the default drawing/filling color?
Black 18. How many colors are built into the Expo class?
25 19. If you want to draw PAC-MAN, what method would you use?
20. All draw methods of the Expo class have a corresponding drawThick method which have the exact same parameters, except for one extra parameter at the end. What does that parameter specify?
The thickness of the shape 21. What file contains the documentation of the Expo class.
Expo.html 22. Refer to your answer to the previous question. When you look at this file, you will see brief “one-sentence” descriptions of each of the methods of the Expo class. What do you need to do if you want more detailed information on a particular method?
Click on the name of the method. 23. In a method’s documentation, what does the precondition specify?
The precondition specifies what must be true for the method to work properly. 24. In a method’s documentation, what does the postcondition specify?
The post condition specifies what is true after the method is finished. 25. If a method has BOTH a precondition and a postcondition, what must be true for the postcondition to happen?
The precondition must be true. 26. What does NaN stand for?
Not a Number
Alice: Chapters 1-2 True or False
30) According to the Alice text, learning to program makes you a computer nerd
31) According to the Alice text, Computer Scientists refer to “If” statements as Conditional Execution.
32) In Alice, an object has 5 degrees of orientation (ie. Up, down, back, left, right)
33) In Alice, an object has 6 degrees of freedom:
34) An object is: __________________________________________________.
35) Alice is written in ____________________.
36) In Alice, the Object Tree contains ____________________________________________________________.
37) In Alice, an instruction is ______________________________________________________.
38) Creating a computer program is a _______________-step process which includes _________________, _________________, _________________, _________________ .
39) “Algorithmic” means “___________________”
40) It is “possible”/“impossible” to make a syntax error in Alice
41) In the Circling Fish exercise from Ch. 2, the most effective way to circle the fish around the Island is to