English Department Freshmen English Summer Reading and

English Department   

Freshmen English Summer Reading and Grammar Exercises All freshmen (College Prep, Honors, and High Honors) will read the novel Lord of the Flies, by William Golding. You will be assessed at the beginning of the school year with a test and/or written assignments related to the novel. Use the Penguin Classics Deluxe Edition and read the foreword by Lois Lowry and the Introduction by Stephen King (ISBN 9780143129400)

Please note: you must purchase the edition of the book that is indicated above. You cannot use an electronic version for class. All freshmen will also complete the grammar exercises that follow the book topics.



High Honors freshman will also read The Boys in the Boat, by Daniel James Brown

Topics for The Boys in the Boat: You should type your responses to these topics and save the typed responses so that you can reformat them at the beginning of the school year according to directions that will be provided in class. 1. The Boys in the Boat is the actual story of “nine Americans and their epic quest for gold at the 1936 Berlin Olympics.” While you were reading the book, how did your awareness that the “characters” are real and the events actually took place affect your reaction to the story? (200300 words) 2. What has the author done to give the story much of the effect of a novel? (200-300 words) 3. Briefly explain how you reacted to each of the following individuals from the book and why: Joe Rantz, George Pocock, Al Ulbrickson, and Ky Ebright. Choose an additional two individuals from the book and explain your reaction to them. (150-200 words each)


    Freshman Summer Grammar Assignment  All freshmen must study the definitions and complete the exercises on  parts of speech that follow.  Students should print out the pages, follow the  directions for each exercise, and put the answers on the printed pages.  Students will take a diagnostic test on this material at the beginning of the  school year; therefore, study and practice is imperative.    PARTS OF SPEECH THE NOUN A noun is a word used to name a person, place, thing, or idea. A proper noun is the name of a particular person, place, or thing. Proper nouns are always capitalized. [New Jersey] A common noun does not name a particular person, place, or thing. Common nouns are not capitalized. [school] A concrete noun names an object that can be perceived by the senses. [book] An abstract noun names a quality, a characteristic, an idea. [popularity] A collective noun names a group. [herd, team, jury] A compound noun is two or more words joined together. They may be written as one word [doorstep], as two words [training school], or with hyphens [father-in-law]. THE PRONOUN A pronoun is a word used in place of a noun or of more than one noun. The noun that the pronoun replaces is called the antecedent of the pronoun. Personal pronouns are most commonly used. First Person: I, my, mine, me, we, our, ours, us Second Person: you, your, yours Third Person: he, his, him, she, her, hers, it, its, they, their, theirs, them A reflexive pronoun refers to the subject and directs the action of the verb back to the subject. An intensive pronoun emphasizes a noun or another pronoun. Reflexive and intensive pronouns are myself, yourself, himself, herself, itself, ourselves, yourselves, and themselves. A relative pronoun (who, whom, whose, which, that) introduces a subordinate clause. An interrogative pronoun (who, whom, whose, which, what) introduces a question. A demonstrative pronoun (this, that, these, those) points out a person, place, thing, or idea.

An indefinite pronoun, such as all, each either, both, everyone, several, nobody, refers to a person, a place, or a thing that is not specifically named.

THE ADJECTIVE An adjective is a word used to modify a noun or a pronoun. The most frequently used adjectives, a, an, the, are called articles. THE VERB A verb is a word that expresses an action or state of being. An action verb expresses activity, whether physical or mental. A linking verb connects a noun or pronoun with the words that identify or describe the noun or pronoun. Many linking verbs are verbs of being, formed from the verb be. [is, am, are, were, was, be, being, been] An auxiliary verb, or helping verb is sometimes needed to help the main verb to form a verb phrase. THE ADVERB An adverb is a word that modifies a verb, an adjective, or another adverb. It may tell how, when, where, or to what extent (how often or how much) the action of the verb is done. THE PREPOSITION A preposition is a word that expresses a relationship between a noun or a pronoun and another word in a sentence. The noun or pronoun that follows the preposition is called the object of the preposition. The preposition, the object, and the modifiers of that object form a prepositional phrase. Some commonly used prepositions are about, above, at, between, by, for, in, of , like, into, to with. THE CONJUNCTION A conjunction is a word that joins words or groups of words. Coordinating conjunctions: and, but, or, nor, so, for, yet Correlative conjunctions: either...or not only...but also neither...nor whether...or both...and Subordinating conjunctions: (commonly used) after,, before, if, because, while, when, until, than, though, where, as THE INTERJECTION An interjection is a word or phrase used to express emotion and has no grammatical relation to other words in the sentence. [Help! Ouch! Ah! Well! Ugh!]

*****************Use the link below for additional explanation/help***************** https://owl.english.purdue.edu/owl/section/1/5/

EXERCISES Complete each of the exercises. Refer to the parts of speech definitions as needed. NOUNS Circle the 25 nouns that appear in the following paragraph. As a young woman, Elizabeth Cady Stanton studied the classics and mathematics both at home and at Troy Female Seminary, from which she graduated in 1832. Beginning at an early age, she recognized the injustices suffered by women, especially in education and politics. In 1840, she married Henry Stanton, a prominent abolitionist. At an antislavery convention in London, Mrs. Stanton was outraged at the treatment of the female delegates. She later helped to organize the first meeting to address women’s rights. At that convention, she read her Declaration of Sentiments, which addressed the inferior status of women and called for reforms.

Nouns continued Circle the collective and compound nouns that appear in the following sentences. 1. The public seems to like movies about strange creatures. 2. Perhaps the majority likes to escape from reality by watching these movies. 3. I read about a club in California that is devoted to old monster movies. 4. Our neighborhood group gets together to watch Alfred Hitchcock movies. 5. Hitchcock can frighten an audience without monsters. 6. Harriet Tubman, an African American and probably the most famous conductor on the Underground Railroad, led her own parents to safety and freedom in 1857. 7. I read in the newspaper that in 1955 Marian Anderson appeared with the Metropolitan Opera in New York City, becoming the first African American soloist to perform with that company.

8. My stepfather and my sister-in-law saw her perform at the Met. 9. Creativity and imagination, as well as an interest in the education of the deaf, led Alexander Graham Bell to invent the telephone. 10.

Roberto Clemente, who played baseball for the Pittsburgh Pirates, was killed in a plane

crash while on a relief mission for victims of an earthquake in Nicaragua.

PRONOUNS Circle the pronouns in each sentence. Draw an arrow from the pronoun to its antecedent if it has one. 1. I do not consider myself one of those who seem thoroughly satisfied with the world as it is. 2. Nobody has bought more than one of the records on sale at the discount store. 3. Someone once said that humorists are those who laugh at one or more of the world’s foibles. 4. Some of the most famous contemporary humorists are women who write prose and poetry. 5. Phyllis McGinley has written humorously about suburban life as she has known it. 6. Dorothy Parker, who was one of the few to have a book of verse on the best-seller list, frequently wrote about the subject of heartbreak, which she treated with ironic humor. 7. Shirley Jackson wrote serious stories like “The Lottery”; she also wrote humorous ones about her family life. 8. Few of the people who have seen Jean Kerr’s comedies on Broadway have failed to find amusement in them. 9. Nearly everybody is familiar with P. L Travers’ stories about Mary Poppins, a character everpopular with young people. 10.

Erma Bombeck, whose books are about life in the suburbs, is one of the better-known


ADJECTIVES Circle the adjectives in the following paragraph. Do not include the articles a, an, the. By the early 1980s, an extraordinary craze for bicycling had swept the United States. The early versions of Bicycles made for an awkward ride. Ungainly, the cycles had a large wheel in the front and a small wheel in the back. In 1885, however, a more sensible model was introduced, one that resembled the modern cycle. Bicycling quickly became a national sport.

NOUNS, PRONOUNS, ADJECTIVES On the lines provided, identify each italicized word in the following sentences as an adjective (ADJ), a pronoun (PRO), or a noun (N). 1. As a young ________ girl, Susan B. Anthony was taught the beliefs of the Quakers _______, which ________ stress the equality of all________ people. 2. Many ________ people are working to clean up polluted ________ rivers and streams________ to make them more livable environments ________ for wildlife. 3. The cover________ of this________ book has seen better________ days. 4. Someone________ has filled the fruit________ bowl with oranges________. 5. Does that________ new bird feeder in the elm________ tree attract hummingbirds________.

VERBS Circle the verbs and verb phrases in the following sentences. Label each action verb (A) and linking verb (L). 1. Over the centuries, English has borrowed many words from other languages. 2. Because a newly borrowed word sounds unfamiliar, people sometimes do not hear it correctly.

3. The will pronounce the word and will spell it as if it had come from other, more familiar, English words. 4. The wrong spelling hides the true origin of the word and gives the false impression that its source is contemporary English. 5. The word woodchuck, for example, might have come from two English words, wood and chuck. 6. Actually, the origin of woodchuck is the Algonquian word otchek. 7. Another Algonquian word for a kind of animal is musquash. 8. When the English-speaking settlers adopted the word, it became muskrat. 9. In a similar way the Dutch word for cabbage salad, koolsla, became the English word coldslaw, and the French word for a kind of cart, cariole, is now the English word carryall. 10.

Linguists usually call this kind of word change “folk etymology.

ADVERBS On the answer lines, list in order the adverbs in the following sentences. After each adverb write the word or words it modifies and state whether the adverb tells how, when, where, or to what extent. 1. Greek and Roman myths frequently have supplied themes for art. __________________________________________________________________________ 2. Numerous recognized works of poetry, prose, drama, sculpture, and painting have used these almost universally known figures and tales. __________________________________________________________________________ 3. Such works of poetry as John Milton’s Paradise Lost and John Keat’s “Ode on a Grecian Urn” clearly reflect the influence of mythology. __________________________________________________________________________

4. During the Renaissance and the Neoclassical period, painters often chose subjects from mythology and dramatically depicted commonly known scenes of Greek and Roman myth and legend. __________________________________________________________________________ 5. Today, writers are equally indebted to classical mythology. __________________________________________________________________________ 6. Historically, myths also have been an amazingly rich source of names for animals, plants, and heavenly bodies. ___________________________________________________________________________ 7. Certainly, few of us would know the identities of any constellations if we were not able to use the mythological names that dramatically capture the shapes of these heavenly bodies. ___________________________________________________________________________ 8. Not unexpectedly, myths also have had rather important influences on our everyday language. ___________________________________________________________________________

PREPOSITIONS Circle the prepositions and underline the prepositional phrases in each of the sentences. 1. As of November 1963, there was a new island in the Atlantic Ocean near Iceland called Surtsey. 2. The island, about one square mile, was formed from the lava of a volcanic eruption that broke the surface of the ocean. 3. Two other islands, in addition to Surtsey, were formed at that time. 4. These islands, however, eventually sank beneath the sea. 5. Surtsey, however, survived, and plants grow on the small island.

6. In the Bering Strait, between Alaska and Siberia, there are two islands that are stepping stones between two of Earth’s largest land masses. 7. One of the islands, named Big Diomede, is owned by the Soviet Union; the other, Little Diomede, is owned by the United States. 8. According to many scientists, these two islands are all that remain of a land bridge that once joined Asia and North America. 9. How, however, the continents are separated by the icy waters of the Bering Strait.

CONJUNCTIONS Circle the conjunctions in the following sentences. 1. Amid the rivers and forests of tropical New Guinea, you can see not only the unusual riflebird but also the beautiful bird of paradise. 2. We considered several different albums before we finally chose one to give to Jeff for his birthday. 3. Although it seemed early in the season for swimming, we found that the water in the lake was cool but refreshing. 4. The small citrus grove is in the middle of the desert, but it flourishes because an intricate irrigation system supplies it with water. 5. So that we may eat by seven, we should quit skiing by six; moreover, we should leave time to stow our gear and change our clothes. 6. Before the game begins, the National Anthem will be performed either by the marching band or by a group of singers from the chorus.

INTERJECTIONS Underline the interjections in the following sentences. Circle any letters that should be capitalized and add commas and exclamation points where necessary. 1. Of course you know that you will be required to take at least five major subjects. 2. Wow that was an absolutely fantastic film. 3. No the painting is not straight yet; lower the left side a little. 4. No don’t give that book to James; it’s mine.


Sophomore English Summer Reading 2017 College Prep Please note: you must purchase the editions of the books that are indicated below. You cannot use an electronic version for class. College Prep Students will read the play A Raisin in the Sun, by Lorraine Hansberry. Expect to be tested at the beginning of the school year on the details of the play, and be prepared to provide some thoughtful analysis of the characters, plot, and themes.

This play can be found in The Norton Introduction to Literature, which you used during your freshman year and have been directed to retain for use next year. Transfer students can pick up a copy of the textbook by contacting Mr. Casey at [email protected] to arrange a time to pick it up, or they can use a different edition of the play. Honors, and High Honors students are responsible for reading The Power and the Glory, by Graham Green, Honors and High Honors students will also read The Stranger, by Albert Camus. The best way to approach this assignment is to look over the topics before reading each book and make appropriate notes while reading. These topics will be used for class discussion, as well as papers that your teacher may assign in September. Students may also be tested on the novels at the start of the school year. Such a test will likely include details from the novel and some thoughtful analysis of the plot, themes, and characterization. The Power and the Glory (Penguin Classics: ISBN 9780142437308) The Stranger (Vintage International: ISBN-10: 06979720200

ISBN-13: 9780679720201

Topics for The Power and the Glory 1. In Catholic teaching, the priest is seen as fulfilling the role of Christ when administering the sacrament. Does the “whiskey priest,” in performing his priestly duties, sacrifice himself in a way that is analogous to the sacrifice of Christ? Support your answer with specific details from the novel. 2. Compare and contrast the priest and the lieutenant in terms of values, motivations, and concern for the common man. In your response consider the dialogue between the priest and the lieutenant at the end of the novel. 3. Consider the following passage from near the end of Part Two, chapter one: But at the center of his own faith there always stood the convincing mystery – that we were made in God’s image. God was the parent, but He

was also the policeman, the criminal, the priest, the maniac, and the judge. Something resembling God dangled from the gibbet or went into odd attitudes before the bullets in a prison yard or contorted itself like a camel in the attitude of sex. He would sit in the confessional and hear the complicated dirty ingenuities which God’s image had thought out, and God’s image shook now, up and down on the mule’s back, with the yellow teeth sticking out over the lower lip, and God’s image did its despairing act of rebellion with Maria in the hut among the rats. He said “Do you feel better now? Not so cold, eh? Or so hot?” and pressed his hand with a kind of driven tenderness upon the shoulders of God’s image. Do you agree with the ideas expressed in this passage? How might these ideas impact your own life? How can one see the image of God even in those who commit the most deplorable and heinous acts?

Topics for The Stranger 1. What is your reaction to Meursault’s approach to life? How is your own approach to life similar to and/or different from his? What advice would you offer to him? Do you personally know any Meursault types? 2. Why, in your opinion, does Meursault kill the Arab? Is this killing justifiable? Does it remind you of other killings that you have read or heard about? Can you conceive of any situation in which you might commit a violent act? Would your violence be justified?                

Junior English Summer Reading

2017 Please note: you must purchase the editions of the books that are indicated below. You cannot use an electronic version for class. All junior students—College Prep, Honors, and AP—are responsible for reading In Our Time, by Ernest Hemingway (Scribner ISBN 9780684822761). Honors and AP students will also read Their Eyes Were Watching God, by Zora Neale Hurston (Harper Perennial ISBN 9780060838676). The summer assignment is meant to get you to think about the books and about the value and pleasure of reading, and to relate reading to your own life. Your assignment is as follows: Consider the topics listed below for each book. Your typed responses will be the basis for class discussion and papers that your teacher may assign in September. Teachers may check these written responses. You should also expect to be tested on this material at the start of the school year. The test may include details from the novel and some thoughtful analysis of the plot, themes, and characterization. Topics for Their Eyes Were Watching God 1) Janie is depicted as the hero of an epic journey. Discuss what Janie's journey depicts about Southern Black Life. Further, what discoveries does she make regarding her own identity? 2) Discuss the ways which the novel depicts the burdens placed upon black women particularly by men. 3) Discuss the importance of setting in the novel. How are the characters affected by where they live and what they do? Topics for In Our Time 1. Choose one of the stories (not the shorter vignettes) from In Our Time that deals directly or indirectly with war, and type a paragraph of at least twelve lines explaining how that story suggests the emotional and psychological impact of war. 2. Consider the following statement by Ernest Hemingway concerning his “Iceberg Theory” of writing: If a writer of prose knows enough of what he is writing about he may omit things that he knows and the reader, if the writer is writing truly enough, will have a feeling of those things as strongly as though the writer had stated them. The dignity of movement of an ice-berg is due to only one-eighth of it being above water. A writer who omits things because he does not know them only makes hollow places in his writing. –Ernest Hemingway What Hemingway means is that a story can suggest a great deal more than what it overtly states, and that a reader should be able to sense what the writer has left unsaid.

Choose two of the short stories from In Our Time (not the same story that you chose for topic #1) and two of the vignettes (the chapters that are italicized and placed between the stories). For each of the stories type a paragraph of at least twelve lines, and for each of the vignettes a paragraph of at least six lines, in which you try to identify what the writer has left unsaid and explain how those omissions help to illustrate Hemingway’s “Iceberg Theory.”                                        

Senior English Summer Reading 2017 The summer reading assignment is meant to get you to think about the books and about the value and  pleasure of reading, and to relate reading to your own life.    

Your assignment is as follows: Consider the topics listed for each book below, and the elements of  literature that you have learned in your English classes thus far here at SHP, as you read the book  assigned.  Your responses will be the basis for class discussion and papers that your teacher may assign  in September, so be sure to take careful and sufficient notes. You should also expect to be tested on this  material at the start of the school year. The test will likely include details from the novels and some  thoughtful analysis of the plot, themes, and characterization.   Keep in mind that, regardless of whether or not your teacher collects these responses,  they should be done carefully, thoughtfully, and neatly in order to be used effectively  for class discussions. 

College prep: Dubliners, by James Joyce (Penguin: ISBN‐10: 0140186476   







ISBN‐13: 978‐0140186475) 

Please note: you must purchase the edition of the book that is  indicated above.  You cannot use an electronic version for class.    Topic for Dubliners  In a letter to his publisher Grant Richards, dated May 5, 1906, Joyce explains that his central objective in  Dubliners [published in 1914] is to explore “the moral history of my country and I chose Dublin for the  scene because that city seemed to be the centre of paralysis” (262). As you read Dubliners, identify the  characters’ moral dilemmas, and how they arise, that lead them to feel physically or emotionally  paralyzed, that is trapped, by their circumstances, which include their country, their nationality, their  language, and/or their religion. You should also pay careful attention to the ways that Joyce’s characters  cope, or fail to cope, with the effects of their choices regarding their moral dilemmas.     Honors and AP: All AP/Honors Students must purchase and read Gulliver’s Travels by Jonathan Swift,  and only AP students will purchase and read The Mayor of Casterbridge by Thomas Hardy.      


Students should try to get the Signet Classic editions   of Gulliver’s Travels and The Mayor of Casterbridge.  



If that edition is not available, they should try to get the   Penguin Classics edition. 

Gulliver’s Travels Penguin ISBN‐10: 0141439491 


ISBN‐13: 978‐0141439495 



ISBN‐13: 978‐0451531131 


       Signet    ISBN‐10: 0451531132 

The Mayor of Casterbridge Penguin ISBN‐10: 0141439785 

ISBN‐13: 978‐0141439785 





          Signet ISBN‐10: 0451530926 

ISBN‐13: 978‐0451530929 


Topics for Gulliver’s Travels: for Honors and AP   1.

For Swift, learning and science, in order to be effective, had to have a practical as well as a  theoretical side and not be in direct conflict with nature. His “Voyage to Laputa” demonstrates  his mastery of scientific/intellectual satire. How is this demonstrated in the lifestyle on Laputa  and the experiments in Lagado? Are there scientific projects or intellectual trends today, which  could be similarly satirized? 


Swift once asserted that he hated mankind but that he loved individuals. Does this book  reinforce this idea? Do you feel that the fourth voyage, “A Voyage to the Houyhnhnms,” is too  harsh in its treatment of humans? Do you see Swift’s idea as being relevant in your own life, to  current affairs, and/or to films and television works today? 


The name “Gulliver” is a pun on “gull” or “gullible.” In what ways is Gulliver gullible? Cite  examples from all four journeys to show how Swift uses this trait to make his points. Have you  ever been gullible about something? What was the result? 


In one of his conversations with the King of Brobdingnag, Gulliver quotes the monarch with the  following observation:  That whoever could make two ears of corn or two blades of grass to grow upon a spot of ground  where only one grew before, would deserve better of mankind, and do more essential service to  his country than the whole race of politicians together. 


Based upon Gulliver’s experiences in Lilliput and on his defense of the political system of his own  country, would you agree or disagree with the King of Brobdingnag’s assertion? Would it be valid  in terms of America today? Explain. 

  Topics for The Mayor of Casterbridge: for AP only  

What is the significance of setting in this novel? Consider especially the ancient Roman

History Department Summer Reading Assignments Summer 2017

FRESHMAN YEAR World History—College Prep : No required reading World History—Honors: Steven Pressfield, The Afghan Campaign, (available in both paperback and eBook formats)

Human Geography—Advanced Placement: 1) Students should thoroughly read the course description at AP Central.[http://apcentral.collegeboard.com/home] 2) Colin Woodard, American Nations: A History of the Eleven Rival Regional Cultures of North America, 2011, Penguin Books (paper), ISBN 978-0-14-3122029

SOPHOMORE YEAR World History 2—College Prep: No Required Reading World History 2— Honors: Shusaku Endu, Silence, (Translated by William Johnson), Taplinger Publishing Company, 1980 (paperback)

World History—Advanced Placement (Mr. Hulsy): J.R.McNeill & William H. McNeill, The Human Web, W.W. Norton & Company, paperback,  2003, Introduction and Chapters I through IV, pp. 3‐115. 

World History—Advanced Placement (Mr. McMahon): 1) Students should thoroughly read the course description at AP Central. [http://apcentral.collegeboard.com/home] 2) Tom Standage, An Edible History of Humanity, 2009, Walker Publishing Co., ISBN-13: 978-0-8027-1588-3 3) Garry Wills, What Paul Meant, 2006, (for Theology High Honors)  

JUNIOR YEAR US 2—College Prep: Lars Anderson, The All Americans

US—Honors: 1. Taylor, Colonial America: A Very Short Introduction, 2012, ISBN-13: 9780199766239

US—Advanced Placement: 2. Taylor, Colonial America: A Very Short Introduction, 2012, ISBN-13: 9780199766239 3. Toni Morrison, A Mercy 4. Henretta, et al, America’s History, Chapters 1 & 2 Students should submit an outline of Chapters 1 & 2 online at turnitin.com before the first day of class. Students should register at turnitin.com for class 6491580, Password Pirate

SENIOR ELECTIVES Economics—College Prep: Microeconomics—AP:

none none

Modern European History—AP: Students should thoroughly read the course description at AP Central. [http://apcentral.collegeboard.com/home] US Government and Politics-AP: Jack N. Rakove, Original Meanings, Random House, 1996. US Government and Politics-Honors David O. Stewart, The Summer of 1787, Simon & Schuster, 2007 US Government and Politics-CP: No Required Reading 1.

background of Casterbridge and its isolated rural position. Does Hardy ever suggest that the  environment, especially its natural characteristics, can control, influence, or reflect human  activity? Have you ever felt this about some place or environment in your own life, either in  positive or negative terms? 


The narrator of The Mayor of Casterbridge makes the following observation about the  protagonist, Michael Henchard: “But most probably luck had nothing to do with it. Character is  fate.” How do you define “fate” or “destiny”? How true is this statement as it relates to  Henchard’s rise and fall? How much of his “tragedy” is caused by his own actions and how much  is caused by luck or fate? 


In Hardy’s work, evidence of irony is often used to underscore what he believes to be the  unstable condition of human existence. This often happens when seemingly insignificant events  turn out to have dreadful, but totally unexpected, consequences. Cite and explain several  examples of this “unpredictability” from the novel. Has this concept ever affected your own life?  Explain. 


Henchard’s misfortunes reflect upon his selling of his wife at the start of the novel. This  demonstrates the ideas that Hardy believed that, in life, there is always a price to pay for one’s  actions. Do you agree with this idea? Did you ever decide to do something for which you had to  pay a price at a later time? 


Theology Department  Freshman Honors/Seton Scholars (There is no assignment for Freshman CP) Introductory Note Freshman Honors and Seton Scholars are required to read the first three chapters of Velvet Elvis, by Rob Bell. Writing for a culture that is more familiar with mistaken views of Christian tradition and less aware of authentic interpretations of the bible, Rob Bell seeks to revive the spirit and energy of the time-honored Christian search for God and truth in the experiences deep within all of us and in the wisdom of Tradition. He calls upon the church tradition of communal practices of interpretation of the Scriptures as it is informed by today’s insights from historical research. Bell speaks the language of today’s youth culture. His references range from first-century rabbis to twenty first century rock bands. Discussion of his book will serve as an introduction to the problems and method of theology. Please read the first three chapters. Then write a brief response to the reading (no more than two pages) in which you include the following:

1. Comment on Bell’s ideas about religious experience and the use of the bible. What problems does he see with the way that many people attempt to interpret Scripture? What does he see as a more beneficial and more correct approach? 2. Do you agree with his understanding of the problems of being Christian today? Identify and discuss several examples. Do you see any additional problems that he has not mentioned? 3. Evaluate the “answers” that Bell offers. Do you find them to offer good direction in addressing the problems that he identifies? Why or why not?

Departmental Note ‐ The first days of classes will be Thursday, September 7 and Friday, September 8.   Your theology teacher will give you his/her turnitin.com account information on that day.  The paper  must be submitted to turnitin.com by 8:45 am on Monday, September 11.  (Your teacher also has the  right to ask for a hard copy of the paper on Monday the 11th).   The grade on the paper will be  incorporated into your first trimester average. Your grade on the paper will be lowered by one full grade  for each day late, up to three days.  Failure to submit the paper on the 4th day (Friday, September 15)  will result in a 10 point deduction from your First Trimester average.  Even at this point, the essay is a  course requirement. Failure to hand it in may jeopardize the student’s position in an honors class  section.  The 10 point deduction for failure to do the paper will still be assessed if the student is  moved to a CP section.   



 Sophomore Honors

(There is no Assignment for Sophomore CP) Sophomore Seton Scholars should consult the Social Studies Summer Assignments

The sophomore honors summer assignment is based on a reading of the biblical book known as Acts of  the Apostles. This book is similar in format to the gospels, but deals with the emergence and  development of the early Church (the book is often seen as a “sequel” to the Gospel of Luke).  This  assignment is meant to “set the table” for the Church Studies course which begins in September.  You  will not be reading the entire book, but a little more than half (Acts 1:1‐15:35)  We would like you to read from the translation known as New American Bible, Revised Edition.   (NABRE).  If you do not have this version at home, it is available online on the website of the US  Conference of Catholic Bishops:  http://www.usccb.org/bible/books‐of‐the‐bible/index.cfm#Acts.      In addition to the reading from Acts itself, the student needs to review the following web page:   http://catholic‐resources.org/Bible/Acts.htm.  This page was designed by Fr. Felix Just, S.J., the President  and Executive Director of the Loyola Institute for Spirituality in Orange, CA.  Fr. Just holds a Ph.D. in New  Testament Studies from Yale University, and has taught at Loyola Marymount University (Los Angeles),  the University of San Francisco, and Santa Clara University.  His website provides excellent resources for  Biblical study, and the page for Acts of the Apostles is a fine example.        On Fr. Just’s webpage, there are 5 “Questions for Review and Discussion”.  After you have read the  assigned Acts passage and reviewed Fr. Just’s webpage, compose answers to those 5 questions, as well  as the question listed below:    6.  Which individuals in Acts are portrayed as responsible for preaching the gospel to new audiences  (other than Jews)?  Cite examples.      The expectation is that the paper be at least 2‐3 pages, and be presented in the standard MLA format.      Departmental Note ‐ The first days of classes will be Thursday, September 7 and Friday, September 8.   Your theology teacher will give you his/her turnitin.com account information on that day.  The paper  must be submitted to turnitin.com by 8:45 am on Monday, September 11.  (Your teacher also has the  right to ask for a hard copy of the paper on Monday the 11th).   The grade on the paper will be 

incorporated into your first trimester average. Your grade on the paper will be lowered by one full grade  for each day late, up to three days.  Failure to submit the paper on the 4th day (Friday, September 15)  will result in a 10 point deduction from your First Trimester average.  Even at this point, the essay is a  course requirement. Failure to hand it in may jeopardize the student’s position in an honors class  section.  The 10 point deduction for failure to do the paper will still be assessed if the student is  moved to a CP section.   

Junior Honors (There is no Assignment for Junior CP)   Junior year begins with a study of the Old Testament, and the goal of the summer assignment is to prepare the students for this Old Testament study while simultaneously getting some sense of the approach to Scripture study presented at Seton Hall Prep. Junior Honors Students are to read The Jewish Approach to God, by Rabbi Neil Gillman, Jewish Lights Publishing. They are to submit answers to the following questions found below based on the reading. The paper should be presented in the standard MLA format.

Questions for Reflection Based on The Jewish Approach to God:

Intro  Do you think that God can be known?  Which of the two ways of talking about God mentioned in the book are you most comfortable with?  Why?  Explain why it is necessary to use metaphors/symbols/analogies to talk about God? Of these, which is  your favorite metaphor/symbol/analogy?  Explain the idea the “Torah is how our ancestors understood God’s will, not God’s will per se.”    Chapter 1  How does Rabbi Gillman’s conception of God as one resonate with your own?  Why do you think the Shema is so important for Judaism? Should it be equally so for Christians?  Do you agree with Gillman that God is lonely? Explain.    Chapter 2  Evaluate Gillman’s claim that “once God created human beings free, God simply had to accept the  inevitable implications of that freedom.”  Has it ever seemed to you, as in Psalm 44, that God may be sleeping?  Gillman argues, consistent with classic Christian theology, that God’s power is self‐limiting. Evaluate this  insight in light of your own life experience.    Chapter 3  Do you feel that it’s appropriate for people to argue with God as Abraham does? Do you?  How do you personally experience God’s pathos?  Gillman argues that for God to be God we must be in relationship ‐ sometimes closer, sometimes  farther. In this light, he uses images from scripture such as spouse, parent and lover. Do these ideas  make sense to you? How do they reflect your experience?    Chapter 4  Read Psalm 91 and react to the images of God used by the psalmist in light of Gillman’s reflection.  Which of the covenantal metaphors for God discussed by Gillman make most sense to you right now?   

Chapter 5  Do you think that God, in some way, “welcomes our challenge, even our impiety?” Why?  Evaluate Kaplan’s rejection of the omnipotence of God.  Do you sometimes experience God as good and sometimes as bad? Reflect on how.    Chapter 6  Briefly recount, in your own words, how the Jewish idea of punishment (and God) evolved in the Bible.  Gillman references the point that “God must forgive because God above all knows what it means to be a  human being”.  How can this be understood from a Jewish point of view?  How can this idea form the  basis for a dialogue between Christians and Jews?    Chapter 7  According to Gillman Genesis answers four questions, or poses four major truths about God’s creating.  What are they? What sense do they make to you?    Chapter 8  How are the experiences of Torah for Jews and Jesus for Christians similar?  Reflect on the notion of chosen people. How might it be acceptable to think of one’s own people as a  chosen people? What caution must one keep in mind?   Reflect upon the three quotes (on each from Heschel, Rosenzweig, and Eisenstein) that Gillman offers  on revelation. What sense do you make of them?    Chapter 9  Gillman argues that the ways Jews remember Exodus are analogous to the Christian idea of Jesus’  resurrection. React to that.  Compare the three motifs of Jewish eschatology with your own understanding of what will happen in  “the end.”  React to the ideas of Ein Sof and Shekinah as symbols to describe the unknowable and all  powerful/unknown limited nature of God.  How can it be said that Christians work to unify the Yod Heh with Vav Heh?  (Notice that the questions  asks how Christians do this, not how Jews do it.)    Departmental Note ‐ The first days of classes will be Thursday, September 7 and Friday, September 8.   Your theology teacher will give you his/her turnitin.com account information on that day.  The paper  must be submitted to turnitin.com by 8:45 am on Monday, September 11.  (Your teacher also has the  right to ask for a hard copy of the paper on Monday the 11th).   The grade on the paper will be  incorporated into your first trimester average. Your grade on the paper will be lowered by one full grade  for each day late, up to three days.  Failure to submit the paper on the 4th day (Friday, September 15)  will result in a 10 point deduction from your First Trimester average.  Even at this point, the essay is a  course requirement. Failure to hand it in may jeopardize the student’s position in an honors class  section.  The 10 point deduction for failure to do the paper will still be assessed if the student is  moved to a CP section.    Seniors (There is no summer assignment in Theology for seniors)

SHP Math Department Summer Assignment 2017    The Summer Assignment is to be done neatly on loose‐leaf paper and is to display all work, including  details and diagrams as needed. Please see attached for examples and due dates related to your specific  assignment. Any student who fails to submit the Summer Assignment will be removed from the AP  Program.    AP Statistics: 

(no assignment for Statistics CP) 


Handout distributed in school (and attached). 


Value:  50 total points. See attached for breakdown of points. 

  AP Calculus AB/BC:   



Handout distributed in school (and attached).           Value: 100 total points. See attached for breakdown of points. 

  * AP Calculus AB and AP Calculus BC have the same assignment.  * There are no summer assignments for any other courses.                        

AP Statistics Summer Assignment – 50 point quiz grade ‐ Due first day of class    Important Note:  The Chapter 1 material in this assignment will not be covered in class.  You will be  responsible for it and may come to help class if you have questions.  This material will be included on the  Chapter 1 Test    You will need a textbook – get one from Mrs. Sgaramella in Room 208 before the last day of school.    If at any time you have questions, feel free to email [email protected]     General information    o Assignment is due on the first day of class. 10 points will be deducted from the  assignment for every school day it is late, regardless of whether our class meets or not.      o You may handwrite (neatly) or type your answers.  Graphs must be drawn by hand  unless otherwise noted.    I. You will collect your own set of data that will be used throughout this assignment.  You are to  create a table with nutrition information for 25 food items from the restaurant of your choice  using their website, A sample table is below.       Record the official menu name for the item in the first column and the type of item in the  second column (for example burger, side, vegetable, sandwich, or dessert).  Plan to have 4‐5  different categories in the second column.  In the 3rd through 5th columns, record the  number of calories, total fat (in grams), and total carbs (also in grams) per serving for each  item.   Be sure to use a variety of different types of food in the table (i.e., don’t use all burgers).      Read the Introduction Chapter – pages 2‐5 (stop at the Activity on hiring discrimination – we will do this  in class) and use the data in your table to answer the following question:    1. Food Data Table. (4 points)  2. Answer question #4 on page 7 USING YOUR DATA instead of the Roller Coaster data in the  book.  (6 points) 

  Part I Sample Table  Name of Menu  Item 

Type of food 

Calories per  serving 

Fat (g)  

Protein (g) 

Per serving 

Per serving 

Bob’s Giant Burger 

Burger (or  Sandwich) 




Bob’s Baby Fries 




Bob’s Cole Slaw 



Jenny’s Apple Pie 



Bobby’s Chicken  Nuggets 





Displaying Categorical Data:  Read Section 1‐1, pages 8‐12 (stop at Two Way Tables and Marginal  Distributions – we will cover this in September).    2. Search “misleading graphs” in Google images (or any other location on the internet),  select a graph (preferably not the very first one you see), insert it into your document  (this one does not have to be hand drawn) and explain why it is misleading and what  you would do to correct the problem. (4 points)  3. Draw a bar graph using the categories in the second column of your table. (4 points) 


 Displaying Quantitative Data with Graphs ‐ Dotplots:  Read Section 1‐2, pages 27‐32    4. Create a dot‐plot using your Fat data (instructions on page 27).  Use whatever scale on  the x‐axis that you feel is appropriate. (4 points)  5. Are there any potential outliers in your data?  If so which foods are they?  (4 points) 


Displaying Quantitative Data with Graphs – Stemplots:  Read Section 1.2, pages 33‐35 (stop at  Histograms)    6. Create a hand‐drawn stem‐plot using your protein data (instructions are in the example  on page 33) (4 points) 



  Displaying Quantitative Data with Graphs – Histograms:  Read pages 35‐42   

7.  Create a histogram by hand of your calorie (instructions are in the example on page 35.)  (4 points)  8.  Would you say that the data values are close together, spread apart a little bit, a great  deal, or just a fair amount?  This is how we measure the “spread” in a dataset. (4 points)    Note:  we will cover creating histograms on the graphing calculator in September – you are not required  or expected to be able to do it for the summer assignment.    V.

Describing Quantitative Data with Numbers – mean and median.    Read Section 1‐3 pages 50‐55 (stop at Interquartile Range).    9.   Create a table similar to the one below showing the mean, median, and shape for each  set of your data.  You may calculate the mean and median by hand or using a  calculator/computer. (6 points)    SHAPE: At this point, you have a dot‐plot of the fat grams, a stem‐plot of your protein,  and a histogram of your calorie data.  When we have a skewed shape to a distribution,  we use the median as a measure of center.  When the distribution is symmetric, or bell‐ shaped, we use the mean as a measure of center.   




  skewed to the right                                 skewed to the left                                   bell‐shaped       
















  AP Statistics – Examples of acceptable answers/formats    All written answers should be in paragraph form or in a neat bullet list, where appropriate.    Sample Answer for Exercise #4 page 7 

(a) The individuals are roller coasters opened in 2009.   (b) The categorical variables are Roller coaster (the name of the coaster), type (steel or wood) and the  design (sit down, flying). The quantitative variables are height (in feet), speed (in mph) and duration  (in seconds). (c) The highlighted roller coaster is the Prowler, a wood, sit‐down type coaster. It’s  height is 102.3 feet, its speed is 51.2 mph and the duration of the ride is 150 seconds.    Examples of correct graphs for Exercises in your textbook (note your graphs will be hand‐drawn):    Exercise 11 page 22‐23     Exercise 37 page 42                              Exercise 55 page 46 



AP Calculus AB/BC Summer Assignment    Part I:   Memorize the attached special angle table for a quickly timed 50‐point quiz during the first week  of school.    Part II:  Memorize the attached set of graphs for a quickly timed 50‐point quiz during the first week of  school.    Special Angles                                   




Language Department   

La clase de AP Lenguaje y Cultura  Fecha de entrega el 15 de julio    La suerte es la sinergia entre la oportunidad y la preparación.  Prepárate y que tengas muchas oportunidades en la vida.    El objetivo del trabajo de verano es desarrollar tus habilidades comunicativas durante el verano para  salir bien en la clase de AP y en el examen de AP. Para tu preparación, este verano vas a practicar la  comunicación interpretativa leyendo varias lecturas y escuchando conversaciones y reportajes.   También vas a escribir relatos de lo que has escuchado y leído, para desarrollar todas tus habilidades  con el idioma.    Todo el trabajo de verano es para el 15 de julio. Por favor, escribe todos los resúmenes a máquina, a  doble espacio, en formato MLA. Te pido que hagas todo el trabajo con cuidado para que aprendas  mucho español y que goces de ser bilingüe   


The AP Spanish Language and Culture Exam Format 



Primera parte: Comprensión auditiva y resúmenes (60 puntos) 

La mejor preparación para comprender el español hablado es practicar, escuchar y responder a lo que  has escuchado. Para comprender mejor, es imprescindible tener experiencias repetidas de oír y  escuchar. Por lo tanto, tu misión es:    Escuchar 3 PODCASTS y escribir un resumen de 80 palabras para cada podcast    

Escucha los 3 podcasts de www.notesinspanish.com  (Advanced).   Después de escuchar, escribe un resumen de 80 palabras que describe las ideas principales y tu  reacción a la información.   Cada podcast dura 10 minutos – escúchalos tantas veces como sea necesario para tener una  buena comprensión.   

Ver colecciones de REPORTAJES NOTICIEROS EN VIDEO (60 puntos)  y escribir un resumen de 80 palabras para cada coleccion de reportajes de 30 minutos  (90 minutos en total)   Escucha y observa reportajes en español 3 distintas veces por 30 minutos y después   escribe un resumen de 80 palabras (para cada colección de reportajes de 30 minutos).     Sugiero BBC Mundo (http://www.bbc.co.uk/mundo) y también Radio Naciones Unidas  (http://www.unmultimedia.org/radio/spanish/)  porque estos sitios aparecen en   el examen de AP.    Toma apuntes y escribe un resumen para cada 30 minutos de ver los reportajes.   El resumen debe incluir la fecha, el nombre de la fuente, la duración y detalles   del reportaje: ¿Quién? ¿Qué? ¿Cuándo? ¿Dónde? ¿Cómo?  y también tus propias  reacciones en 80 palabras.   


 Segunda parte: Comprensión de lectura y resúmenes (60 puntos) 

En el final de este documento hay una colección de cuatro pares de artículos cortos sobre varios temas.  Cada dos articulos están relacionados de una manera; por ejemplo, los primeros dos artículos (1a y 1b)  tratan del turismo y su impacto en los sitios visitados por los turistas.  El tercer y el cuarto artículo (2a y  2b) tratan de la música y su impacto en la vida de los jóvenes.  Para cada articulo, por favor haz lo siguiente:     

Resume cada artículo en 80 palabras en tus propias palabras (ocho resúmenes). El resumen  debe incluir tu reacción personal a lo que has leído.   Aprende el vocabulario clave y las palabras no conocidas.  Escribe los resúmenes a máquina, a doble espacio, en formato MLA.   Al final del resumen, compara y contrasta la información con el otro artículo de la pareja  y  anota la comparación en un diagrama Venn.  En otras palabras, compara y contrasta artículo #1a  con #1b; #2a con #2b, hasta la última pareja de artículos (#4a con #4b). 

Los ocho resúmenes con las comparaciones serán calificados usando una rúbrica que se basa  50% en la descripción del trabajo y su habilidad de interpretar las lecturas y 50% en escribir  usando tu gramática y ortografía correcta. (Cada resumen vale 20 puntos y cada comparación en  Venn vale 20 puntos)  Toma apuntes y colócalos en un diagrama Venn para comparar y contrastar los dos artículos.  Usa cuatro diagramas Venn para los cuatro pares de artículos. Un ejemplo sigue:  



III.  Tercera parte: El repaso de la gramática y el sitio web de AP Central  Basado en los resultados de años pasados, necesitas repasar lo siguiente enlínea.      

The past participle and the compound tenses  The subjunctive, especially the imperfect subjunctive with the conditional   Future tense and the future perfect tense  

APÉNDICE    Los artículos para la Segunda Parte: Comprensión de lectura y resúmenes  1a Plan para preservar Machu Picchu 





p. 1 

2b Turismo con los indios Kuna   




p. 2, 3 

2a El talento del coro “Fabrettino” 





p. 5 

2b Jóvenes de la Sinfónica… 





p. 6 

3a La ciencia lo avala: reírse mejoa la salud 




p. 7 

3b El que ríe vive mejor  



p. 8 







4a Perú: El repliegue del glaciar   




4b Cambio climático afectará especialmente Latinoamérica 

p. 9   

p. 10 

  CÓMO ENTREGAR LOS TRABAJOS    Por favor, mándame todo a mi correo electrónico, [email protected], antes del 15 de julio. Cualquier  pregunta o duda, escríbeme; no me molestarás. Que disfrutes del verano y que aprendas mucho.    Sra. de Mainardi  [email protected]   

Writing the Organized Essay   


PLEASE THINK BEFORE YOU WRITE!  Here’s how:     

Write out your THINK in English and check  for a logical progression of ideas. Once you  are satisfied that your THINK is persuasive...  Write your THINK in Spanish. Use your  dictionary. Then you are prepared to...   WRITE your composition without stopping  so you don’t lose your train of thought.  Never write your composition in English  first because translating is difficult and  anyway, your goal is to WRITE in Spanish!  Finally...  REVISE your composition. If you are able to  come back to it later, you will find it less  perfect than you thought, because...  YOUR FIRST DRAFT IS YOUR WORST  DRAFT! Don't let anyone else read it! 

  English (write sentences): 









Look for the following elements in your composition.  Circle the number next to each category. (5= yes,  estupendamente; could not be better!) 




5 4 3 2  T = TITLE Does the title relate to the  composition? Does it interest you? 


  5 4 3 2  H = HOOK Does the introductory sentence  hook you into reading further?    5 4 3 2  I = IDEA Is there one and only one main idea  in the first paragraph? (What is it?)    5 4 3 2  N = NEXT IDEA Does the next paragraph  also have only one main idea? (What is it?)    5 4 3 2  K = KILLER ENDING Does the ending make  your main point forcefully?  Your composition must show purpose (50% of your  score) and language mastery (50% of your score).   


I            N            K 


  Spanish (translate JUST those sentences):  T         







Becoming a Discerning and Happy Reader in Spanish  AP Spanish Literature Summer Assignment    La suerte es la sinergia entre la oportunidad y la preparación.  Prepárate y que tengas muchas oportunidades en la vida.    Este verano vas a leer cuentos cortos de Álbum. También vas a leer …y no se lo tragó la tierra, Los  funerales de la Mamá Grande y dos novelas que elijas tú. Mientras más leas, mejor.    1. Álbum. Favor de leer los siguientes cuentos cortos que se estudian en la clase de AP:    “El hijo” p 96  “Mi caballo mago” p 139  “No oyes ladrar los perros” p 191  “Dos palabras” 208    Luego, por correo electrónico con el deletreo comprobado (spellchequeado), por favor mándame fichas  bien pensados para los cuatro cuentos. Si prefieres, en lugar de la ficha, puedes escribir un THINK (en  inglés y en español) para una idea buena tuya que te vino al leer el cuento. (80 puntos) Para el 15 de  julio.    2. Lee Los funerales de la Mamá Grande. Este autor, Gabriel García Márquez, es posiblemente el  inventor del cuento corto moderno. Favor de hacer dos fichas: una para el cuento “La siesta del  martes”, que es el favorito del autor (y que aparece en el examen AP) y una para el libro entero. Trata  cómo forman los cuentos un libro cohesivo. (40 puntos) Para el 15 de julio.    3. Lee …y no se lo tragó la tierra, de Tomás Rivera, un librito de la vida de un niño chicano de familia de  trabajadores migrantes. Interesante ver cómo estas viñetas forman una obra completa. Esta obra no es  como parece. Favor de hacer tres fichas, para las dos viñetas de este libro que aparecen en el examen 

de AP, la epónima “…y no se lo tragó la tierra” y “La noche buena”, y una para el libro entero. (60  puntos) Para el 15 de julio.    4. Lee dos o tres novelas que prefieras tú. Mejor leer cuatro. La idea es que te pongas feliz y cómodo con  la lectura. Muéstrame los libros antes del final del año, por favor. Para el primero de septiembre.    Cualquier pregunta o duda, llámame o escríbeme. No me molestarías. Que disfrutes del verano.  Sra. Vargas  [email protected]  Rivera, Tomas. …y no se lo tragó la tierra. Houston: Arte Público Press, 1996. Impresión.  García Márquez, Gabriel. Los funerales de la Mamá Grande. Mexico, D.F.: Editorial Diana, 1986. Impresión.  Renjilian‐Burgy, Joy, and Rebecca M. Valette. Album. Boston: Houghton Mifflin, 2005. Impresión. 

Writing the Organized Essay   




Here’s how: 


   

Write out your THINK in English and check  for a logical progression of ideas. Once you  are satisfied that your THINK is persuasive...  Write your THINK in Spanish. Use your  dictionary. Then you are prepared to...   WRITE your composition without stopping  so you don’t lose your train of thought.  Never write your composition in English  first because translating is difficult and  anyway, your goal is to WRITE in Spanish!  Finally...  REVISE your composition. If you are able to  come back to it later, you will find it less  perfect than you thought, because...  YOUR FIRST DRAFT IS YOUR WORST  DRAFT! Don't let anyone else read it! 

  English (write sentences): 









Look for the following elements in your composition.  Circle the number next to each category. (5= yes,  estupendamente; could not be better!) 



5 4 3 2  T = TITLE Does the title relate to the  composition? Does it interest you? 






5 4 3 2  H = HOOK Does the introductory sentence  hook you into reading further? 




5 4 3 2  I = IDEA Is there one and only one main idea  in the first paragraph? (What is it?) 




5 4 3 2  N = NEXT IDEA Does the next paragraph  also have only one main idea? (What is it?) 




5 4 3 2  K = KILLER ENDING Does the ending make  your main point forcefully? 


Your composition must show purpose (50% of your  score) and language mastery (50% of your score). 





  Spanish (translate JUST those sentences):    T      K  Ficha para acordarse de una obra narrativa (prosa)    

Título, Autor:   Año y época literaria en que se escribió:   Género: cuento corto  Estilo:   Códigos culturales, históricos, religiosos, literarios, biográficos:                 

   Fondo (el mensaje) 

Forma (el medio) 

Marco escénico:  

Tipo de narrador:  


Cita favorita:  








Tono (adjetivo):  

El tema y algunos subtemas, en oraciones completas:  

Recursos literarios, con citas:  




Cita 1.  






Cita 2.  






Cita 3.  






Cita 4. 






Cita 5.  




  Cita 6.    




Ficha para acordarse de un poema     Título, Autor:   Año y época literaria en que se escribió:   Género: poema  Estilo (tipo de poema):   Códigos culturales, históricos, religiosos, literarios, biográficos:                 

   Fondo (el mensaje) 

Forma (el medio) 

Marco escénico:  

Cita favorita:  



Oposiciones binarias: 

Grupos semánticos y tono (adjetivo):  


Métrica y rima: 



El tema y algunos subtemas, en oraciones completas:  

Recursos literarios, con citas:  




Cita 1.  






Cita 2.  






Cita 3.  




Cita 4.  






Cita 5.  




  Cita 6.    




Ficha para acordarse de una obra dramática (teatro)     Título, Autor:   Año y época literaria en que se escribió:   Género: obra de teatro  Estilo:   Códigos culturales, históricos, religiosos, literarios, biográficos:                 

   Fondo (el mensaje) 

Forma (el medio) 

Marco escénico:  

Indicaciones del dramaturgo y versificación, si la hay:  




Cita favorita:  






Tono (adjetivo):  

El tema y algunos subtemas, en oraciones completas:  

Recursos literarios, con citas:  




Cita 1.  






Cita 2.  






Cita 3.  




Cita 4.  






Cita 5.  




  Cita 6.    


3575 – AP Latin Summer Assignments 1.

Due: Thursday, June 30 DBG 4.25-4.28 (62 lines)


Due: Monday, August 1 DBG 4.29-4.33 (63 lines)


Due: Thursday, September 1 (at your orientation) 4.34-4.36 & 5.24-5.25 (62 lines)


Due: Wednesday, September 7 (first day of class) Read (in English): DBG 1 (entire text) DBG 4 (entire text) DBG 5 (entire text) DBG 6 (entire text) DBG 7 (entire text)

Email all assignments to [email protected]

PLEASE include all Latin text with your translations. You may use this link to copy and paste text. http://www.forumromanum.org/literature/caesar/gallic.html

Do NOT be tempted to utilize the provided translations.

Should you have any questions, please contact Mr. Denk at [email protected]


Italian 5 Summer Assignment From Racconti Romani written by Alberto Moravia 1. “Scherzi di Ferragosto” pgs.207-226 2. “Caterina” pgs.251-256 (read and summarize in Italian) From Prosatori del Novecento written by Moravia/Vittorini 1.“Una donna sulla Testa” pgs.1-12 2. “Il Viaggio” pgs15-20 (read and summarize in Italian) From Italian Folk Tales author unknown 1. “Lionbruno” pgs.7-30 (read and translate) From Avventure in citta’ witten by Costantino/Wald 1. La Vendetta dei mostri pgs.10-17 2. La Vetrina vuota pgs.36-43 3. Aiuto auito! Pgs.92-97 (read and complete all exercises) Study of Italian Cinema- Neorealism 1. “Ladri di Bicicletta” 1948 Vittorio De Sica 2. “La Strada” 1954 Federico Fellini (view and summarized in Italian) Italian Grammar: From Italian for You Translation pg 4 ex B pg.12 ex A pg.17 ex B pgs.20-21 ex 1 ex 2 ex 3 pg.31-32 ex B pgs.36-37 ex A 58   

AP Chinese 2017 Summer Assignment AP 中文课程2017年暑假功课

The goal of the summer assignment is to familiarize you with the content of the AP exam and to give you practice in the various areas that will be covered.

All students in AP Chinese are required to complete the summer assignment below. Complete the portions below by the corresponding deadlines. The summer assignment will count as your first large assessment (test) grade.

Part 1: Chinese Article Reading and Reactions (3 Articles), DUE 7/15

20 points

Part 2: AP Practice Exam, Multiple Choice Section, DUE 7/31

20 points

Part 3: AP Practice Exam, Open Ended Writing & Speaking, DUE 8/15

20 points

Part 4: Film Viewing and Reaction Essay, DUE 8/31

20 points

TOTAL: 60 points

AP Chinese Exam: Background Information According to the AP Chinese and Culture course website, the AP course is designed so that:

Students learn about various aspects of contemporary Chinese society, including geography and population, ethnic and regional diversity, travel and transportation, climate and weather, holidays and food, sports and games, and current affairs. They also explore the realm of Chinese societal relationships, examining how individuals interact with family members, elders, and peers, and integrate this knowledge into their interpersonal communications. The course introduces students to significant persons, products, and themes in Chinese history. This introduction may touch on such topics as Chinese contributions to philosophical thought, government institutions, and artistic pursuits (e.g., calligraphy, painting, literature, and music, as well as folk arts


and culture). The course also views Chinese culture in an international context. Students learn that Chinese culture has spread to many parts of the world, influencing and being influenced by the global community. For example, they develop an awareness of China’s role in issues of global importance, concerning areas such as energy and the environment, economics, and politics. The course helps students broaden their worldview by comparing Chinese cultural products, practices, and perspectives with those of their own society. With this background, students can ultimately move beyond a basic knowledge of the products and practices of Chinese culture to an understanding of how these products and practices reflect a Chinese way of viewing the world.

The exam is divided into 2 sections, each worth 50% of the test's value. Please take a look below to see the breakdown of each section:




2017 AP CHINESE SUMMER ASSIGNMENT (4 PARTS) Part I: Chinese Article Reactions Due: July 15, 2017 Submission Instructions: Complete all 3 summaries per the instructions below and combine into one document, then upload to turnitin.com. Make sure you include the titles and links of the articles you have chosen for reference.

Visit the Slow Chinese or Chinese Reading Practice website and pick any 3 articles you would like to read at the intermediate (HSK 3 or 4) level. Then complete the following for each article: ● Include the title and link to the original article ● Write a 100 character summary of the article. ● Glossary and example sentences: Pick at least 5 new words or phrases from each article and write an example sentence with each word. ● Venn Diagram: compare American culture and Chinese culture in terms of this article ● Explain your reaction towards the article. Is what happened good, bad, interesting, etc, and why?

Example of a Venn Diagram:


Sample Writing Assignment:

中国打破世界纪录 造世界上最大的伞 China Smashes Record for World’s Largest Umbrella

Link: www.examplewebsite.com/articlename.html 64   

Summary: 在江西九江星子县的一家公司做出了世界上最大的伞。这把伞很大:致敬22.9米,高 14.39米,重5.7吨,可以覆盖418平方米!印度也作出了一把大伞,可是比中国的伞更小。 再说,中国的伞不但大,而且很漂亮因为它有很多颜色。很多人站在伞下逼样呢。 Reaction: 我觉得这篇文章很有意思。中国的很大伞很好因为伞很有特色、很漂亮。此外,因为这个 公司到了在吉尼斯世界纪录中的一席之地,所以最大的伞对这个公司有好处。

Glossary: 伞 (sǎn) – umbrella 因为春天的时候下很多雨,你应该买一把伞。 打破(dǎpò) - to break  中国打破世界纪录  覆盖 (fùgài) – to cover (area) 这把大伞可以覆盖418平房米。 印度 (Yìndù) – India 中国的大伞比印度的大伞更大。

Venn Diagram: 美国文化 

美国和中国的文化 (Same)

 (Different)  我们都用伞 ● 下雨的时候才用伞 ● 美国没有中国那么大的 伞

中国文化 (Different) ● 为了防晒,女生也带伞 ● 中国的伞很有特色


PARTS 2 and 3: AP Model Exam ● PART 2: Multiple Choice, AP Section 1 ○ (Reading and Listening Section) Due: July 31, 2017 ● PART 3: Open Ended, AP Section II ○ (Writing and Speaking) Due: August 15, 2017 Complete the AP Chinese practice exam at the link below. Complete the test without looking up words or getting help. This practice will give you a good idea of the test format and the difficulty of the test. DON'T WORRY - the test may seem impossible, but you will be learning a lot over the next year to help prepare. After you finish the test, you can check your answers with the key and go back to figure out where you went wrong.

Part 2: Multiple-Choice Questions ● ●

http://apcentral.collegeboard.com/apc/public/repository/2007_Chinese_Released_Exam_FINAL.pdf Audio Files: http://apcentral.collegeboard.com/apc/public/courses/teachers_corner/205159.html

Part 3: Open-Ended Questions ●



Audio Files: http://apcentral.collegeboard.com/apc/members/exam/exam_information/216817.html


Part 2: Multiple Choice Responses (Due 7/31) Submit a document on turnitin.com that contains: ● ●

Your responses to all the multiple choice questions (type the letters) For incorrect responses, include correct response and a short explanation as to why you put the answer you did vs. the correct answer.

Part 3: Open-ended Responses (Due 8/15) Writing: ●

Submit a document on turnitin.com that contains two parts: ○ The typed Story Narration Writing Task. Make sure to include as much detail as possible and use the transition words below. ○ The typed Email Response Writing Task. Make sure your message actually responds to the original email. Provide as much advice or detail as possible to answer the question posed in the original email. Speaking: Submission Instructions: Call the SHP Chinese Class Google Voice number (973-869-9936) and leave your audio tasks as separate voice mails. The voice mails will contain the following: ● ●

Conversation. Play the audio file using earbuds on one ear; use the other ear to talk in phone for your response Cultural Presentation. Give yourself 4 minutes to prepare, then record your 2 minute presentation over the phone.

Appendix: Useful Transition Words in Chinese

Time 时间 First



Afterwards, next




Then (in a series)

从而 、然后( coll.)

At the same time


At that time

当时、 那时候(coll.)







Additional idea(s) 更多想法 Besides








In other words


To illustrate or explain 表明 For example



像……一样; 跟……一样

Compare/Contrast比较和对比 Although




Not ….rather…


One on hand


On the other hand



A is more … than B

A比B 更 + adj.



To show a result 结果 Therefore

因此 、所以(coll.)





In any case, no matter what


Of course


To emphasize an idea 重点 Especially


In fact


Not only…but also…


To summarize 总结 After all


In sum


PART 4: Film Viewing and Writing Assignment  《饮食男女》 Yǐnshí nánnǚ  Due: August 31, 2017

Watch the 1994 film 《饮食男女》 "Eat Drink Man Woman" by Ang Lee (李安). The describes the relationship between an aging widower and his three daughters. It is set in modern-day Taiwan.


Your writing task, in an essay of approximately 250 characters, is to describe the movie and its cultural significance. You must select a specific focus for your essay, such as: the film's major events and how the characters dealt with them (births, weddings, funerals, etc.); the importance of community and interdependence in Chinese culture; the dichotomy between traditional Chinese culture and modern Chinese culture; etc.

Submission Instructions: Type your essay using Chinese pinyin input and submit via turnitin.com

● ● ●

Complete a "THINK" for your essay (see next page for instructions). A THINK includes a title, hook, introduction (w/thesis statement), next ideas/new topics, and a killer ending. Use at least 10 of the transition words found at the end of this document (see appendix) Length must be at least 250 characters.

Main Characters 主要人物: zhǔyào rénwù: ● ● ● ● ● ● ●

朱厨师(朱爷爷)Zhū chúshī (Zhū yéyé) 朱家珍 (大姐)Zhū Jiā zhēn (dàjiě) 朱家倩(老二)Zhū Jiā qiàn (lǎo èr) 朱家宁(老小)Zhū Jiā níng (lǎo xiǎo) 温厨师(温伯父)Wēn chúshī (wēn bófù) 锦荣 Jǐn Róng 梁伯姆 Jiáng bó mǔ

讨论问题 Question Prompts that you could use to guide your essay

1. 2. 3. 4.

这部电影的主题是什么?主要的人物是谁?他们之间的关系怎么样? 电影里的父亲扮演什么样的角色? 在这部电影里,有什么样的社会变化? 为什么饮食在中国文化中那么重要?


THINK before you write!

Here’s how: ● ● ● ● ● ●

Write out your THINK in English and check for a logical progression of ideas. Once you are satisfied that your THINK works... Write your THINK in Chinese. Use your dictionary. Then you are prepared to... WRITE your composition without stopping so you don’t lose your train of thought. Never write your composition in English first. Translating is difficult and anyway your goal is to WRITE in Chinese! Finally... REVISE your composition. If you are able to come back to it later, you will find it less perfect than you thought, because... YOUR FIRST DRAFT IS YOUR WORST DRAFT! Don't let anyone else read it!

Title 题目 Hook 预言 Idea 主题(论点) Next Idea 副题 (Additional Idea) Killer Ending 总结


THINK Checklist

Look for the following elements in your composition. Circle the number next to each category. (5= yes,非常好; could not be better!)

5 4 3 2 T = TITLE Does the title relate to the composition? Does it interest you?

5 4 3 2 H = HOOK Does the introductory sentence hook you into reading further?

5 4 3 2 I = IDEA Is there one and only one main idea in the first paragraph? (What is it?)

5 4 3 2 N = NEXT IDEA Does the next paragraph also have only one main idea? (What is it?)

5 4 3 2 K = KILLER ENDING Does the ending make your main point forcefully? Your composition must show purpose (50% of your score) and language mastery (50% of your score).



AP COMPUTER SCIENCE SUMMER 2017ASSIGNMENT Email w/questions and completed assignments to [email protected] Completed assignments must be sent my school account ([email protected]) and must have the assignment as an attachment and not within the body of the email. Each file(attachment) should be named using your last name and the part number ----- for example yourLastName_part1.doc. You should be using your Microsoft Online shp email address. You will be added to the One Note Class this way. You must put your name and APCS in the reference of all emails sent to me. You should be using your Microsoft Online email address. There are 3 parts. Please note the due dates for each assignment. Again assignments must have the assignment as an attachment and not within the body of the email. This material will be covered and reviewed during the first few weeks of class. Part 1 **Send me an email with an attachment stating that you are in this course (follow directions above). I will be making an email contact list . DO this today. Write your full name and address in the document. For the summer assignment you will be downloading a pdf containing Chapters 1,2 and 3 of text 1 of the text below. Text : Exposure Java Author: Schram, Leon. Print these and keep in a binder. ABACUS






























Assignment for Part 1 **Send me an email today with an attachment stating that you are in this course (follow directions) Readings: Chapter 1 and 2 Schram. Answer questions provided (Exercises 1.1,1.2,2.1) and follow directions. Write out question and answer. Type your answers in paragraph form and include the complete question above each answer. Your name and email address must be included on all assignments. Due date July 1,2017 Late assignments will warrant dismissal from the course.

Assignment for Part 2 Readings: Chapter 3 Schram. Answer questions provided. (Exercises 3.1 & 3.2) Follow directions from above. Be sure to write your answers in paragraph form. Due date July 15, 2017. Part 3 --- History Write short, but descriptive, complete paragraphs defining the terms, events and inventors listed below as their work relates to the computer. There should be a separate paragraph for each topic. Arrange these paragraphs in chronological order, creating a timeline of significant events, inventions and contributors which led to the creation of the Mark I, the precursor of the modern (electronic) computers and then to the generations of the Modern (electronic computers)..Due date for part 3 July 29, 2017 . You must use a minimum of 4 sources. Follow MLA format for all citations and use both on line and off line (print) sources: We will be using JCreator at school. But you can download Dr. Java to get started with our first programs. Downloading an IDE 1)for Dr. Java Go to : http://www.drjava.org/ and choose the appropriate download 2) for JCreator Go to this page to download both JCreator LE and the JSDK. (There is a 21 day trial and then the cost is approximately $35) http://jcreator.com/download.htm 3) You could alternatively use Eclipse or NetBeans

Chapter I Introduction to Computer Science Chapter I Topics 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 1.11 1.12 1.13 1.14

Teaching the Exposure Way Exposure Equation Roller Coaster Emotions Tackling Computer Science Excessive Help Computer Fundamentals How Do Computers Work? Messages with Morse Code Electronic Memory Counting in Other Number Systems Memory and Storage What Is Programming? Programming Languages Summary

1.1 Teaching the Exposure Way One of the most important elements of learning in a classroom is the “student teacher relationship.” Who claims that? Me, Leon Schram, a teacher at Berkner High School, Richardson, Texas or Mr. Schram if you happen to be a student-type person. If you are a student - at Berkner High School - reading this book, your suspicions were correct. Something happened to Mr. Schram back in the Sixties when he was in Vietnam. You might suspect too much exposure to Agent Orange? It has probably caused some brain cell damage. You know - the slow dissolving - one brain-cell-at-a-time kind of damage. Makes sense, it has been about 35 years since Vietnam and this guy is acting very weird these days. Many years ago I learned quite a lesson about relationships with students. I had a young lady in my class who had trouble with math. No, let me be honest, this girl was pitiful with any type of mathematical problem. Our school had some type of talent show and I went to see it. I was absolutely blown away. This girl, my bless-her-will-she-ever-learn-math-student, had the voice of an angel. She was animated, she was incredibly talented, and suddenly I saw her differently. That talent show knocked me straight out of my tunnel-vision-view of a struggling math student. I told her the following day how impressed I was with her performance. She beamed and was so pleased that I had noticed. Something neat happened after that. Sure, she still agonized in math but she worked, and tried, harder than she had done previously. At the same time, I tried harder also. The teacher/student relationship, which had developed, made her a better student and it made me a better teacher.

I have been a teacher for a long time, and I have been a student for even longer. In fact, I am still a student taking both college classes and network technology courses. As a teacher, and as a student, I have seen my share of books that hardly ever get opened. Students try, do not get it, get bored, get disinterested, get frustrated, feel stupid, are intimidated .... pick your poison. The book just sits somewhere and becomes useless. Now this particular book may be the most informative, most complete, most up-to-date, most correct book on the subject, but if the book sits and occupies space, the content matters little. How does an author of a book develop a “student-teacher” relationship? That is tricky business, but if you are really curious what I look like, try my web page at http://www.schram.org. In 1996, Robert Hynecek, a former student of mine, drew a graphics picture, and this picture is now on my web page. Some say that the picture is a good likeness. Picture or not, it is my aim to write this book in the first person using an informal, verbal style of communication. I want to talk to you, rather than write to you. By the way, I do not recommend this writing style for English-type teachers. I will guarantee you that they are neither amused nor impressed. My English teachers certainly have never cared much for my writing style and I have been told at many occasions that my writing lacks the scholarly flavor one associates with college style writing. For one thing, one does not use I, one uses one. Do you know how boring it is to keep saying one does this and one does that? Well, I do not know what one does, but I do know what I do, so I will keep using I and we. This is not for the sake of glorifying myself, but to keep an informal style. Students have told me in the past that it appears that I am talking to them. In fact, I have been accused of writing with an accent. In case you all do not realize it I was neither born in Texas nor the United States. I was born in Holland, moved all over the place, ended up in the United States, took a test in English, US government and US history, and then became an US citizen. Six months after my new citizenship I was rewarded with an all-expenses-paid trip to Vietnam. Today, I have forgotten several languages I learned in my youth, and I cannot speak any language I remember without an accent. A few more items on this personal relationship business. I was born in 1945. I have been married to the sweetest wife in the world since April 9, 1967. Her name is Isolde. I have four children, John, Greg, Maria, and Heidi. Furthermore, I have a daughter-in-law, Diana, a son-inlaw, David, and 4 grandchildren. My favorite activities are skiing, rock climbing, rappelling, SCUBA diving, traveling and writing. Now there is a slight problem. You know a little about me, but I know nothing about you. Well perhaps we will meet one day, and I may also hear about you from your teachers. By the way, there is a way that I can get to know more about you. You can drop me an e-mail line using [email protected] Now please read this carefully. I put my e-mail address here just for casual chit-chat. You may wish to send me a note and say hi. You might even want to give me some constructive criticism about these books. However, do not write and ask for advice on programs that do not work. You have a computer science teacher. Your teacher knows your assignments, knows your background, and knows your computer science level. Your teacher can help you far more effectively than I possibly can at a distance. Another point, I get frequent email from students requesting to buy some of these books that you are reading. I do not publish paper copies for sale. School districts purchase a copy license, and each school district uses their

own method for making copies. You can approach your teacher about acquiring copies from them, if that is an option at your school. Good, now that we have that straight, let us move on. You may get the impression that all this informal style, and such, may take away from the serious business of learning computer science. Do not believe that for one minute. There are many pages ahead of you and each topic is going to get a thorough treatment. Also do not think, just because this introduction is light-hearted, that everything will be in the same style. Some topics are duller than dirt and you will just have to digest some discomfort and make the best of it. Other topics are pretty intense, and I will do my best to make it clear what is happening, but there are no promises. I will try hard to do my part and you need to do yours. Just exactly what you need to do to learn will come a little later in this chapter.

1.2 Exposure Equation Somewhere during the time when Cro-Magnum Man told the Neanderthals to take a hike basically my early Twenties - a neat Sociology professor said something very interesting. What he said ended up having a profound attitude on my teaching and my writing. He claimed that nothing in life is obvious, and he told the following story. Imagine a young boy in the Amazon jungles. This boy has always lived in the jungle without any modern convenience. He has never been in a city, he has never seen a television nor seen a book. Now imagine, that for reasons unknown this young boy travels to Colorado in the winter time. The little boy stands in a yard somewhere and watches the snow with bewilderment. He is astonished; he does not understand what is falling from the sky. Another little boy, about the same age, from Colorado, looks at the boy’s behavior. The young Colorado boy does not understand the other boy’s bewilderment. Why is the boy acting so odd, obviously it is snowing, so what is the big deal?

The Amazon boy is bewildered. The Colorado boy is confused that the other boy is bewildered. The professor asked us what the difference between the two boys is, and use only one word to describe that difference. The word is . . . . . .


The point made by my sociology professor was so wonderfully simple and logical. If you have zero exposure to something, you will be bewildered. If you have never in your life seen a plane, heard a plane fly by, seen a picture of a plane, heard anybody talk about a plane, you will be one frightened, confused puppy when the first plane comes by. This exposure theory states that nothing in life is obvious. What we do have are varying degrees of exposure. This means the next time somebody says: “It is painfully obvious to see the outcome of this situation,” do not get excited. Translate that statement into: “after being exposed to this situation for the last 20 years of my life, and having seen the same consequences for the same 20 years, it is now easy for me to conclude the outcome.” Well, this good sociology professor - I wish I remembered his name and could give him credit impressed me with his obvious-bewilderment-exposure theory. Based on his theory I have created an equation:

Bewilderment + Exposure = Obvious

This equation states that bewilderment is where you start. With zero exposure it is not logical to immediately comprehend a new concept, let alone consider it to be obvious. However, let enough exposure come your way, and yes, you too will find something obvious that was confusing at the first introduction. This means that you need some special sympathy for your first instructor and your first book. I have had that theory work for, and against me. Students have come to me and said, “it made so much more sense to me when it was explained in college.” I have had the opposite claim with, “if only my first instructor had explained it as well as you did I would not have had so much trouble.” So just what is the point here? Something very weird happens with academic learning. Students, and I mean students of all possible ages, in all kinds of academic topics, expect understanding on the first go-around. Students open their books, and with some luck read a topic once. Perhaps a second, brief reading occurs immediately before an examination. And more than once, I have been told you told us that yesterday when I am repeating an important, probably confusing, point that requires repetition. Now let us switch the scene to athletics, band, orchestra, cheerleading and the drill team. How many band directors practice a half-time show once? Have you heard of any drill team directors sending girls home after they rehearsed their routine for the first time? Seen anybody on the swim team get out off the pool after one lap lately, claiming that they know that stroke now? How about basketball players? Do they quit practice after they make a basket? Do the cheerleaders quit the first time they succeed in building a pyramid? You know the answers to these questions. In the area of extra-curricular activities, students get exposed too death. As a matter of fact, some of this exposure is so frequent, and so severe that students are lucky to have any time left over for some basic academic exposure. But guys, learning is learning and it does

not matter whether it is physical, mental, artistic or everything combined. You cannot learn anything well without exposure. And yes, in case you have not noticed by now, I believe so strongly in this philosophy that I call these books Exposure Java just like my previous text books that were called Exposure C++. I am harping on this topic because I believe that so many, many, students are capable of learning a challenging subject like computer science. The reason that they quit, fail, or hardly even start is because they interpret their bewilderment as an indication of their aptitude, their inability to learn. One little introduction, one short little exposure and a flood of confusion overwhelms many students. Fine, this is normal; welcome to the world of learning. Let me borrow from my favorite sport, skiing. I have watched a whole bunch of people learn to ski. I have taken many students on ski trips and I have taught a fair number of people of different ages to ski. You know, I have never seen anybody get off the lift for the first time and carve down that bunny slope like an Olympic skier. I have seen many people stumble off the lift wondering what to do next. I have watched these brand-new skiers as they ski down for the first time all bend over, out of balance, skis flopping in the breeze, poles everywhere, and usually totally out of control. A close encounter with the snow normally follows. Fine, you did not look so swell on the first time down, or even the first day, or maybe the first trip. After people’s first taste of skiing, I have seen many determined to enjoy this wonderful sport and I have watched as they made fantastic progress. I have also seen other people who quit after minimal practice, and concluded they were not capable of learning to ski. Normally, the boring, obligatory list of excuses comes attached free of charge. This means whether you are a high school student, learning computer science for the first time or a teacher, learning Java after C++, you can learn this material. You can learn it well, even with surprisingly little pain, provided you do not self-inflict so much permanent pain with all this business of self-doubt and I cannot do this or I cannot do that. So you are confused. You do not understand? Great, join the crowd because the majority of the class is confused. Open your mouth, ask questions, hear the explanation a second time around and allow time to flow through your brain. There is not a channel you can change ... a button you can push ... a pill you can take ... or a specialist you can pay, to soak up knowledge easily. You need exposure, and surprise ... exposure takes effort. Ask a champion swimmer how many laps they have completed? Ask anybody who is accomplished in any field how they arrived. Let me know if they arrived on day one. I want to meet that extraordinary person.

1.3 Roller Coaster Emotions Nobody, in my experience as a computer science teacher, expressed the roller coaster emotions of computer science learning better than Howard Smith. Howard is not his real name, but the young man may not like to see his name in print. A typical encounter in the computer lab with Howard went something like this. “Mr. Schram!! Mr. Schram!! I love computers! I am going to

be a computer scientist! Computers are so cool!” This excitement would normally follow some segment of Howard’s assignment that worked correctly. Unfortunately, Howard was soon faced with an uncooperative computer in the next stage. Frequently, there were problems, and Howard could be seen in the lab jumping up and down as he exclaimed, “Mr. Schram, I hate computers! I don’t want to touch another computer. Computers hate me. Mr. Schram, I want to drop this course. I want out! I want out now, this minute! I hate, hate, hate computers!” Few people show emotions to the degree that Howard did, but he did illustrate a very important point. There is nothing steady about learning computer science. Your time in the computer lab is primarily devoted to making the computer perform some assigned task correctly. You will experience the excitement when the computer responds correctly, and yes, you will also experience the frustration when your computer just does not cooperate. This type of emotion is so different from studying a history book or writing an essay. Essays do not go through stages of working and not working. An essay slowly, and steadily becomes better, and even when your essay is far from perfect, you may decide to turn it in anyway. A computer program can have some small glitch and will not work at all. Is this so bad? It is not bad at all and I have seen thousands of students learn computer science very successfully. I am mentioning the roller coaster feelings because I have observed it and it may be of help for you to realize that such feelings are very common. After you gain confidence, you may find that learning computer science is very rewarding and can be quite a bit of fun.

1.4 Tackling Computer Science Students have all kinds of different learning and study approaches. You must accept one simple fact. Learning computer science, like learning most lab sciences, is most effective when you discover an important concept. Teachers can give you theorems, general laws and all kinds of facts about some scientific discipline. Yet, these laws were discovered by scientists as they observed a wide variety of different situations. The same philosophy will be used in the Exposure books. You will see many, many small programs. Most programs will focus on one or two concepts. Study each one of the program examples carefully. Check to see what the examples have in common. Remember that reading and studying program examples has limited results. You need to get your hands dirty. Type in the program examples. Observe how the programs work. Change some of the statements by adding, deleting and altering some of the information. The more you play with the program statements, the better your understanding will grow.

Steps In Learning Computer Science 

Read the assigned text book pages before the lecture.

Closely listen to the lecture. In particular, focus on any concepts that were confusing during your reading.

If program examples are used at your computer, make sure that you are at the same place as the lecture.

Play with the computer. Load or type small program examples and try different approaches.

Ask questions, if you are confused. Concentrate your questions on the topic being discussed.

Read the material again after the lecture for continuing exposure. Make note of any topics that are still confusing.

Read the lab assignments before arriving for a scheduled lab. Think about the solution.

Work on the lab assignment. Ask for help when you are stuck. Make sure to give clear questions.

Make sure that you get clarification in any area that is confusing before you take a test.

Pay particularly close attention when a test is returned and your teacher goes over the questions.

Please realize that cramming does not work with computer science. You need the combination of text book reading, lecture/discussion, and hands-on lab assignments to discover patterns, learn topics and comprehend the bigger picture.

1.5 Excessive Help A person who does an entire lab assignment without any help from anybody will not be accused of cheating on an assignment. Another person, whose effort on a lab assignment consists of copying somebody else’s file does not gain any knowledge from such an approach. Blindly copying somebody’s work and calling it your own is academic cheating. Few people argue with the examples stated above. The problem occurs in the middle. What exactly is right, what is wrong, and what might be called academic dishonesty? Computer science students learn not only from their teachers, they also can learn a great deal from fellow students. Sometimes, the best teacher for you may be the person who has just discovered a solution to the problem that is also frustrating you. The name of the game is learning, and learning comes in many different forms with many different types of teachers. One day understanding clicks in your brain when you try something on the computer ... another day it may be a teacher’s statement in a lecture ... perhaps you read a chapter in your text book again ... and certainly it can be the help of a fellow student.

Program assignments are a considerable part of your grade. Teacher policies fluctuate tremendously but your ability to finish computer lab assignments is an integral part of your total grade. You need to recognize that an easy temptation presents itself. How about simply copying the lab assignment from a good buddy or somebody who is about to become your good buddy? You know some nice kid who appears to be pretty smart and always finishes the assignment before you do.

There are two major problems with this approach:  

It is wrong because it is unethical. It is wrong because you are not learning.

If you do not realize that copying other people’s work - with or without their consent - is wrong, then it is time you discuss this issue with your parents to get clarification on basic issues of right and wrong. Computer lab assignments, that can be copied, are only a part of the total grade picture. You also have to take written tests and you have to take computer lab tests. If students study together, help each other with lab assignments, and if the students learn from their study group, they will learn and do fine on tests. Students who put in zero effort do not learn and fail tests miserably. Those of you who are inclined to help your friends by letting them copy your disk need to consider the type of friend that you are. A true friend will teach and prepare a buddy for upcoming quizzes and tests. Somebody who likes the quick popularity that comes with improper diskcopying allows a “friend” to fail in the future.

Excessive Help Do not get excessive help. Do not copy diskettes. It is wrong. You know it is wrong, and you will not learn. Do form study groups. Do work together and help each other understand difficult concepts. Do encourage your friends when they are struggling.

1.6 Computer Fundamentals Getting started with computer science is none too easy. The course that you are taking and the book that you are reading assumes that this is your first formal computer science course. Furthermore, it is also assumed that you have no knowledge of programming. If you do know some programming, fine, but it is not any kind of a prerequisite. This means that we should start at the beginning. However, does the beginning mean an explanation like: this is a monitor; that is a printer; here is the power button; there is the network server? Probably not. Today’s high school students

usually have been behind a variety of computers since elementary school. Many students have heard stories about the history of old computers along with lectures on how computers make mankind’s life simpler. Did you know how long it used to take to fill out useless paperwork? Today we can finish ten times the useless paperwork in a fraction of the old time with the aid of computers. Progress is good. Anyway, this chapter is not going to talk about a variety of computer components that many students have learned about in previous classes. In the event I am wrong, and you are now touching a computer for the first time, I feel assured that your teacher will cover the necessary basics with you. The focus of this section will be on understanding how the computer works. What makes it tick? How does it store information? How does it manage to calculate, and how is information stored? And, what is a program anyway? In general, all the introductory information necessary to start learning programming.

1.7 How Do Computers Work? Human beings do not spend money on expensive items unless such items somehow improve human capabilities. Cars are great. They move faster than humans, they do not get tired, and they keep you comfortable in bad weather. They are expensive, but the expense is worth it. Computers process information and do this processing better in many areas compared to human beings. The three areas in which a computer is superior to a human being are shown in figure 1.1. Figure 1.1

Three Areas Where Computers Beat People  Computers are faster  Computers are more accurate  Computers do not forget You may be quick to accept that computers are faster, but you are not so sure about the other two. Too often you have heard the term computer error and you also remember hearing about data that was lost in the computer. Well, let us start our computer lesson right now by clearing up some basic myths. Computers do not make errors. Sure, it is possible for a computer to give erroneous information. However, the computer is nothing but a stupid machine that faithfully, and always accurately, follows instructions. If the instructions given by a human being to a computer are faulty, then the computer will produce errors. At the same time, many so-called computer errors are caused by sloppy data entry. A person who receives an outrageous electric bill is told that the computer created an erroneous bill. True, the computer printed the bill, but not until a data-entry clerk had slipped an extra zero in the amount of electricity used for the previous month. Perhaps you are still not convinced. After all, what about the situation when a computer breaks down? Won’t that cause problems? Broken computers will certainly cause problems. However,

your computer will not work at all. Your computer applications will not work and you are stuck, but the computer does not suddenly start adding 2 + 2 = 5. You may also have heard that people lose their computer information because of problems with disk drives. Once again this happens, but computer users who keep their computers and diskettes in a proper environment, along with a sensible backup system do not have such problems. Well, you give up. No point arguing with a stupid book that cannot hear you. Fine, the computer is faster, the computer is more accurate, and sure the computer does not forget. But how is this managed electronically? You know that electricity is incredibly fast, and you have every confidence that the flip of a switch turns on a light or a vacuum cleaner. Today’s computers are electronic and just how does electricity store information? How does a computer perform computations? How does a computer translate keyboard strokes into desirable output? These are all good questions and an attempt will be made here to explain this in a manner that does not become too technical.

1.8 Messages with Morse Code Unless you are a Boy Scout or Navy sailor, you probably have little experience with Morse code. Today’s communication is so much better than Morse code, but there was a time when Morse code was an incredible invention and allowed very rapid electronic communication. Imagine the following situation. Somehow, you have managed to connect an electric wire between the home of your friend and yourself. You both have a buzzer and a push button. Each one of you is capable of “buzzing” the other person, and the buzzer makes a noise as long as the button is pressed. You have no money for a microphone, you have no amplifier, and you have no speakers. Furthermore, your mean parents have grounded you to your room without use of the telephone. But you do have your wires, your buzzers and your buttons. Can you communicate? You certainly can communicate if you know Morse code or develop a similar system. Morse code is based on a series of short and long signals. These signals can be sounds, lights, or other symbols, but you need some system to translate signals into human communication. Morse code created an entire set of short and long signal combinations for every letter in the alphabet and every number. Usually, a long signal is three times as long as a short signal. In the diagram, below, a long signal is shown with three dots closely placed together. A short signal is indicated by a single, lone standing, dot. Consider the first five letters in the Morse code system, shown in the figure 1.2 table.

Figure 1.2


First Five Letters In Morse Code short - long   long - short - short - short    

       


long - short - long - short long - short - short short

You, and your buddy, can now send messages back and forth. By pressing the buzzer with long and short sounds. Letters and numbers can be created this way. For instance the word BAD would be signaled as follows:

   

 

  

The secret of Morse code is the fact that electricity can be turned on, and it can be turned off. This means that a flashlight can send long and short beams of light and a buzzer can send long and short buzzing sounds. With an established code, such as Morse code, we can now send combinations of long and short impulses electronically. Very, very brief pauses occur between the shorts and longs of a letter. Longer pauses indicate the separation between letters. This basically means that electronically we can send human messages by turning electricity on and off in a series of organized pulses. Does this mean that Samuel Morse invented the computer? No, he did not get credit for starting the computer revolution, but it does serve as a simple example to illustrate how electricity can process letters by translating on and off situations into letters and numbers.

1.9 Electronic Memory Fine, Morse code explains how letters can be translated into electronic impulses. This explains electronic communication, but Morse code does not store any letters. Morse code signals are sent and they are gone, followed by the next signal. If you doze off, you miss the signal and it is too bad. Luckily, somebody became clever and a special device was invented that printed dots (short signals) and dashes (long signal) on a paper tape as the message was received. Now that explains a paper memory, and perhaps you even remember something about punched computer cards, but we still have not gotten to an electronic memory. Suppose you line up a series of light bulbs. How about picking eight bulbs. Each light bulb is capable of being turned on and off. With these eight light bulbs we can create 256 different combinations. Two tables are shown in figure 1.3 below. The first diagram shows on and off. The second diagram uses 1 and 0. In Computer Science, 1 means on and 0 means off.

Figure 1.3



off off off off off










In this particular example, the second and eighth bulbs are on, and all the other lights are off. This represents only one of 256 different combinations. Figure 1.5 will show three more combinations. It certainly is not Morse code, but using the Morse code example, we can imagine that each one of the 256 combinations is assigned to a letter, a number, or some other type of character. The number system you use is base-10. Counting and computation in base 10 is not simpler than other bases because it is base 10. It is simpler because you use base 10. Sounds confusing, does it not? In elementary school, you practiced multiplication tables in base 10. How many multiplication tables did you practice in base 5 or base 8? Not too many, right? Rumor has it that people developed a base 10 system because of our ten fingers. Now, in base 10, digits range from 0 to 9. After the largest digit, 9, we must use two digits, 10, 11, 12, etc. to count higher. Mathematically speaking, counting and computation is possible in many different bases. A number system that is very skimpy in digits is base-2. Only the digits 0 and 1 are used. Many digits are needed for even small-valued numbers. The first 32 numbers in base-2, with the equivalent base-10 values are shown in figure 1.4.

Figure 1.4

Base 10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Base-2 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111

Base 10 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Base-2 10000 10001 10010 10011 10100 10101 10110 10111 11000 11001 11010 11011 11100 11101 11110 11111

Now consider these three “8 light bulb” combinations in figure 1.5. Each one of these combinations of on and off light bulbs can be viewed as a base-2 number.

Figure 1.5

0 1 0 0 0 0 0 1 01000001 (base-2) = 65 (base 10)

0 1 0 0 0 0 1 0 01000010 (base-2) = 66 (base 10)

0 1 0 0 0 0 1 1 01000011 (base-2) = 67 (base 10) You are looking at A, B, C on the majority of today’s personal computers. By convention, at least the convention of the American Standard of Computer Information Interchange (ASCII), number 65 is used to store the letter A. Combinations 0 through 127 are used for a standard set of characters. The second group from 128 through 255 is used for a special extended set of characters. Now we are finally getting somewhere. We can use eight lights for each character that needs to be stored. All we have to do is place thousands of light bulbs in a container and you can store bunches of information by using this special binary code. There is another big bonus. Mathematically speaking, computations can be performed in any base. With our clever binary system, we now have a means to store information and make calculations simpler as well. We have now (hopefully) established that information can be stored in base-2 numbers. Base-2 numbers can store characters by using a system that equates numbers like the base-2 equivalent of 65 to A. At the same time, mathematical operations now become an electronic reality. In other words, the magic of on/off switches allows both electronic storing of information as well as electronic computation. We can also add some terminology here. A single bulb can be on or off and this single light represents a single digit in base-2, called a Binary digit, which is abbreviated to Bit. We also want to give a special name to the row of eight light bulbs (Bits) that make up one character. This row shall be called a Byte. Keep in mind that Byte is not plural for Bit. There is one problem with storing characters in a single byte. You only have access to 256 different combinations or characters. This may be fine in the United States, but it is very inadequate for the international community. Unicode is now becoming very popular and this code stores characters in 2 bytes. The result is 65,536 different possible characters. Java has adopted Unicode, as have many technical organizations. The smaller ASCII code is a subset of Unicode.

Bits, Bytes and Codes

Bit is a Binary digit that is either 0 (off) or 1 (on). 1 Byte = 8 Bits. 1 Byte has 256 different numerical combinations. 2 Bytes has 65,536 different numerical combinations. ASCII uses one byte to store one character. Unicode uses two bytes to store one character. Early computers did in fact use one vacuum tube (essentially a light bulb) for each Bit. Very large machines contained thousands of vacuum tubes with thousands of switches that could change the status of the tubes. Miles of wires connected different groups of vacuum tubes to organize the instructions that the computer had to follow. Early computer scientists had to walk inside giant computers and physically connect and reconnect wires to different parts of the computer to create a set of computer instructions. The incredible advances in computer technology revolve around the size of the Bit. In the forties, a Bit was a single vacuum tube that burned out very rapidly. Soon the large vacuum tube was replaced by a smaller, more reliable, vacuum tube. A pattern was set that would continue for decades. Small is not only smaller, it is also better. The small tube gave place to the peasized transistor, which was replaced by the planar transistor and bits were miniaturized, becoming smaller and smaller. Today, a mind-boggling quantity of Bits fit on a microchip. This is by no means a complete story of the workings of a computer. Very, very thick books exist that detail the precise job of every component of a computer. Computer hardware is a very complex topic that is constantly changing. Pick up a computer magazine, and you will be amazed by the new gadgets and the new computer terms that keep popping up. The intention of this brief introduction is to help you understand the essence of how a computer works. Everything revolves around the ability to process enormous quantities of binary code, which is capable of holding two different states: 1 and 0.

1.10 Counting in Other Number Systems In the last section you saw a table that assisted in base-2 counting. The primary concern with binary counting is to help understand how the computer manages information. Base-2 is not the only number system used by the computer. You will frequently see base-16 used as well. I want you to look at the number system charts below first. Various number systems are represented to help you see a pattern in counting that is the same in all bases. At the same time, take a close look and compare the base-2 and base-16 number systems. Something unique is going on that helps to explain why base-16 or the hexadecimal number system is also used with computers.

Base 10


Base 16

Base 5

0 1 2 3 4 5

0000 0001 0010 0011 0100 0101

0 1 2 3 4 5

0 1 2 3 4 10

6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 0001 0000 0001 0001 0001 0010 0001 0011 0001 0100 0001 0101 0001 0110 0001 0111 0001 1000 0001 1001 0001 1010 0001 1011 0001 1100 0001 1101 0001 1110 0001 1111 0010 0000 0010 0001 0010 0010 0010 0011 0010 0100 0010 0101 0010 0110 0010 0111 0010 1000 0010 1001 0010 1010 0010 1011 0010 1100 0010 1101 0010 1110 0010 1111 0011 0000 0011 0001

6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31

11 12 13 14 20 21 22 23 24 30 31 32 33 34 40 41 42 43 44 100 101 102 103 104 110 111 112 113 114 120 121 122 123 124 130 131 132 133 134 140 141 142 143 144

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

0011 0010 0011 0011 0011 0100 0011 0101 0011 0110 0011 0111 0011 1000 0011 1001 0011 1010 0011 1011 0011 1100 0011 1101 0011 1110 0011 1111 0100 0000

32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F 40

200 201 202 203 204 210 211 212 213 214 220 221 222 223 224

Did you observe the relationship between the base-2 and base-16 numbers? The base-2 numbers are intentionally written with groups of four digits. Take a close look, and you will see that any group of four base-2 digits corresponds to one base-16 digit. This makes conversion between base-16 and base-2 a rather simple substitution job. The binary system is very tedious to view, and you can easily get confused. For this reason you will see that many computer values, such as memory addresses, are displayed in the hexadecimal, base-16 system.

1.11 Memory and Storage Electronic appliances used to have complex - cables everywhere - dusty interiors. Repairing such appliances could be very time consuming. Appliances, computers included, still get dusty on the inside, but all the complex wires and vacuum tubes are gone. You will now see series of boards that all have hundreds and thousands of coppery lines criss-crossing everywhere. If one of these boards is bad, it is pulled out and replaced with an entire new board. What used to be loose all over the place, vacuum tubes, transistors, resistors, capacitors, wires, etc. is now neatly organized on one board. Electronic repair has become much faster and cheaper in the process. In computers the main board with all the primary computer components is called the motherboard. Attached to the motherboard are important components that store and control information. These components are made out of chips of silicon. Silicon is a semiconductor, which allows precise control of the flow of electrons. Hence the names memory chip, processing chip, etc. We are primarily concerned with the RAM chip, ROM chip and the CPU chip. I mentioned earlier that information is stored in a binary code as a sequence of ones and zeroes. The manner in which this information is stored is not always the same. Suppose now that you create a group of chips and control the bits on these chips in such a way that you can not change their values. Every bit on the chip is fixed. Such a chip can have a permanent set of instructions encoded on it. These kinds of chips are found in cars, microwaves and many electronic appliances that perform a similar task day after day.

Computers also have information chips that store permanent information. Such chips are called Read Only Memory chips or ROM chips. There is a bunch of information in the computer that should not disappear when the power is turned off, and this information should also not be altered if the computer programmer makes some mistake. A ROM chip can be compared to an old record album. You can listen to the music on the record album, but you cannot alter or erase any of the recordings. Another type of chip stores information temporarily. Once again, information is stored in many bytes, each made up of eight bits, but this information requires a continuous electric current. When the power is gone, so is the information in these chips. Computer users also can alter the information of these chips when they use the computer. Such chips can store the data produced by using the computer, such as a research paper or it can store the current application being used by the computer. The name of this chip is Random Access Memory chip or RAM chip. Personally, I am not happy with that name. I would have preferred something that implies that the chip is Read and Write, but then nobody asked for my opinion when memory chips were named. The amount of memory in a computer is measured in bytes, not bits. Modern computers have so many bytes that usually memory is indicated as so many kilobytes or megabytes of memory. Kilobytes are rapidly fading from the computer scene and gigabytes are alive and well in current computer terminology. Figure 1.6

Measuring Memory KB Kilo Byte MB Mega Byte GB Giga Byte TB Tera Byte

1 thousand bytes 1 million bytes 1 billion bytes 1 trillion bytes

The measuring memory diagram, in figure 1.6, may get a frown or two. The information is technically incorrect. The diagram is meant to help remember the measure size in a rounded manner. After all, Kilo does mean one-thousand. Technically speaking one KB is 210 or 1,024 bytes. Using the same logic you can compute that one MB is 220 or 1,048,576 bytes. I am sure you can live very comfortably using the previous “not really correct” diagram. The most significant chunk of silicon in your computer is the CPU chip. CPU stands for Central Processing Unit and this chip is the brain of the computer. You cannot call this chip ROM or RAM. On this tiny little chip are lots of permanent instructions that behave like ROM, and there are also many places where information is stored temporarily in the manner of a RAM chip. The CPU is one busy little chip. You name it, the CPU does the job.

A long list of operations could follow here but the key notion is that you understand that all the processing, calculating and information passing is controlled by the Central Processing Unit.

The power of your computer, the capabilities of your computer, and the speed of your computer is based on your CPU chip more than any other computer component.

Secondary Storage I just know that you are an alert student. ROM made good sense. RAM also made sense, but you are concerned. If the information in RAM is toast when you turn off the computer . . . then what happens to all the stored information, like your research paper? Oh, I underestimated your computer knowledge. You do know that we have hard drives, diskettes, zip diskettes, tapes, and CDs that can store information permanently. We have stored information on rust for quite some time. Did I say rust? Yes, I did and perhaps you feel more comfortable with iron oxide. Tiny particles of iron oxide on the surface of a tape or disk are magnetically charged positively or negatively. In a different manner than the internal computer, but with a similar logic, coded information is stored on a tape or a disk. Please do keep in mind that this information will not disappear when the power is turned off, but it can be easily altered. New information can be stored over the previous information. A magnetic field of some type, like a library security gate, heat in a car, dust in a closet, and peanut butter in a lunch bag can do serious damage to your information. You might be confused about the currently popular CD-ROMs. You can see that they are external to the computer, but ROM implies Read Only Memory. CDs store enormous amount of information. The information is permanent and thus behaves like ROM. When you use a CD with a computer it behaves as if you had added extra ROM to your computer internally. CDs do not use rust; they are far too sophisticated for such a crude process. The CD is coded with areas that reflect and absorb laser light. Once again we can create a code system because we have two different states, on and off. The on/off state is the driving force of the digital computer. What is digital? Look at your watch. You can see digits, and you see the precise time. There is no fractional time. A clock with hour, minute and second hands is an analog device. It measures in a continuous fashion. A measuring tape is also analog, as is a speedometer with a rotating needle. What is the beauty of digitizing something? With digital information it is possible to always make a precise copy of the original. It is easy to transfer, store and use digitized information. Entire pictures can be converted to a digitized file and used elsewhere. I am sure you have been in movie theaters where “digital” sound is advertised. So digital is the name of the game. Just remember that not all digitizing is equally fast. The internal memory of the computer is digital and it uses electronics. The access of a hard disk involves electronics, but the information is read off a disk that rotates and only one small part of the disk is “readable” at one time. Accessing a disk drive is much slower than accessing internal memory.

1.12 What Is Programming? Computer science is a highly complex field with many different branches of specialties. Traditionally, the introductory courses in computer science focus on programming. So what is programming? Let us start by straightening out some programming misconceptions. Frequently, I have heard the phrase: just a second sir, let me finish programming the computer. I decide to be quiet and not play teacher. The person “programming” the computer is using some type of data processing software. In offices everywhere, clerks are using computers for a wide variety of data processing needs. Now these clerks enter data, retrieve data, rearrange data, and sometimes do some very complex computer operations. However, in most cases they are not programming the computer. Touching a computer keyboard is not necessarily programming. Think about the word program. At a concert, you are given a program. This concert program lists a sequence of performances. A university catalog includes a program of studies, which is a sequence of courses required for different college majors. You may hear the expression, let us stick with our program, which implies that people should stick to their agreed upon sequence of actions. In every case, there seems to be two words said or implied: sequence and actions. There exist many programs all around us and in many cases the word program or programming is not used. A recipe is a program to cook something. A well- organized recipe will give precise quantities of ingredients, along with a sequence of instructions on how to use these ingredients.

Any parent who has ever purchased a some assembly required toy has had to wrestle with a sequence of instructions required to make the toy functional. So we should be able to summarize all this programming stuff, apply it to computers and place it in the definition diagram below.

Program Definition A program is a sequence of instructions that makes a computer perform a desired task. A programmer is a person who writes a program for a computer

Think of programming as communicating with somebody who has a very limited set of vocabulary. Also think that this person cannot handle any word that is mispronounced or misspelled. Furthermore, any attempt to include a new word, not in the known vocabulary, will fail. Your communication buddy cannot determine the meaning of a new word by the context of a sentence. Finally, it is not possible to use any type of sentence that has a special meaning, slang or otherwise. In other words, kicking the bucket means that some bucket somewhere receives a kick. A very important point is made here. Students often think very logically, write a fine program, and only make some small error. Frequently, such students, it might be you or your friends, become frustrated and assume some lack of ability. It is far easier to accept that small errors will be made, and that the computer can only function with totally clear, unambiguous instructions. It is your job to learn this special type of communication.

1.13 Program Languages You are happy with the fact that a program is a set of instructions to perform a given task. So what needs to be done is understand how instructions are communicated to a computer. At this stage, we have talked quite a bit about binary code, digital information and you have a pretty good hunch that our computers are not using Star Trek technology. So do not try to talk to a computer in English and tell it to finish your history homework. For decades computer scientists have struggled with computers understanding human language. It has not been easy. We have made remarkable progress and a brief history of programming languages will help to understand where we are today, and what you will be doing this school year in computer science.

Programming In Machine Code Programming the first computers was an unbelievably difficult task. Individual vacuum tubes had to be switched on or off. Instructions were sequenced in early computers by physically

plugging wires from one computer memory segment to another. It is true that the early computers were amazingly fast. They were electronic, and they amazed people with their speed and accuracy, but programming those early computers was incredibly time consuming. Very few computers existed in those early days, and large teams of programmers and technicians were necessary for programming even simple jobs. Later, computers did improve the program process by allowing tape and cards to be used for program input. This was far more efficient than walking inside a computer, but there still remained the tedious process of thousands of 1s and 0s that had to be entered. Mistakes were very easily made, and very difficult to detect.

Programming in Assembly Language It did not take long before computer scientists realized that computers are the perfect tool to help people with programming. After all, a program is a set of instructions that can be executed by the computer. This set of instructions, or program, can certainly include instructions that help to translate a more human set of instructions into computer machine code. A special computer language was created called Assembly Language. With Assembly Language, programmers were able to give instructions to the CPU with a short code for every type of task performed by the CPU. Every CPU instruction had a mnemonic name. For instance, mov AX,1234 is the instruction to place the value 1234 into the AX register. The AX register is a temporary calculation scratch pad in the CPU. Assembly Language brought another improvement by using hexadecimal (base-16) numbers rather than binary (base-2) numbers. There exists a unique relationship between base-2 and base-16 numbers, such that any set of four-digit base-2 numbers can be represented by one base-16 number. It is certainly easier to work with one-fourth the digits. A programmer first wrote a set of instructions in the special Assembly Language code. This code was then “translated” by a so-called “Assembler.” The Assembler translated the mnemonic short word instructions into machine code that could be processed by the computer.

Programming with Interpreters and Compilers Assembly Language started the ball rolling. A computer program had been created to make the job of creating a machine language program simpler. This process could be continued and a more sophisticated program could translate a program that is very similar to human language. One person, who must be mentioned, is the late Grace Hopper. Grace Hopper was a lieutenant in the Navy when she first worked extensively with computers. She was largely instrumental for developing translating programs that allow programming in a human-style language. She was one of the main developers of the popular program language, COBOL, and was very influential in the development of early translators. Two types of translating programs were created, interpreters and compilers. An interpreter takes a program and translates the program one line at a time. After each line is translated, the resulting machine code is executed. A compiler translates the entire program into a machine

code file and then executes the file. It is easier to create an interpreter, but the execution speed is slower than a compiler. A compiler is far more complex to create, but it executes much faster than an interpreter. The majority of today’s program languages use compilers for translators. The language you will learn, Java, oddly enough is both a compiled and an interpretive language. How this is possible will be explained soon.

Low-Level and High-Level Program Languages Languages that are very close to computer binary code are called low-level. Machine code and Assembly Language are low-level languages. Languages that are closer to human languages are called high-level languages. Some languages are very high-level today, and many programming tasks have already been performed. With many languages, it is possible to click and drag on program objects that have already been created and insert them inside your program. So why not simply write your programs in English? Is that not a matter of creating some kind of translating program that takes English instructions and creates a machine code file for the computer? This is certainly what has been attempted for many years, but translating human languages has been very elusive. Consider the following example. In the sixties, computer scientists tried to write a program that would translate English into Russian and Russian into English. This is really the same problem of properly understanding the meaning of human language. The scientists decided to test their program by entering an English sentence. The resulting Russian sentence was then entered back into the computer and the final result should be the original English sentence. Should, that is, if the computer could translate correctly in both directions. The original sentence entered was:

The spirit is willing but the flesh is weak I do not have a clue what the Russian result was, but I do know the final English result. Our computer scientists were quite surprised with

The Vodka is great but the meat is rotten This little experiment showed the major problem with human languages. Human languages like English are idiomatic. We use all these idioms and proverbs, and slang and special nuances that are meaningless to the computers. How can computers figure out human language, when humans are confused? The bottom line is that programming requires a restricted language. This language can have human type words, but the words selected, the symbols and punctuation used, all must have a very precise meaning. The manner in which the program language structures its statements is called syntax. Program languages must have very precise syntax. Compilers first check to see if a program has correct syntax. Only after the syntax checks out, is the next step of translating into binary code performed.

A Brief History of Program Languages The first successful programming language for the mathematics and scientific community, FORTRAN (FORmula TRANslation language), was released in 1956. FORTRAN was an excellent language for mathematics and science, but it could not handle the record processing required for the business world. In 1960, COBOL (COmmon Business Oriented Language) was created (largely by Grace Hopper) for the business community and the armed forces. COBOL became extremely successful when the Department of Defense adopted COBOL as its official programming language. PL1 followed, trying to be a language for everybody. PL1 attempted to be both an excellent language for science and for business. The result was an extremely cumbersome language that never gained much popularity. Then there were a host of many other short-lived languages. BASIC (Beginner All-purpose Symbolic Instructional Code) was designed for beginning college students. BASIC became the first popular program language for personal computers in the seventies. BASIC required little memory, and it was the only language that could initially be handled by the first micro computers. In the late seventies, early eighties, Pascal took a strong hold in the educational community. Pascal was developed by Niklaus Wirth, specifically for the purpose of teaching proper computer science programming techniques. This language was adopted for the Advanced Placement Computer Science Examination in 1984 and stayed in that position until the 1998 exam. In the early seventies, the UNIX operating system was developed at the Bell laboratories. This operating system was written in several languages some of which were called BCPL or just plain B. A later version of the language was called C, since it followed B. In the eighties, the C language became very popular as the language of choice for operating systems. As the demands for sophisticated computer uses grew, so did the demand for ever more sophisticated computer programming languages. A new era with a powerful programming technique was born called Object Oriented Programming (OOP). You are hardly in a position to appreciate the finer features of OOP. Right now appreciate that a new language had to be developed to incorporate the power of OOP. Bjarne Stroustrup combined the popularity of the existing C language with the demands for OOP and developed C++. C++ includes all the previous capabilities of C, many improvements on the early C, and the new features of object oriented programming. C++ actually is somewhat of a hybrid language since object-oriented Style Programming is possible, but so is the older C-style programming that today's modern programmers frown upon. There is something else that you need to understand about this program language stuff. You can say that there is one level above the compiler, called the linker. It did not take computer scientists long to figure out that the majority of programs use the same source code in each and every program. This is the type of code used with input and output, mathematical calculations, etc. It seemed silly to keep creating this code over and over again. Special library files of handy computer routines were created and already translated into special machine code files. Now these files cannot be executed by the CPU because the instruction set is not complete. Such files are known as object files.

When modern programmers write a compiled program, like C++, they write their own personal source code and the compiler checks their syntax to make sure everything is written correctly. The first pass through the program is the compile pass. Now a second pass links the compiled code with any other library file and combines it into one nifty file that can be used by the computer’s CPU.

Java Comes on the Scene C++ will continue to be a very important programming language for years to come. The industrial strength features and the tremendous number of programs written in C++ guarantee its survival. In the early Nineties Sun Microsystems worked on a language called Oak. The main focus of this new language was to be platform independent and object-oriented. Platform independent means that the language does not cause problems as programs are transported between different hardware and software platforms. Oak was used internally by Sun Microsystems for about four years and released to the public in 1995 with the new name Java. Java was a big success largely because the new language was perfectly suited for the Internet. Universities also adopted Java very rapidly. By the late Nineties object-oriented programming was taught everywhere and the new language Java gave no choice like C++. This appealed to many college professors who did not like the fact that C++ allowed, older non-OOP programming. The College Board adopted Java as the AP Computer Science language to be used for its examination starting with the 2003-2004 school year. And you have just started a computer science course that will use Java as its programming language.

1.14 Summary This has been an introductory hodge-podge chapter. It is awkward to jump straight into computer science without any type of introduction. Students arrive at a first computer science course with a wide variety of technology backgrounds. Some students know a little keyboarding and Internet access along with basic word processing skills taught in earlier grades. Other students come to computer science with a sophisticated degree of knowledge that can include a thorough understanding of operating systems and frequently knowledge of one or more program languages as well. Information is stored in a computer with combinations of ones and zeroes. Individual binary digits (bits) store a one or a zero. 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. Neither this chapter nor this book explained anything about the operating system. 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.

If your basic computer knowledge is weak, make sure to pick up additional information from your teacher, library or bookstore. Technology is evolving and students arrive in computer science classes with increased sophistication. In this course no prior knowledge whatsoever about any programming language or programming logic is assumed. However, a fundamental knowledge of basic computer operations is essential and assumed. 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.

Chapter II: Introduction to Java Chapter II Topics 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14

Introduction Getting Started with Java A Visit to the United Nations Java Bytecode Applications and Applets Java Tools Setting Up Your Workspace Compiling & Executing Applications Compiling & Executing Applets Is it Java 2 or is it Java 1.4.1? Java Input/Output Issues Text Output With println A Simple Program Template Summary

2.1 Introduction Some students are impatient in general, but when it comes to technology, many students are very impatient. Lots of students march in a computer science class with prior knowledge of using a computer. Such students have played fancy video games, emailed all over town, researched on the Internet, and used computers for word processing. These students are not impressed with a dull, text output, program that displays: Hello Guys. Computer science is not very different from many other professions in the introductory stages. Few medical students perform open-heart surgery during the first week of medical school. The average law student is not asked to argue a case before the Supreme Court after studying one court case. Navy pilot candidates are not asked to land an airplane on an aircraft carrier at night, during a storm, with one engine shut down, during week-one of flight training. In other words, if you expect to waltz in and start creating programs that will land you a $5,000.00 a month parttime job, then you will be disappointed. This chapter will start by showing you the necessary tools to write a simple Java program. Keep in mind that you will be creating your program in a high-level language, Java. This means you need some type of editing environment to write your program. After the program is written you need to go through several steps to create machine code that can be executed by the computer. Learning those fundamental program-writing skills is right now our primary concern.

In this chapter we will also look at the two primary output modes that are available with Java: text and graphics. Text is petty easy and pretty boring. Graphics is exciting, interesting and quite a bit more challenging. The focus in this chapter is to understand first how to create small, simple text programs. Exciting video games, snazzy interactive web pages are all possible with Java. However, that is not a practical starting point. It is possible that you already know some other programming language, such as C++. If such is the case, you will learn Java much faster and you may find the topic descriptions in Exposure Java rather slow moving. That is fine, but keep in mind that this text book is written for the student who has no prior knowledge of any programming language nor any exposure to computer science concepts. If you have such prior knowledge, you are lucky, but do be careful. Java is similar to some other program languages, but there are also major differences, which can cause difficulties.

2.2 Getting Started with Java There are many abstract concepts in computer science. These are concepts independent of any programming language. Object Oriented Design, Algorithmic Analysis and various other topics can be discussed without reference to a specific programming language. In high school and in college the title of the course will probably say Computer Science or AP Computer Science. In most cases your course title will not simply state Java Programming. Yet here you are in Chapter I with a section titled: Getting Started With Java. Trust me you will learn plenty of abstractness and you will learn many generic computer science concepts, but my experience has shown that students are more comfortable when abstractness and generic concepts come at a later date. Consider the following. You love to travel. Traveling everywhere is your goal, your passion and your dream. So what do you do? Just travel? That is not so practical. You want to visit many foreign destinations, but getting there requires familiarity with air travel or train travel or car travel or canoeing or hiking or biking. At this stage let us consider that our goal and destination is to unlock the mysteries of computer science and right now we are using the Java Train to get us there. So come aboard and see where we are heading. In this first Java introduction you will learn what makes Java a unique language that is platform independent and works so well with the Internet. You will also find where you can download Java tools for free from Sun Microsystems. Java makes a distinction between a program meant to be executed in a web page and a program meant to be executed in a regular computer environment. This is a distinction that you need to understand well. Finally, you will observe and practice the steps necessary to take a Java source code program to final execution.

2.3 A Visit to the United Nations Some students are getting concerned. Perhaps you have heard that Mr. Schram is actually also certified as a Social Studies teacher and the poor man is just getting confused. How does the United Nations help us get started with Java? Good question and you will soon see how the

United Nations provides us with an excellent analogy to explain how Java accomplishes some of its main goals. Have you ever observed a United Nations meeting in Brussels with all the delegates present? It is fascinating to hear around 200 delegates from around the world communicate and yet each delegate speaks in his or her own language. How does everybody else understand what is discussed in roughly 200 different languages? The delegates could consider that everybody speaks in one universal language. What might that language be? Oh, of course, it is English. Easy for you to say because you already speak English. How about Spanish? Spanish is spoken all around the world. It seems like a good candidate for a universal language. Now not so quick. In reality more people speak Chinese than English or Spanish, so the logical choice is Chinese. I trust you see the problem. Convincing 200 delegates to adopt a single language would probably mark the end of the United Nations, as we know it today. Now the UN could hire translators for every possible language combination. That adds up to about 20,000 different translators and an enormous salary budget for the UN. We have not even considered where the 20,000 translators would be staying in the building. Perhaps you think that 20,000 is an outrageous amount, but think about it. The delegate speaking Punjabi needs 199 translators from Punjabi to each of the other 199 languages. The next delegate needs 198 translators, and then 197 and this number of combinations is close to 20,000. I hope you do not think that the UN uses such an approach. A clever two-step translation process is used. English is selected as an intermediate language. Do not get confused because English is not the selected universal language for all the delegates. It is an intermediate language. This requires 199 translators who can speak each one of the 200 languages and English. Assume that delegate from India speaks Punjabi. His or her message is first translated by one translator from Punjabi to English. Then 198 translators go to work and translate English to each one of the other 198 languages. Suppose that the delegate from Iran responds in Farsi. The process repeats itself in the opposite direction. Farsi is first translated into English. Now English is translated into 198 different languages, including Punjabi, and the delegate from India has a first response. Yes it does result in a time delay, but with a minimal number of translators everybody is able to communicate. The secret of the United Nations communication success is the two-step translation process with the intermediate English step. Java uses a similar two-step translation process to achieve one of its important goals of being platform independent.

2.4 Java Bytecode Computers have improved tremendously over the years and today most computers communicate rather well with each other. Still, it is common to create a program on one computer that will simply not work on another computer. As a summer workshop presenter for many years I would be careful to bring along my own Pascal and C++ software. Early on, I learned that my

programs, carefully written and checked in my own lab, would frequently hiccup in another lab with different computers and software. One of Java's goals is to be platform independent. The term platform is used abstractly here, but you can use it literally. If you walk from one platform onto another platform that are both of identical size and height it is easy to transfer. Different platforms cause difficulties. In the early days of train travel, Europeans experienced the inconvenience of changing trains at some country borders, because the railroad tracks were different sizes and trains could not continue.

Platform Independence A programming language is considered platform independent or portable if program source code created on one type of platform can execute on another platform without any difficulty. So how does Java accomplish this feat? Programs start out as source code written by a programmer in a somewhat human language, in this case Java. Now this source code needs to be translated into machine code that the computer understands. Now comes the problem. A machine code file on one computer does not necessarily make sense to another computer. The code file may be lovely ones and zeroes of the type that computers use, but not all computers follow the same rules of how to handle this low-level code. Look around when you travel. Not everybody drives on the right side of the road. Java starts by compiling the high-level source code into bytecode. Bytecode is almost machine code, but not quite. Computers cannot execute bytecode. The bytecode file that is created will be identical regardless of where it was created. Think about the UN. Bytecode is the intermediate English stage. For starters this means that Java compilers need to be available for all the different platforms to create the exact same bytecode for the same source code. You will be pleased to know that is exactly what Sun Microsystems did. Bytecode is not understood by any computer. It is not the machine code that is normally required for execution. However, bytecode is understood by a special program that is a Java interpreter. That is right, Java uses a compiler to translate programmer's source code into bytecode and then continues with an interpreter to translate and execute the bytecode file line by line.

Bytecode Bytecode is a low level-level code file that cannot execute as a regular machine code file. Bytecode is understood, and executed, by a Java interpreter. Do you understand the United Nations analogy better now? Platform-A uses the necessary compile software to translate a source code program into bytecode. This bytecode arrives at Platform-B. Platform-B has acquired a Java interpreter that will translate, and execute the bytecode according to Platform-B's requirements.

So the two-step translation process makes sense to you, even though platform-independence was never a high priority in your life? But why use both a compiler and translator? Aren't compilers more efficient translators? Good question and compilers do execute much faster than interpreters do. However, the efficiency comes with a price. Compilers are much larger programs than interpreters are. It takes sophisticated processing to determine if an entire program has correct syntax before the translation process starts. Interpreters are only concerned if one line has correct syntax and then proceeds to translate that one line. The answer to this question is connected with Sun Microsystems's second goal. Remember that their first goal was to create a platform-independent language, and that goal was achieved with the two-step translation process. Their second goal was to create a language that would be suitable with web pages on the Internet. Achieving this goal requires that a web browser can translate the provided bytecode. Using a compiler does mean efficient execution speed, but it also means a large program that needs to be added to the web browser. There is also a secondary problem. Compilers first translate the entire file before execution. Now this is a big plus and customers of application programs do not have to wait around to translate any programs. When you word process you do not start by translating some source code program. This was already done for you by the software company. You get the executable program and the only waiting time required is the time that it takes to load the program in memory and execute the instructions of the program. With a web browser there is another story. You click on some Internet link and now your web browser downloads some Java bytecode. Many people will get impatient waiting around for an initial translation process, even if the end result is quicker. If the web browser uses an interpreter that starts spitting out execution after each line of translation that means something is happening, and this approach is more desirable for a web browser.

Java Uses a Compiler and an Interpreter Java uses a compiler to translate the program source code created by the programmer into bytecode. Java then continues and uses an interpreter to translate the bytecode into executable machine code line by line. It must be clearly understood that it is not possible to take some Java bytecode and start executing this on any computer. Yes the code is meant to be portable to any computer with any operating system. However, this only works with a computer that has a Java Virtual Machine (JVM). JVM is the name for the interpreter that takes the bytecode and then executes the program. The name virtual is selected because with this interpreter in place, the computer now acts like any other computer that has the JVM. The key here is that there are many JVMs floating around. Everyone starts with the same bytecode, but these different JVMs all take the bytecode and create the appropriate machine code for its assigned computer. You may also understand some delay with web pages. First, there is the time required to actually download the web page file. Second, if the file contains Java bytecode then there will be a

second delay translating the Java file. You might wonder why somebody would then want to use Java on a web page if it causes a delay. Java has several nice benefits for the Internet. With Java it is possible to make web pages dynamic and interact with the user. Regular web pages can look pretty, but it requires some special language like JavaScript, VBScript or Java to provide information to web pages that can be processed. A second benefit is security. Regular HTML web pages do not hide the code. The code used to create the web page can be viewed in the browser. Frequently, this is not very desirable like in the case where you take an on-line test. It is not possible to see the original Java source code and even if you could view the Java bytecode in the browser, it would not make any sense at all.

2.5 Applications and Applets The term Java Applet is now so widespread that most computer and Internet users have seen or heard this term rather frequently. Do you know what an applet is? The name implies little application and that definition can cause confusion. A Word Processing program is a very large application. Another program that averages three numbers is a very small application, but the average program can either be an application or an applet in Java. When a program is written to execute in its own stand-alone environment, it is a regular application. This is different from a program that operates inside a web page. The web page is controlled by HTML, which is Hyper Text Markup Language, a special program language for web pages. When a Java bytecode file operates inside a web page, it must conform to certain web page standards that do not exist in a stand-alone environment. The web page controls the Java bytecode and not the other way around. Now if the bytecode is designed to operate inside a web page it is called an applet, otherwise it is called an application.

Applet or Application? A Java program designed to operate inside a web page is called an applet. A Java program designed to operate in a stand-alone environment is called an application. If the difference between application and applet is clear then you should realize that an applet could be much larger than an application. Now in reality it is true that most applications are larger than applets; it is just important to know that this is not a requirement. You must also understand that a web page can have multiple applets inserted throughout the entire website. Remember that it is not possible to create an entire website with Java. The Java applet or applets must operate inside an HTML environment that controls the website.

2.6 Java Tools Sun Microsystems provides the necessary software on their website to write Java programs and allows you to download this software free of charge, subject to a variety of legal conditions. Basically, to write Java programs you need an editor, a compiler and an interpreter.

The Basic Java Tools 1. A text editor to write Java program source code 2.

A compiler to translate source code into bytecode


An interpreter to translate and execute bytecode

Java provides you with the necessary compiler and interpreter software for free. The text editor is where there are many choices. There is a choice between a text editor that is part of an integrated environment and a stand-alone text editor. There are various software packages on the market that combine the editor to write the program with the Java translators and various other tools to develop Java programs. Such software has a complete Integrated Development Environment or IDE for Java. Most of the popular Java IDEs need to be purchased, but there are some excellent free products on the market as well. To understand the convenience of an IDE you must first understand what is involved with Java development using a stand-alone text editor. You need to start with a fundamental text editor. It is not necessary that this is a full-fledged word processor. There is no need to underline program statements, display words in different font sizes nor spell-check the program. Underlining Java code will confuse the compiler and spell-checkers are familiar with a human language like English, not a programming language like Java. A plain-old editor like Notepad is sufficient, and such a text editor comes free with any type of windows environment. The text editor is used to create, load and save Java programs. After a program is finished it needs to be saved. Now it is necessary to use the Java compiler to create bytecode. If the Java compiler is happy with the syntax of your program, the source code will be translated into bytecode. If some mistake is made in the sentence structure or syntax of your program statements, the compiler will respond with some error messages. At this stage you need to return to the text editor to identify and fix your errors. It is this process of going back forth between text editor and compiler that is avoided by the IDEs of a variety of products. The IDE is used to create the program and also compile the program. If a mistake is made in the creation of the program, the IDE automatically returns you to the editor part of the IDE to find your mistake. Now enough about the IDE because we won’t be focussing on that in this chapter anyway. After you have acquired some practice with using the Java compiler and interpreter at the command prompt, you will learn how to make your life simpler with a software package that integrates all the different Java tools. Right now let’s return to the Sun Microsystems Java software that can be downloaded for free. You already have Notepad, Wordpad or some kind of pad to create your programs. Now you need to download the software to do some serious Java programming. Sun Microsystems has a large website with the main URL (Uniform Resource Locator or Internet Address) at http://java.sun.com. You can start at the home page or you can go straight to the specific URL to download the latest version of Java, which is at: http://java.sun.com/j2se/1.4.1/download.html.

The latest version - at the time I wrote this - is Java 2 SDK 1.4.1. What that actually means will be explained shortly. This version will be used for the Exposure Java version, which is taught during the 2003-2004 school year. I will show you a sequence of web pages to help you download the correct software, starting with the figure 2.1 first web page. Select DOWNLOAD in the SDK column for Windows (all languages). SDK means Software Development Kit.***** We will be using Java 5.0 The information that follows, especially the actual web site displays, may be different from your experience. Few things are more dynamic than web pages on the Internet. First there is the issue of newer versions that constantly change. Second, there may simply be a change in the appearance of the web page that somebody decided to change. THESE IMAGES ARE OUTDATED –however you should read through them --- as stated on the sheet given to you at the end of school which are repeated here: We will be using JCreator at school. But you can download Dr. Java to get started with our first programs.

Steps for downloading an IDE 1)for Dr. Java Go to :


and choose the appropriate download

2) for JCreator Go to this page to download both JCreator LE and the JSDK. (There is a 21 day trial and then the cost is approximately $35) http://jcreator.com/download.htm 3) You could alternatively use Eclipse

or NetBeans

Nevertheless, there is an excellent chance that what you will see on your monitor will at least greatly resemble the pictures that follow. If they don't, you will get additional instruction from your teacher for this section. Figure 2.1

You might be curious about the many choices you see in the web page shown by figure 2.1. Two separate download columns are available , called JRE and SDK. The first column lets you download files a Java Runtime Environment (JRE), which is necessary to run Java programs that have already been created. These files are not for programmers or students of computer science. The JRE files are strictly for people who use existing applications, which in this case were created in Java. The second column contains the Software Development Kit (SDK) files. This set of files includes all the JRE files, but additionally you also get the special files that will translate your Java source code into the intermediate bytecode. Programmers and computer science students will need to download files from this column. If you are working on an Intel-based PC, you need to download the Windows version. You will note that there are a variety of Java SDK files for different operating systems. After you select the appropriate file for downloading, a window appears, shown in figure 2.2 that asks you for a variety of information. The information you provide is optional. You may want to skip the information requests and proceed directly with download Figure 2.2

You will now be treated to the customary legal license agreement that you must accept before you can download the software. You may be surprised why Sun Microsystems provides free software and then beats you over the head with legal language. This is actually quite understandable. Companies do not pay the bills by providing products for free. Frequently, the free software is a simpler version of a professional, not free, product. In other cases the product is free under certain conditions. For instance, Sun Microsystems is happy to let you use their software for free to learn Java and to write Java programs, but if you start to make money selling programs that use their software, the rules change.

Figure 2.3 shows the start of the rather lengthy legal document. I have carefully read this document, and you should read it for yourself. The legal language is confusing, but you can take my word that if you plan to use the software to learn Java programming, you may download this product for free without any concern. The entire legal description takes up many web pages. I have chosen not to display the entire document. Figure 2.4 shows the bottom of the page where you need to click the ACCEPT button.

Figure 2.3

Figure 2.4

Sun Microsystems has an interesting way to identify its software. In the early software-days, software used whole numbers for major revisions and decimals for minor changes. You would see numbers like Word Perfect V3.0 followed by Word Perfect V3.1 and so on. Some companies started to use calendar years, like Windows 95 and Windows 98. Java versions have a fascinating approach. There have been two major Java versions, which are Java 1 and Java 2. Currently we are using the Java 2 platform. Now within the Java 2 platform there have been improvements to the Software Development Kit or SDK for short. The latest edition of the SDK is now Edition 1.4.1. Hopefully, that explains somewhat the rather complicated name of Java (TM) 2, SDK, Standard Edition 1.4.1 shown on the web pages. I will make no attempt to explain the difference between Edition 1.4.1 and any previous editions. As of April 14, 2003, edition 1.4.1 is the latest, finished, edition and if newer editions are available when you read this you can use the same fundamental download and installation instructions. The web page in figure 2.5 finally gets you to the point where you can truly start to download a file. Click on the Download j2sdk-1_4_1_02-windows-i586.exe link and proceed to download the 37 MB file. Figure 2.5

The file you download is a compressed, self-extracting file. In the next web page you are given the option where to save this file. It is your choice. Maybe you have a special folder for download files or maybe you want all the Java files to be in the same folder. It does not matter.

Figure 2.6 shows the web page with the pop-up window where you specify the download location. Now you need patience depending on your Internet connection. With a slow modem you might want to order pizza or go out to see a movie. Downloading 37 MBs takes a long time with a slow modem connection.

Figure 2.6

After you download the software go to the download folder and double click on the selfextracting file and then install the Software Development Kit, SDK1.4.1. You will be prompted to accept the default directory or browse to pick your own. This is your choice, but I suggest you install in a convenient folder like Java, Java14 or some other simple folder name. The default directory that is created by the installation package is j2sdk1.4.1. You will find out shortly that it is necessary to change to that directory and use its name frequently at the command prompt. In other words, you will be typing this folder name frequently, hence my suggestion for a name like Java14, which I will use for this chapter. After installation, list the directory of your files. You can do this in windows, but you might as well get used to looking at the Dos Prompt or the Command Prompt, because you will first start learning Java programming by using the command prompt. After you get to the command prompt, change directories until you get to the directory where the SDK was installed. In my case it is installed in directory Java14. The name does not matter; what matters is that you see the directories and file names listed like the ones shown in Figure 2.7: C:\>cd Java14 C:\Java14>dir

Volume in drive C is MAIN Volume Serial Number is 2750-1708 Directory of C:\Java14 . 04-24-02 7:43p . .. 04-24-02 7:43p .. BIN 04-24-02 7:43p bin JRE 04-24-02 7:43p jre LIB 04-24-02 7:44p lib README TXT 8,277 02-07-02 12:52p README.txt LICENSE 13,853 02-07-02 12:52p LICENSE COPYRI~1 4,516 02-07-02 12:52p COPYRIGHT README~1 HTM 15,290 02-07-02 12:52p readme.html INCLUDE 04-24-02 7:44p include DEMO 04-24-02 7:44p demo SRC ZIP 10,377,848 02-07-02 12:52p src.zip 5 file(s) 10,419,784 bytes 7 dir(s) 1,148,334,080 bytes free C:\Java14>

Right now the main concern is with the BIN, short for BINary, directory. That is the directory where you will find the compiler and interpreter to run Java programs. Change to the BIN directory and take a look at the executable programs that start with the Java name, in figure 2.8. Note that these examples not only show you the desired output, but it also shows you the commands to enter to get the desired result, like the CD and DIR DOS commands. Figure 2.8 C:\Java14>cd bin C:\Java14\bin>dir java*.exe Volume in drive C is MAIN Volume Serial Number is 2750-1708 Directory of C:\Java14\bin JAVA JAVAC JAVADOC JAVAH JAVAP JAVAW

EXE EXE EXE EXE EXE EXE 6 file(s) 0 dir(s)

24,649 02-07-02 12:52p java.exe 28,766 02-07-02 12:52p javac.exe 28,772 02-07-02 12:52p javadoc.exe 24,670 02-07-02 12:52p javah.exe 28,762 02-07-02 12:52p javap.exe 24,651 02-07-02 12:52p javaw.exe 160,270 bytes 1,147,609,088 bytes free


Our main concern with this list of executable programs are two specific programs called javac.exe and java.exe. You will become intimately familiar with them. These are the two programs that create the bytecode file and execute the final result. The javac.exe file is the compiler that translates your program source code file into the intermediate bytecode. The java.exe file is the interpreter, which translates and executes the program. There are two other significant programs in the bin directory, which need to be mentioned. It is called appletviewer.exe and is shown in figure 2.9. This program allows programmers to view applet executions without changing to a web browser. This saves a lot of time and is a great convenience. The fourth program of interest is javadoc.exe, which will assist you in documenting your programs in the future. If you have not noticed it before, the text displays show the DOS abbreviated names on the left side and the complete names on the right side. Make sure that you use the complete names with your programs.

Figure 2.9 C:\Java14\bin>dir app*.exe Volume in drive C is MAIN Volume Serial Number is 2750-1708 Directory of C:\Java14\bin APPLET~1 EXE 1 file(s) 0 dir(s)


02-07-02 12:52p appletviewer.exe 24,675 bytes 1,146,847,232 bytes free


Required Java Programs javac.exe compiles Java source code into bytecode. java.exe interprets and executes bytecode applications. appletviewer.exe interprets and executes Java applets. javadoc.exe creates useful program documentation.

2.7 Setting Up Your Workspace Soon you will be introduced to the convenience of using a Java Integrated Development Environment or IDE. Writing programs with an IDE is more convenient that using the command-line approach. I will use the command line approach initially to help you clearly see the difference between the compiler, the interpreter and the type of error messages that are created. For a text editor we will use our good friend Notepad. Simple, friendly, uncomplicated Notepad will do very nicely. If Notepad is beneath your exulted text processing capabilities go for another editor. Just makes sure not to use a word processor that saves fancy word process character in their files like MS Word or Word Perfect. Those types of files will give you headaches. Now first you need to get to the DOS Prompt. It will help to create a DOS Prompt icon on your desktop. Windows has a DOS Prompt and NT and Windows 2000 use a Command Prompt. Both behave in the same way. Click on the Command Prompt and you will be taken out off your lovely Windows environment into the black and white world of commands entered at the flickering prompt. Are you displeased? Don't be because one thing you won't see is that tiresome hourglass that still shows up even on my fancy 2.0 GigaHerz machine that I am staring at right now. Now press to switch back to windows. This will put the DOS Prompt on the task bar. In Windows activate Notepad and either create a program in Notepad or load the desired program. In Notepad you create and view the program and at the Dos Prompt you will create the bytecode file and execute the final result. This is done quite efficiently by pressing to

toggle back and forth between the Windows-Notepad environment and the DOS Prompt. You can also click on the small icons in the task bar if you prefer. I mentioned before that you can select your own folder names and create your own organization. On the other hand, if you use the same approach that I use, the book examples will match your computer experience and give you greater confidence that you are working correctly. At any rate, your teacher will give you details where the sample programs are located. Do not confuse the Java SDK files - we just looked at - with the sample Java programs that will be presented in this book. The sample programs are not in the same location as the SDK files.

2.8 Compiling & Executing Applications It is not my intention to explain any Java syntax right now. There are programs already written that are ready for testing and they will give you practice in using the Java Software Development Kit. You should have a Progs02 directory, like figure 2.10, with a set of sample files in them. In a Windows environment the files names are displayed in order. This is not necessarily the case with a DOS prompt display. Figure 2.10 C:\Java\Progs02>dir Volume in drive C has no label Volume Serial Number is 3CB5-DC3F Directory of C:\Java\Progs02 . .. GO BACKUP JAVA02~7 JAVA02~1 JAVA02~8 JAVA02~9 JAVA02~1 JAVA02~2 JAVA02~3 JAVA02~4 JAVA02~5 JAVA02~6


04-16-03 4:39p 04-16-03 4:39p 86 05-30-02 9:22p 04-11-03 2:12p 298 04-16-03 6:12p 232 04-16-03 6:13p 416 04-16-03 6:12p 777 04-16-03 6:13p 195 04-16-03 6:12p 351 04-16-03 6:13p 292 04-16-03 6:14p 349 04-16-03 6:14p 376 04-16-03 6:14p 402 04-16-03 6:14p 3,774 bytes 12,775.02 MB free

. .. Go.bat Backup Java0202.java Java0203.html Java0203.java Java0204.java Java0201.java Java0205.java Java0206.java Java0207.java Java0208.java Java0209.java

If you see these files, you are in business and ready to get to work. I am assuming that you have your workspace set up as it was described earlier. You are ready to jump between the Dos Prompt and the Notepad text editor. Let us start by looking at the first program. It won't hurt to get a feel for the appearance of a Java program. Do not ask questions about why this and why that because you won't get answers. Right now your mission is to learn to handle the workspace properly so that you can go to town in the future and create programs. Load program Java0201.java, as is shown in figure 2.11, into the Notepad text editor or other text editor you are using. Figure 2.11

Future program examples will not be shown inside the Notepad window. It wastes a bunch of space and it also makes the chapter files bigger with all this graphics image stuff. One little trick about using Notepad. You may find it irritating that every time that you load a file in Notepad you need to specify the directory location. That is not necessary. Load a file, and even though you are not making any changes, go ahead and "save as" the file right back in the directory where it came from. From that point on, Notepad will faithfully stay in the directory where you are working. This is terrific, you have completed step-one of the Java program development process. You have created a program or actually Mr. Schram created a program and you have skillfully loaded the program and looked at it. No matter who did the work, it is the same first step. Now we go to the all-important second step where you need to create bytecode with a compiler. In case you did not notice it, the Java source code files all end with suffix .java and now all your intermediate bytecode files will end with *.class. Switch to DOS with and let us be efficient. We will go ahead and translate three programs, one after the other, all into bytecode. You will now use the javac.exe program to compile the Java source code programs into bytecode files. This means that Java0201.java will compile into Java0201.class and the same applies to the other programs. Use the same command for every file ending in .java, as shown in figure 2.13. Ignore the special Java0203.html file for now. You will need that file later, but not for this first compiling step.

But first, we are faced with an interesting dilemma. The javac.exe and java.exe files that you will need to use for compiling and executing your programs are in the C:\Java14\bin directory. Unfortunately, the sample programs you are using are located in C:\Java\Progs02. You can use the commands shown in figure 2.12, which will compile the first three Java programs in Chapter II. Figure 2.12 C:\Java\Progs01>C:\Java14\bin\javac Java0101.java C:\Java\Progs01>C:\Java14\bin\javac Java0102.java C:\Java\Progs01>C:\Java14\bin\javac Java0103.java C:\Java\Progs01>

Using the entire directory path for the javac.exe file, and later for the java.exe files is quite tedious. There is a handy path DOS command, which only needs to be typed once and then you do not need to use the long directory path anymore. You will tell the computer which directory path to follow to find potential files. In figure 2.13 you will see the path command, followed by the abridged commands to compile three programs. If you have sufficient DOS knowledge, you can alter the path statement in your autoexec.bat file, and the path will be automatically ready when the computer boots up. If this makes sense, great, if not there is no problem, follow the example below. Figure 2.13 C:\Java\Progs02>path c:\java14\bin C:\Java\Progs02>javac Java0201.java C:\Java\Progs02>javac Java0202.java C:\Java\Progs02>javac Java0203.java C:\Java\Progs02>

Now the Java compiler is very ho-hum when everything is fine. You are not told that you are doing a good job. You do not see some type of success!! message. You will see absolutely nothing, except a return to the DOS Prompt. This is good and you will not want to see message during the compiling phase. Right now we are going to do something that you will repeat frequently in the future. The last step was the second step in the Java development process, which is the compile from source code to bytecode file stage. Students, especially beginning students, have amazing skills and creativity in making a program file disappear outside the current space-time continuum. It pays to be a little paranoid. If step two was done correctly, you should now have three bytecode files that all end in the suffix *.class. Our reliable dir command will verify this request for us as shown in figure 2.14 Figure 2.14: Volume in drive C has no label Volume Serial Number is 3CB5-DC3F Directory of C:\Java\Progs02 . .. GO BACKUP JAVA02~7 JAVA02~1 JAVA02~8 JAVA02~9 JAVA02~1 JAVA02~2 JAVA02~3 JAVA02~4 JAVA02~5 JAVA02~6 JAVA02~1 JAVA02~2




298 232 416 777 195 351 292 349 376 402 427 637

04-16-03 04-16-03 05-30-02 04-11-03 04-16-03 04-16-03 04-16-03 04-16-03 04-16-03 04-16-03 04-16-03 04-16-03 04-16-03 04-16-03 04-16-03 04-16-03

4:39p 4:39p 9:22p 2:12p 6:12p 6:13p 6:12p 6:13p 6:12p 6:13p 6:14p 6:14p 6:14p 6:14p 7:08p 7:08p

. .. Go.bat Backup Java0202.java Java0203.html Java0203.java Java0204.java Java0201.java Java0205.java Java0206.java Java0207.java Java0208.java Java0209.java Java0201.class Java0202.class

JAVA02~3 CLA 14 file(s) 3 dir(s)


04-16-03 7:09p Java0203.class 5,226 bytes 12,754.59 MB free


Life is good, provided you have something similar to figure 2.14 on your computer. You see all source code *.java files and you also see the lovely bytecode files nicely ending in the allimportant *.class suffixes. Not every student will see these bytecode files. Some of you are ready to swear to everything that is holy that you followed directions and you did everything correctly. I believe you, your teacher believes you, and your friends believe you. However, unless you see three files ending in .class, like shown in figure 2.14, you will not be able to proceed to the next step. For step three you need to make a distinction between executing an application or executing an applet. Different tools are needed for each situation. Java0201.java and Java0202.java are applications. We will start with them. Java0203.java along with Java0203.html create an applet for a web page and requires quite a different approach. For the final step you will need to use an interpreter, which for an application program is the java.exe program. You need to use java.exe with the bytecode file, but you do not include the bytecode suffix, .class, in the translation command. The correct command is shown in figure 2.15. Figure 2.15 C:\Java\Progs02>java Java0201 JAVA TEST PROGRAM C:\Java\Progs02>

Keep in mind that the Java interpreter is case sensitive. You must enter the file name exactly as it is shown in figure 2.15, including upper and lower case letters. The statement JAVA TEST PROGRAM is the actual program output. The output is not very attractive but right now we want to keep it simple. In the future you will learn how to create more attractive GUI (graphics user interface) type programs. Now continue and translate/execute the second Java program. The process is the same. You use the java.exe program without the suffix and follow it with the name of the Java program without the .class suffix. You may think that it matters little because the .class suffix is not even used in the command. True, but you will not find your computer very cooperative if the *.class bytecode files are not available. The output of the second program is shown in figure 2.16. Figure 2.16 C:\Java\Progs02>java Java0202 Line #1 Line #2 Line #3 Line #4 Line #5 C:\Java\Progs02>

It is entirely possible that neither Java0201.java nor Java0202.java worked at all. You did verify that you have the required .class bytecode files but after attempting to interpret and execute the first program your output may resemble something closer to what is shown in figure 2.17. Figure 2.17 C:\Java\Progs02>java Java0202 Exception in thread "main" java.lang.NoClassDefFoundError: Java0202


You will get that error message if your computer has difficulty finding the location of your bytecode files. Not all computers will behave in the same manner. Computers boot up with different settings that result in different behavior. The problem that you are encountering can be solved by telling the java interpreter the location of your class files. You will be pleased to know that you only need to do this once per chapter session. Look at figure 2.18, which uses the set classpath= command. You may need to use that command, but make sure to alter the precise directory wording so that it reflects the actual directory structure that exists on your computer. Figure 2.18 C:\Java\Progs02>set classpath=c:\java\progs02 C:\Java\Progs02>

Using classpath It is very possible that the java.exe interpreter has difficulty finding your *.class bytecode files. The asterisk * in *.class is a wildcard character and means any file name with a .class ending. Add the CLASSPATH command at the DOS prompt to insure that your bytecode files can be found. Use a statement such as: c:\set classpath=c:\java\progs02 to indicate the location of the *.class bytecode files.

2.9 Compiling and Executing Applets Just for fun let us go ahead and treat Java0203.java like the previous two programs. I know teachers must not have a life if that is considered fun. In the previous section you already created a bytecode intermediate Java0203.class file. You learned that interpretation and execution is achieved with the java.exe program when used with the appropriate bytecode file. So what will happen when we

continue this process with the third Java program? Earlier it was mentioned that this program is meant to be an applet for a web page. Check it out and try to execute like is shown in figure 2.19. Figure 2.19 C:\Java\Progs02>java Java0203 Exception in thread "main" java.lang.NoSuchMethodError: main C:\Java\Progs02>

That error message looks a suspicious lot like the message some people may get when the java interpreter cannot find the bytecode file. For starters let us look at the actual Java0203.java source code. It is shown in figure 2.20. Compared to the previous two Java programs, this program looks different, but you can draw few conclusions because you really do not know what belongs in a program. Figure 2.20 // Java0203.java // This program is used to demonstrate how to execute a Java Applet // in either a web page or with appletviewer. import java.awt.Graphics; public class Java0203 extends java.applet.Applet { public void paint(Graphics screen) { screen.drawLine(0,0,800,600); screen.drawLine(0,600,800,0); screen.drawLine(100,300,700,300); screen.drawLine(400,100,400,500); } }

Now there is also the issue of the mysterious Java0203.html file. You had just started to reach a certain comfort level with the source code files that all ended in *.java and you did learn that the java compiler creates *.class bytecode files. So what is the story with the Java0203.html file? The .html suffix probably gives most people suspicions in the area of some type of web page and figure 2.21 shows that it is a very minimal program. Figure 2.21

You are getting ready to execute a Java applet, but applets are designed to run in web pages. This means that it is not possible to translate and execute an applet by using java.exe with the bytecode file. You need some type of web page and some minimal HTML code that will include

the Java applet. The actual web page requirements to include applets are a later topic. Right now accept the following. You need two files to see the execution of an applet. First you need the Java source code in a file, such as Java0203.java which needs to be compiled into Java0203.class. Second, you need some webpage segment, like Java0203.html that will include the Java0203.class file to execute the applet. Basically, this means that opening the web page will demonstrate the applet’s execution. The web browser includes a Java interpreter that can translate and execute the applet.

Two Ways to Run an Applet Use a web browser and load the HTML file that includes the Java applet. Use appletviewer.exe to execute the Java applet.

Right now you already have a notepad window open to create and look at source code. Additionally, you have a command prompt window active to compile java source code. It is possible, but somewhat tedious, to also open a web browser window. At the exact same location in the C:\Java14\bin directory where you found javac.exe and java.exe is also appletviewer.exe. The appletviewer program is easy to use. Just make sure that you use the *.html file and not the *.class file. When you execute an application it is not necessary to use the file suffix. With an applet the html suffix is required, as is shown in figure 2.22 below, which will result in the display in figure 2.23. Your display may be slightly different because only the appletviewer window is shown. This window will display on top of your desktop. You will need to close the appletviewer window before you can continue. Figure 2.22 C:\Java\Progs02>appletviewer Java0203.html

Figure 2.23

Are you required to use appletviewer? No, you can test your Java Applet with Internet Explorer or Netscape. Make sure that your browser is current enough to handle Java applets. Open Java0203.html in your browser and your display will look something like figure 2.23. From now on any applet testing will be presented in this book using appletviewer. The use of appletviewer is convenient. It is an executable program in the same bin location as javac.exe and java.exe. Executing appletviewer will change the monitor to a graphics display, and return to the command prompt when you are finished. This is a considerable time savings if you are viewing a large variety of Java applet examples.

Windows 2000 and Windows XP Notice The graphics display in figure 2.23 may only show diagonal lines when you try it on a computer running Windows 2000 or Windows XP. Move your mouse slightly and the other lines will show up.

2.10 Is It Java 2 or Is It Java 1.4.1? You are an intelligent student who follows directions. You went to the Java.Sun.com website and you downloaded the Java tools. You have looked at various book stores that seem to be filled with books titled Java 2 and yet you also see references made to something like Java 1.4.1, JDK 1.4.1 or SDK 1.4.1. What exactly is the difference? Or are they all the same? Java is the name of the program language created by Sun Microsystems. Shortly after the introduction of the initial Java software, Sun Microsystems developed a major language improvement,

which they called Java 2. The Java software is a complete development kit that includes the compiler, interpreter, appletviewer and other goodies. Sun Microsystems refers to their older kit versions as JDK, which stands for Java Development Kit. Currently they have switched to SDK, which stands for Software Development Kit. Sun Microsystems calls their product Java 2 SDK, version 1.4.1. It is a little like Windows 95 and Windows 98. Each one of those products had multiple versions, but they did not use Windows 95.1 and Windows 95.2. Over the years small bug fixes and other improvements were not sufficient to change the name Windows 95, but there are different versions of Windows 95 and Windows 98. So right now we have the second major Java development package called Java 2. Within the Java 2 platform you download SDK Edition 1.4.1, at least at the time when I wrote this chapter. It all likelihood you may see SDK Edition 1.4.2 or SDK Edition 1.5.0 when you read these pages.

2.11 Java Input/Output Issues In the early days of the personal computer, output was plain, simple text. A set of standard characters was used for output display and in the confines of 256 characters, programmers generated output. Programs could still be very complex. In the late seventies the airline industry started using reservation programs that exceeded one million lines of programming code. The monitors used by airline reservation agents were not pretty. They showed plain characters, but they functioned very nicely. Airline tickets in the early days and still today are not required to print anything fancy. In other words, text output can be very functional, and it is a good place to start. Ironically, the first program example in this chapter will be using a windows graphics input/output approach. This program is shown to demonstrate the difference and it is also shown to make you realize that there is added complexity with this style of programming. But before we get too involved with all this input and output stuff we need to understand how the College Board, who is responsible for the AP Computer Science curriculum and examination, thinks about the Java Input/Output issue.

College Board View on Java Input Output 11.User input is not part of the AP Java subset. There are many possible ways for supplying user input; e.g., by reading from a BufferedReader that is wrapped around System.in, reading from a stream (such as a file or an URL), or from a dialog box. 12. Testing of output is restricted to System.out.print and System.out.println. As with user input, there are many possible ways for directing the output of a program, for example to System.out, to a file, or to a text area in a graphical user interface.

In a nutshell, this states that input is not considered at all for testing and output will be limited to text output that is created with println. You may be surprised about the position of the College Board. With time you will realize that the significant computer science concepts do not revolve around input/output issues. Now you do not need to read the entire document presented by the College Board to learn that they fully realize the importance to teach input/output with Java or any other programming language. It just means that the AP Computer Science testing focus is not in that area. The teaching reality of this issue is that programs become mighty dull and very difficult to test unless there is a means to enter data and view the results. You will learn a variety of

input/output approaches in this course and in months to come you may be quite pleased with the types of programs that you are able to create. In the next section you will see a set of small programs that explains how to write programs with text output. Right now, take a look at a short program that uses graphics windows for input and output. Let us take a look at the execution first. As you did in the last chapter, you must first translate the Java source code file with the javac.exe compiler into a bytecode file, and then execute the bytecode file with the java.exe interpreter. This requires using the statement, shown in figure 2.24, to create the bytecode file, followed by the command, shown in figure 2.25, to execute the program. Figure 2.24 C:\Java\Progs02>javac Java0204.java C:\Java\Progs02>

Figure 2.25 C:\Java\Progs02>java Java0204

The output is actually a set of small windows. They display somewhat oddly on top of the existing screen, but an attempt was made to demonstrate a rather minimal graphics input/output program. The purpose of the program is to display the sum of two entered integers. Figure 2.26 shows all three of the windows. Keep in mind that during execution you will only see one window at a time. Figure 2.26

Those three windows were kind-of-nice, and they did look like the type of input or output that you expect in a windows, graphics user environment, called GUI for short. Now go ahead and take a look at the actual Java source code file that created that program. The programmer's code is shown in figure 2.27. The program is relatively short because Java has provided a large quantity of tools to help create this graphics display.

Figure 2.27 // Java0204.java // The program demonstrates how to input and output data with GUI windows. // Even with this rather plain GUI example, there is considerable complexity // involved, and explains why programs will focus on text window output.

import javax.swing.JOptionPane;

public class Java0204 { public static void main (String args[]) { String strNbr1, strNbr2; int intNbr1, intNbr2, sum; strNbr1 = JOptionPane.showInputDialog("Enter Number 1"); strNbr2 = JOptionPane.showInputDialog("Enter Number 2"); intNbr1 = Integer.parseInt(strNbr1); intNbr2 = Integer.parseInt(strNbr2); sum = intNbr1 + intNbr2; JOptionPane.showMessageDialog(null,intNbr1 + " + " + intNbr2 + " = " + sum); System.exit(0); } }

The program includes a pretty large number of features, which require lengthy explanations. This is hardly a good starting point. This example was shown for two reasons. First, we wanted you to see the difference between graphics output and text output. Second, we also wanted you to realize that graphics programs carry extra baggage, which adds complication to a program. This extra baggage is not very desirable at this early stage. In case you did not realize it, there are three different styles of Java programs, and you have seen an example of each type. There is the plain, vanilla text-style application program. There is the graphics-style application program, and there is the Java applet, which is predominantly a graphics-style program that executes only in a web page.

2.12 Text Output With println We will now continue and focus on the elements of text output. As a matter of fact, we are only looking at output. Program input is actually more complex than program output. Our first concern is to digest a program that is similar to the application programs demonstrated in the last chapter. At that introduction your job was to learn how to compile and execute a Java program. Now you need to take a closer look. The output windows in the first half of this chapter will

include the javac.exe and the java.exe commands that are necessary to compile and execute each program. Frequently, the program source code and program execution will be shown close together, as is the case with figure 2.28. The program source code will be shown in an arial font style and the program execution output will be shown in new courier font style. The output is a realistic display. The font-style of the program source is dictated by the texteditor or the Java integrated development environment that you use. My main concern is distinction. Figure 2.28 // Java0205.java // This program demonstrates text output with println. // Note how the file name, Java0205, is the same as the // class identifier Java0205. // Make sure that you observe "case-sensitivity". public class Java0205 { public static void main (String args[]) { System.out.println("Plain Simple Text Output"); } } Java0205.java Output C:\Java\Progs02>javac Java0205.java C:\Java\Progs02>java Java0205 Plain Simple Text Output C:\Java\Progs02>

The time has come to take a closer look at a Java program and start to digest what is happening. You may agree that the text-style program of Java0205.java is simpler looking than the graphics-style program of Java0204.java. Simple is relative so let us take a look at this socalled, simple program and explain some important details. Program Java0205.java is displayed again in figure 2.29, but this time, numbers are supplied for each line in the program to make an easy reference. Please realize that the numbers are not part of the program. Figure 2.29 #1 #2 #3 #4 #5

// Java0205.java // This program demonstrates text output with println. // Note how the file name, Java0205, is the same as the // class identifier Java0205. // Make sure that you observe "case-sensitivity".

#6 #7 #8 #9 #10 #11 #12

public class Java0205 { public static void main (String args[]) { System.out.println("Plain Simple Text Output"); } }

Line #s Brief explanation of the program statement

Lines #1 These five statements are comments for the program. The comments are not compiled - #5 into bytecode, nor will they ever be executed. The two // indicate what follows is a comment. Line #6 This statement starts your program. Use the Java keywords public class and follow them with the program name. Line #7 This is the opening brace of the program. Braces contain program blocks. Line #8 Every application program has a main segment. For now you will use public static void main every time. Line #9 This is the opening brace of the main module block. Line #10 Here is the actual program statement that executes something. The keywords System.out.println display the characters placed between the double quotes that follow. Line #11 This is the closing brace of the main module block. Line #12 This is the closing brace of the program block. A program language cannot use human language. Human language is idiomatic, ambiguous, and the meaning of words change. When I first learned English, grass was something you mowed, bad was coming home after curfew and gay was fun loving and spirited. A program written with those words forty years ago would not do very well today. Writing programs has close similarities to writing an essay. There is an important creative part that revolves around telling a story, debating a point or explaining a concept. An essay is made up of individual sentences that follow proper sentence structure, and each sentence is made up of individual words. It is not possible to create an effective sentence without knowing the meaning of the words that make up the sentence. Likewise in a program language you need to know the meaning of the special words that perform some specific purpose. Right now we shall call all the special words used by Java, keywords.

Java Keywords and Program Statements A Java keyword is a word that has a special meaning in the program or performs a special function. One or more keywords combine to make a program statement. Keywords in Java are case-sensitive. keyword, which is not the same as Print.

This means that print is a Java

Have you seen many keywords so far? You certainly have and these keywords include public, class, static, void, main, String and System.out.println. This is already a pretty good size list for starters. At this stage assume that all these keywords, except for System.out.println are necessary in every program and an explanation of their purpose will come at a later time. In this section you need to learn about println. You did notice that println is attached to some other keywords with a period separation. System.out precedes println and you probably suspect that the periods indicate some type of relationship. You are quite right and System.out means

the output of the system. The third keyword, println, displays output and provides a carriagereturn/line-feed (crlf), as is shown by program Java0206.java, in figure 2.30. Figure 2.30 // Java0206.java // This program demonstrates that generates a // carriage-return/line-feed.

public class Java0206 { public static void main (String args[]) { System.out.println("Text Output Line 1"); System.out.println("Text Output Line 2"); } }

Figure 2.30 Java0206.java Output C:\Java\Progs02>javac Java0206.java C:\Java\Progs02>java Java0206 Text Output Line 1 Text Output Line 2 C:\Java\Progs02>

The program output shows that each println statement generates output on its own line. You might mistakenly think that this is caused by the fact that there are two println statements or two separate lines. Such an assumption is logical, but incorrect. Check out the next program example in figure 2.31. This program is almost identical to the previous program. There is one small, significant difference. The keyword println is now changed to keyword print. Figure 2.31 // Java0207.java // This program shows that does display a linefeed. // Note that the Second Output is displayed immediately adjacent // to the first output without any spaces. public class Java0207 { public static void main (String args[]) { System.out.print("First Output"); System.out.print("Second Output"); } } Java0207.java Output C:\Java\Progs02>javac Java0207.java C:\Java\Progs02>java Java0207 First OutputSecond Output C:\Java\Progs02>

In program Java0207.java there are two separate program statements for each print keyword, but the output is displayed on one line. Do you also notice that the actual characters that are displayed are the same characters that you see in the program statements between double quotes after the println or print keywords? You may decide that it is necessary for println or print to finish the statement with parentheses that contain some string of characters to be displayed. This is not always a requirement. The next program example in figure 2.32 includes one program statement where println is followed by only a set of empty parentheses. It appears that such an "empty" println statement generates a carriage return. Figure 2.32 // Java0208.java // This program shows how to skip a line between statements. // Using with empty parenthesis will generate // a carriage-return/line-feed.

public class Java0208 { public static void main (String args[]) { System.out.println("Text Output on Line 1"); System.out.println(); System.out.println("Text Output on Line 3"); } } C:\Java\Progs02>javac Java0208.java Output C:\Java\Progs02>java Java0208 Text Output on Line 1


Text Output on Line 3 C:\Java\Progs02>

System.out.println and System.out.print Both keywords println and print generate an output display of characters contained between double quotes. Both println and print follow keywords System.out. println("Java is an island in Indonesia.") will display: Java is an island in Indonesia. print("Java is an island in Indonesia.") will also display: Java is an island in Indonesia. The keyword println generates display followed by a carriage-return/linefeed (crlf).

The keyword print generates display without a crlf. The statement System.out.println(); generates a crlf, meaning skip a line, without any other display. You have learned or observed that every Java program appears to have a statement like public class Java0205. You have also observed that the name, called identifier, which follows class is the same name as the source code file name. Basically, you accept such a directive and do not get too excited. Well, when I learn I tend to be excitable and I wonder what will happen if I disobey the rule and use a different class name than the file name. The next program example is stored as program Java0209.java. This source code is compiled into bytecode using the exact same procedure as any of the previous programs, and you probably do not expect any indication of errors. Figure 2.33 shows that the name following class is now Boohiss, which is noticeably different from the convention of using Java0209. Any ideas what the output will be? Are you expecting a few lines of text following the logic of the println keyword? Or do you expect maybe something else? Most observant students will know something is happening. Why does Mr. Schram make such a big deal over this class name and file name if it doesn't or make any difference? Figure 2.33 // Java0209.java // This program demonstrates that the file name of a program // and the public class name must be identical. // This program will not compile.

public class Boohiss { public static void main (String args[]) { System.out.println("The bytecode file name"); System.out.println("will be the same as the"); System.out.println("public class identifier."); } }

Figure 2.34 shows the output of program Java0209.java. Output may be an incorrect term. You are treated to an error message, which tells you in no uncertain terms that the file name and the class name should be identical. Figure 2.34 Java0209.java Output C:\Java\Progs02>javac Java0209.java Java0209.java:7: class Boohiss is public, should be declared in a file named Boohiss.java public class Boohiss ^ 1 error


File Names and Class Names The external file name of your program needs to be identical to the public class name inside your program, minus the java extension. For example: If you use public class Howdy in your program then you need to save the program with Howdy.java.

2.13 A Simple Program Template Learning the early stages in programming in any language is quite difficult and confusing. It is likewise no picnic to try and teach the introductory topics. There are so many interrelated concepts that need to be understood before you can have a good comprehension of the big picture. It is simply not possible to explain every topic with total clarity. Clarity takes time, it takes serious exposure to a lot of examples and doing a bunch of lab assignments. You can do something that will make learning easier. Accept certain facts without explanation. Actually, you do this all the time even if you are not aware of it. Did you or anybody else you know ever purchase a car and require a complete understanding of the internal combustion engine before you turned the key. Certainly not. Take the key, find the keyhole, start the engine and drive off. You let the engine worry about its business and you will worry about the steering of the car. It really is somewhat like that with computer science. So much needs to be explained and there needs to be a starting point where you can focus, learn and manage writing programs yourself. For a number of chapters and lab assignments you will only be creating application programs with text output. Such programs will always require the same number of initial keywords. It is possible to create a template for this type of program and use that template to start any program example or lab assignment. A template program is shown in figure 2.35. Figure 2.35 // Template.java // This program does not display any text, nor does it process any information. It is a // template for an application, text-output, program. public class Template { public static void main (String args[]) { // The comments need to be replaced with // program statements that process and // display information.

} }

Important Template Program Points  Comments are optional in any program, including your templated program.  Start your program with the program statement: public class  In the example the class identifier is Template, which is not a required name.  Use the four braces as shown in the example.  Use the following statement exactly as shown: public static void main (String args[])  Write the program code that you create between the inner braces, replacing the comments.

2.14 Summary Sun Microsystems provides free software to compile and execute Java programs. The Java Development Kit (JDK) or Software Development Kit (SDK) can be found on Sun's website at http://java.sun.com. The current version (April, 2003) finished by Sun is Java 2, SDK Version 1.4.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 Three Steps of a Java Program 1. Write the Java source in some text editor. The source code file must end with .java, like Java0203.java. 2. Translate the source code file with a Java compiler into an intermediate bytecode file that will end with .class, like Java0203.class. 3. Execute the bytecode file with a Java Virtual Machine (JVM) program, which is an interpreter. 3a. The JVM for a Java application is java.exe. 3b. The JVM for an applet is part of a web browser or you can use appletviewer.exe. The second half of this chapter focused on writing short text-style output programs. A graphicsstyle program was shown to explain the difference and to point out that the graphics-style is more complex than text-style. 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. Keywords are divided into groups of reserved words, pre-defined identifiers and user-defined identifiers. User-defined identifiers are names selected by programmers to identify the name of a program and other parts within the program. An identifier can be a set of alpha-numeric characters and the under-score character. Program identifiers need to start with an alpha character. Java programs require a number of keywords, which are reserved words, which were not explained in this chapter. Keywords like public static, void, main and others will be explained in future chapters. It is still possible to write programs without understanding the meaning of these words. A special template was introduced that placed the keywords in the correct location. It is now possible to write a program by writing program statements between the program block braces of the main program segment.

Chapter III Java Simple Data Types Chapter III Topics 3.1



Declaring Variables


Using JCreator


The Integer Data Types


Memory Overflow Problems


The Real Number Data Types


Arithmetic Shortcut Notations


The char & String Data Types


The Boolean Data Types


Declaring Constants


Documenting Your Programs


Mathematical Precedence


Type Casting


Escape Sequences


The AP Java Subset



3.1 Introduction

In the early days of your mathematics classes only constants were used. You know, numbers like 5, 13 and 127. You added, subtracted, multiplied and divided with numbers. Later, you had more fun with fractions and decimal numbers. At some point - the exact year does not matter - variables were introduced. In science and mathematics it is useful to express formulas and certain relationships with variables that explain some general principle. If you drive at an average rate of 60 mph and you continue for 5 hours at that rate, you will cover 300 miles. On the other hand, if you drive at a rate of 45mph for 4 hours, you will travel 180 miles. These two problems are examples that only use constants. The method used for computing this type of problem can be expressed in a more general formula that states: Distance = Rate  Time The formula is normally used in its abbreviated form, which is d = r  t. In this formula d, r and t are variables. The meaning is literal. A variable is a value that is able to change. A constant like 5 will always be 5, but d is a variable, which changes with the values of r and t. Both r and t are also variables. Variables make mathematics, science and computer science possible. Without variables you are very limited in the type of programs that you can write. In this chapter you will learn how to use variables in your programs. 3.2 Declaring Variables A program is made up of words, which usually are called keywords. The keywords in a program have a very specific purpose, and only keywords are accepted by the compiler. A compiler will only create a bytecode file if the

source code obeys all the Java syntax rules. The first rule is that only keywords known to the Java compiler can be used in a program. Another syntax rule is that each variable needs to specify its data type. How about first concentrating on one rule at a time? So what exactly is a keyword? You have seen certain words like void, static and println, but that only tells part of the story. Keywords can be divided into three categories. Java Keywords 

Reserved Words

Pre-defined Java Identifiers

User-defined Identifiers

Reserved Words Reserved words are part of the Java language the same way that table, walk and mother are part of the English language. Each reserved word has a special meaning to Java and these reserved words cannot be used as an identifier for any other purpose in a program. Reserved words that you have seen so far are public, void and static.

Predefined Identifiers Java has a large number of libraries that enhance the basic Java language. These libraries contain special procedures that perform a variety of tasks to simplify the life of a programmer. You have seen two procedures so far: print and println. They are special routines that display output in a text window.

User-Defined Identifiers The third and last type of word used in a program is selected by the programmer. Programmers need to select an identifier for each variable that is used in a program. Variables are used in a program for many purposes, which you will see shortly. You already have familiarity with the general concept of a variable from mathematics. It is possible to say Distance = 60 * 10 to compute the distance traveled at 60 mph for a 10 hour period. That statement comes from the general formula of D = R*T, which uses three variables. Make sure your identifier selection is neither a reserved word nor a predefined identifier. The rules for naming an identifier are simple. The identifier can use alphanumeric characters and the underscore character. Additionally, you need to be sure that the identifier starts with an alpha character. You will note that this rule is identical to the rule for naming the class identifier of your program. Fine, you have accepted the need to declare the variables that are used in a program. You have sympathy with the compiler who needs to sort out the proper keywords from the typos, mistakes, and general attempts made by sometimes-clueless programmers. Of course, you do not fall in the clueless category. Now what about this second syntax rule mentioned earlier, something about indicating a data type with a variable? What is that all about? The data type rule is for the purpose of using memory efficiently. All variable values need to be stored in memory during program execution. As long as the program is alive and the variable is in use, its value will be stored somewhere in RAM. It is certainly possible to skip the whole data type scene and give the same exact memory to each variable. Now is that not the same as stating that every room in a building needs to be the same size? How about meeting rooms, closets, offices, bathrooms and offices; should they all be the same size? No, that is too silly; a room size is designed for its purpose. Building materials are expensive and lease rates are outrageous. A thrifty business person makes sure to rent the proper amount of space; no more and no less.

Variables are needed to store information such as a single character, which can be placed in one byte or two bytes of memory. Other variables store large numbers that require four or eight bytes of memory. There are also variables that need to store the street address of a customer. Such values may require around 50 bytes of memory. The efficient and practical approach is to declare all variables before they are used and let the compiler know how much memory is required. Once the compiler sees the data type of the variable, memory space will be reserved or allocated for the specified data type. There is a good selection of simple data types in Java, but for starters take a look at program Java0301.java. That program uses an integer data type, which is abbreviated int in Java. In figure 3.1 you see that the data type, int, starts the declaration statement, followed by the variable identifier, which in this case is either A or B. This program also introduces the assignment statement, which is a statement that assigns a value to a variable. The equal sign is the assignment operator, and does not create an equation. Novice programmers often think that a program statement, like A = 10; is an equation. Such a statement should be read as A becomes 10 or 10 is assigned to A, but not A equals 10. Figure 3.1 // Java0301.java // This program demonstrates how to declare integer variables with , // and it shows how to display the value of a variable with .

public class Java0301 { public static void main (String args[]) { int a; int b; a = 10; b = 25; System.out.println(); System.out.println(a); System.out.println(b); System.out.println(); } }

Java0301.java Output C:\Java\Progs03>javac Java0301.java C:\Java\Progs03>java Java0301 10 25 C:\Java\Progs03>

Java is picky about a variety of things and pickiness in a language is good or bad depending on your point of view. Experienced programmers like a program language to be relaxed and give them lots of slack. Novice programmers benefit more from a tight leash that allows little breathing space. Most people agree that Java does not let you jump around much. As a matter of fact, Java insists that a variable is assigned a value before the variable value is used.

You declare the variable, so you see to it that it gets a value. Look at Java0302.java, figure 3.2. That program will not even compile. Figure 3.2 // Java0302.java // This program is Java0302.java without assigning values // to the variables. Java does not compile a program that // attempts to use unassigned "simple" data types. public class Java0302 { public static void main (String args[]) { int a; int b; System.out.println(a); System.out.println(b); } } Java0302.java Output C:\Java\Progs03>javac Java0302.java Java0302.java:13: variable A might not have been initialized System.out.println(A); ^ Java0308.java:14: variable B might not have been initialized System.out.println(B); ^ 2 errors C:\Java\Progs03>

Program Java0302.java is almost identical to the previous program minus the assignment statements. This makes Java very unhappy and you are rewarded with some error messages that let you know your evil programming ways. Java is polite though. The error message says that the variable might not have been initialized, and we both know that there is no initialization in sight.

It is a good habit to assign an initial value to a variable as soon as the variable is declared. It takes less program code to use such an approach and you remember to take care of the variable the same time that you first introduce the variable to your compiler. It is possible to combine the declaration statement and the assignment statement into one process. This is shown in figure 3.3 by program Java0303.java, and you will note that it produces the exact same output as the earlier program shown in figure 3.1.

Figure 3.3 // Java0303.java // This program demonstrates that it is possible to declare a variable // identifier and initialize the variable in the same statement. // It is a good habit to initialize variables where they are declared.

public class Java0303 { public static void main (String args[]) { int a = 10; int b = 25; System.out.println(); System.out.println(a); System.out.println(b); System.out.println(); } } Java0303.java Output C:\Java\Progs03>javac Java0303.java C:\Java\Progs03>java Java0303 10 25 C:\Java\Progs03>

The early program examples in this chapter displayed string literals, which were contained between the quotes of a println statement. Now you see that the double quotes are gone, and the value of the variable is displayed by println. You are probably quite impressed by this humble Java println method, but wait there is more. You can combine the literal character string output with the variable value output by using the plus operator, as is shown in figure 3.4. Figure 3.4 // Java0304.java // This program combines output of literals and variables. // "a: " is a string literal, which displays the characters a: // a is an integer variable, which displays its integer value 10. public class Java0304 { public static void main (String args[]) { int a = 10; int b = 25; System.out.println("a: " + a); System.out.println("b: " + b); } } Java0304.java Output C:\Java\Progs03>javac Java0304.java

C:\Java\Progs03>java Java0304 a: 10 b: 25 C:\Java\Progs03>

3.3 Using JCreator You have compiled a variety of sample programs starting with the first chapter. Up to now a distinction exists between the text editor software, used for writing or viewing the program source code, and the Java software used to compile and execute the program. Basically, you have jumped between the text editor and the command prompt. This system is not really so bad and it does help to make a nice distinction between the compiling process and the interpretation/execution process. Java uses javac.exe to compile source code into bytecode, and java.exe to interpret and execute the bytecode. There is a more convenient way. You can use an integrated development environment or IDE. For many program languages there is software available that packages the program editor, filer, compiler, and executor all in one convenient environment. With the Java program language something interesting happens. You will still need the Java software, SDK 1.4.1, which was explained in Chapter II, when you work with the available IDEs. Sun Microsystems does not object to people creating software that makes it easier to write Java programs, but they want the fundamental Java software, created by Sun Microsystems to be used. This means that before you install any type of IDE, you must first install the Java software. This is the exact same software that you have been using for the last couple of chapters. There are many excellent Java IDE programs available on the market for purchase. There are also a surprising number of Java tools on the Internet ready for free downloading. I get numerous emails requesting information about the best Java IDE. I do not know what the best IDE is simply because I have not taken the time to check out all the available products. I have neither the time nor the desire for such a project. I have looked around until I found something that works well and is free. Free is very important to me, because that means that students can use this software at home. The Java SDK package is already free and now we continue with an IDE that is free as well. This is a great combination for our students. The IDE that I use right now is JCreator 2.50 LE, distributed and copyrighted by Xinox Software. I will explain shortly where you can download this product. Is JCreator the best IDE on the market? I am not qualified to make that statement because I have not looked at every option. Even if I had tested every option, it would still be a subjective opinion on my part. I do know that JCreator works very well and is easy to use. You will also find that certain IDEs work better for creating programs from scratch and others are better for viewing large existing programs. If you are already using some IDE, like CodeWarrior, JBuilder or BlueJ, please continue using that IDE and skip this section. Java programs are not IDE dependent, and this section in inserted for the convenience of my personal students who will be using JCreator. It is not my intention to explain all the different capabilities of JCreator. I am not so sure if I know all the capabilities. I will explain how to download the software and how to get started. Right now the mission is to be able to work with existing programs and to write simple new programs using JCreator. JCreator can be downloaded from http://www.jcreator.com. Figure 3.5 shows the home page of the company. You will see a variety of tabs and links you can select, but the information you want is on the main page after you scroll down. In figure 3.6, you will see the page section with the desired download link. Figure 3.5

Figure3.6 You will notice that there are two download options. There are the JCreator Freeware and JCreator Pro trial versions. You notice very specific evidence that JCreator is free. Xinox Software company hopes that you will

like their free Learning Edition and pay the money to purchase their more sophisticated Pro edition. The Pro

Edition adds some nice features, which are particularly useful for professional programmers. You may wish to pay the money to download the nicer version. If you stick with JCreator 2.50 it means that you can download the software with total peace of mind that it is perfectly legal. I assure you that the Learning Edition is very adequate for the lab assignments that are required for your high school computer science and webmaster courses. You will be asked where to save the download file. I suggest that you create a folder inside the Java14 folder, called JCreator and download the zipfile to that location. After you download the file, you will be automatically prompted to install the software. If for some reason this does not happen, go to the JCreator folder and click on the setup.exe file. The installation is very rapid and easy to do. Follow the questions and use common sense. There is one very significant part that requires special attention. JCreator works in conjunction with the Sun Microsystems software that should already be loaded on your computer. The first time that you load JCreator you need to indicate which folder the Java SDK is located. On my computer the folder is Java14. If you fail to provide the correct folder, your future programs will not compile. JCreator will not know where to go to find the javac.exe file. You will also be asked the location of the Java docs files. These files are provided by Sun MicroSystems to document all the many available features of the Java program language. If the Java documentation is loaded, JCreator can access this feature with their IDE. If you have loaded the Java docs specify the directory, otherwise skip that section. After you have performed a correct installation click on the JC icon and take a look at your new Java software tool. You should be seeing a display that is pretty much identical to figure 3.7. This is the default display with four windows. It is possible that you will see fewer windows or that the windows have a different size. Figure 3.7

Click on File selection and load the Java0301.java file. This process is pretty much the same for any type of Windows application. JCreator is no different. Your display will change and look like figure 3.08.

A Note About Projects It is possible that you have prior experience with IDEs that require the creation of a project before any program work can start or is even possible. JCreator can compile and execute programs without projects. At a later chapter, when program complexity increases, you will learn about projects and how to use them in Jcreator. Figure 3.8

You will notice a multi-colored display in your text window. Different words have different colors. You may not care for these colors at all and you can change them if you like. Such details you will need to figure out yourself. Display changes, and other settings are altered with the configure/options selection. It is possible to change the entire monitor to a large text editor window. Figure 3.9 has enlarged the left-top corner of the IDE. Look at the third toolbar row from the top. The fifth icon from the left is a green monitor. Click on that icon and you will get a full screen text window. Figure 3.10 shows the large window. Click on the little monitor icon window to return to the regular IDE environment. Do not click on the x, which will close the icon window. If you accidentally close the monitor icon window, return by pressing the key.

Figure 3.9

Figure 3.10

Your Java0301.java is loaded in the editor window. How do you compile this program? In the past you used javac.exe at the command prompt. You will still use the Java compiler, but now JCreator does much of the work for you. You can go to the Build selection in the top bar and then click compile followed by execute. It is simpler

to use two convenient icons. In figure 3.11, on the third bar on the right side, you will see an icon with a red down arrow. That is the compile icon. Next to it is an icon with two blue squares, which is the execute icon.

Figure 3.11

You need to stop for a brief reality check. JCreator is a very nice package and it will make your life simpler, but your programs will now compile a little slower. At the command prompt you access the Java compiler javac.exe directly and you specify the file that needs to be compiled. With the supplied information the compiler goes to work and you will get word soon about the success of your program. Command prompt compiling has the advantage of speed. With an IDE you click on some button to tell the software that it is time to start compiling. However, the IDE is not actually a compiler. It knows where to access the compiler and after the Java compiler has responded, the IDE then turns around and passes the response on to the output window. This means that there are now more steps involved for the compiling process. Ironically, there will be less steps for you. Your process will be simpler, but it does mean more computer processing and that also means a longer time to complete the process. After you click the compile icon, you wait patiently. It really does not take that long and you will get some response. If your program has errors, the bottom output window will display the errors. The error messages are identical to the ones you would get at the command prompt. The difference is that they are displayed inside the JCreator IDE output window, at the bottom of the window. If you have success, you will get a brief message that states Process completed, as shown in figure 3.12. That is at least something because the Java compiler says absolutely nothing using the philosophy of no news is good news.

Figure 3.12

The Process completed statement is not produced by the Java compiler. It is strictly a JCreator feature that gives you confidence to proceed. Do keep in mind that compile success does not guarantee execution success. You may be curious about the execution. All these programs produce text output and in previous executions you operated at the textstyle, command prompt. Now you are in a full-fledged GUI windows environment. What will happen to the text window? Well you can relax. You can have a GUI desk top and still have a special text window pop up to take care of your special case. Figure 3.13 shows the same output that you saw in earlier programs, but now the output is shown inside a window. Figure 3.13

Before you move on, load, compile and execute each one of the Chapter III earlier programs that you already executed at the DOS command prompt. That means the first four program examples in this chapter. After loading and executing four programs in JCreator, you will feel comfortable with the use of this editor, compiler and interpreter. Keep in mind that every program will conclude with the statement Press any key to continue..., which is a JCreator statement to close the text window that pops up on top of the JCreator IDE. Output Execution Format Change From now on, program output examples will no longer include command prompt directories, nor JCreator statements. You will only see the actual outputs created by the sample programs.

3.4 The Integer Data Type The previous section introduced the notion of declaring variables. You will see many more program examples with variable declarations. In an attempt to be organized, the additional program examples will be shown in a section on each data type. You did already see some examples with the int data type, but as you will see there is quite a bit more to be said about integers. You also need to know how to perform arithmetic operations with integers. Java has four different integer data types. The smallest integer is byte and the largest integer is long. Program Java0305.java demonstrates the four data types. The output display shows the largest value that can be stored in each data type. The comments next to each data type also indicate the space required in memory for the data type. Look closely at figure 3.14 and observe that the integer value that is assigned to maxLong, the long variable, finishes with an L, which is short for long. What is happening here? The compiler knows the data type of a variable because the data type is shown before the variable identifier. Fine, that is easy, but what is the data type of a non-variable-literal-value like 100, 32767 or any other literal value. You may think that it is easy to tell that 32767 is an integer, but what type of integer?

Without any indication, Java will think that an integer literal constant is int, and the limitation on int is 2147483647, which is much smaller than the maximum value allowed by long. So, if you want to assign a value to a long variable greater than the maximum, default int value, you need to tell the compiler that the value is in fact meant to be long. What could be a more logical choice than the letter L? Why the capital L? In this case, it turns out that you can use lower-case l as well, but it looks a lot like the number one. Consider 9223372036854775807l? Can you tell that the last element in the number is the letter L? Figure 3.14 // Java0305.java // This program demonstrates the four integer data types. // The maximum integer value is assigned to each variable. // The maximum integer literal for long is appended with L. public class Java0305 { public static void main (String args[]) { byte maxByte = 127; // occupies 1 byte short maxShort = 32767; // occupies 2 bytes int maxInt = 2147483647; // occupies 4 bytes long maxLong = 9223372036854775807L; // occupies 8 bytes System.out.println("maxByte: " + maxByte); System.out.println("maxShort: " + maxShort); System.out.println("maxInt: " + maxInt); System.out.println("maxLong: " + maxLong); } } Java0305.java Output maxByte: maxShort: maxInt: maxLong:

127 32767 2147483647 9223372036854775807

Java Integer Data Types Data Type

Bytes Used in Memory



Minimum Value Maximum Value

-128 127 short 2 -32,768 32,767 int 4 -2,147,483,648 2,147,483,647 long 8 -9,223,372,036,854,775,808 9,223,372,036,854,775,807 Integer data types in Java have five arithmetic operations. You may have expected the four basic operations of addition, subtraction, multiplication and division, but Java adds modulus division to the list. Look at program Java0306.java in figure 3.15, which demonstrates each one of the operations. Figure 3.15

// Java0306.java // This program demonstrates the five integer operations. public class Java0306 { public static void main (String args[]) { int a = 0; int b = 25; int c = 10; a = b + c; // Addition System.out.println(b + " + " + c + " = " + a); a = b - c; // Subtraction System.out.println(b + " - " + c + " = " + a); a = b * c; // Multiplication System.out.println(b + " * " + c + " = " + a); a = b / c; // Integer Division System.out.println(b + " / " + c + " = " + a); a = b % c; // Remainder Division System.out.println(b + " % " + c + " = " + a); } } Java0306.java Output 25 25 25 25 25

+ * / %

10 10 10 10 10

= = = = =

35 15 250 2 5

There is little explanation needed for addition, subtraction and multiplication. Your biggest concern is that you need to remember to use an asterisk * for multiplication. Division can be a little confusing. Java recognizes two types of division: integer division and modulus or remainder division. Look at the examples in figure 3.16 and figure 3.17 to understand the difference between the two types of division.

Figure 3.16 Integer Division Examples 12 12 12 12 12 12

/ / / / / /

3 4 5 8 12 15

= = = = = =

4 3 2 1 1 0

Figure 3.17 Modulus (remainder) Division Examples 12 12 12 12 12 12

% % % % % %

3 4 5 8 12 15

= = = = = =

0 0 2 4 0 12

3.5 Memory Overflow Problems You learned earlier that data type selection is important because it saves computer memory. You just saw that Java has four different integer types that range from one-byte to 8-bytes in memory allocation. Perhaps you understand that it is wise to use the smallest possible data type to conserve memory space. Saving memory space is an important goal, but it cannot be at the expense of program accuracy. It is possible to be so stingy with memory usage that mathematical operations do not have enough space to operate correctly. Such a problem is called memory overflow, which is demonstrated by the next program example in figure 3.18.

Figure 3.18 // Java0307.java // This program demonstrates memory overflow problems. // Saving memory is important, but too little memory can // also cause problems.

public class Java0307 { public static void main (String args[]) { int intNum = 1000; System.out.println("intNum: " + intNum); intNum = intNum * 1000; System.out.println("intNum: " + intNum); intNum = intNum * 1000; System.out.println("intNum: " + intNum); intNum = intNum * 1000; System.out.println("intNum: " + intNum); } } Java0307.java Output intNum: intNum: intNum: intNum:

1000 1000000 1000000000 -727379968

Program Java0307.java initializes intNum to 1000. The first output displays the initial value of intNum and then there are successive displays after intNum is multiplied by 1000. This works fine for two multiplications. After the third multiplication the output is quite bizarre. This program has a memory overflow problem, which can cause very annoying program errors. To understand what is happening, we need to take a little detour to driving a car. The odometer of a car has a maximum number of miles that can be displayed based on the number of displayed digits. Most odometers are 6 or 7 digits. Consider a 6-digit odometer with 99,999 miles. 0






This odometer cannot display a larger number with 5 digits. One more mile and the entire display will change. Each one of the digits will change from 9 to 0, and the 0 on the far left will become 1. 1






You also need to realize that the odometer will max out at 999,999. It is not possible to display 1,000,000. The limit of displayed mileage is based on the limit of the number of displayed digits. The same exact logic applies to variables in a computer. Different variables are assigned different amounts of memory. In Java a short integer is allocated two bytes of memory. This means a total of 16 bits are used to represent the short integer in memory. Furthermore, remember that every bit can only have two different values: 0 or 1. As a human being you may think in base-10, but the computer is busily storing values, and computing values, in base-2 machine code. The largest possible 6-digit number in base-10 is 999,999 and the absolute largest possible 16-digit number in base-2 is represented by the simulated memory below. 1
















Base 2 number 1111 1111 1111 1111 = 65535 in base 10.

This does not explain why multiplying a positive number times a positive number gives negative results. The largest possible integer, depicted above is not how a short is represented in Java and most other programming languages. Numbers can be positive or negative and the first bit is the sign bit. That leaves 15 bits for representing the number. The 0 in the first bit indicates a positive number. A 1 in the first bit is for a negative number. This means that 0 followed by 15 1s is the largest short integer, which equals 32,767.

How Positive Numbers Give Negative Results 0
















Now logically speaking 32767 + 1 = 32768. If we convert these same values to base 2, we get: 0111 1111 1111 1111 + 1 = 1000 0000 0000 0000 This follows the same logic as 99,999 + 1 = 100,000. We do not see that logic with the 32767, base-10 number, because we have not reached any maximum digit values with base-10. At the base-10 level, 32,767 simply increments to 32,768. At the base-2 level the equivalent values “rollover” and result in the integer value shown below. 1
















Note, however, that the sign-bit, which was positive, has been changed to 1 and now the whole number is negative. This is as far as we want to look at these negative numbers. There is more complexity to the storing and management of negative numbers. If you read other computer science textbooks, you may see something called complement arithmetic. There is a special way to compute negative values in base-2. Right now the biggest point to realize, and remember, is that you will get incorrect values when the variable “overflows.” This means that you need to be very conscious that you pick the correct data type.

Memory Overflow Problems

Memory overflow is a situation where the assigned value of a variable exceeds the allocated storage space. The resulting value that is stored will be inaccurate and can change from positive to negative or negative to positive. Avoid memory overflow problems by using a data type that can handle the size of the assigned values. It is important to save computer memory. However, do not be so stingy with memory that overflow problems occur. 3.6 The Real Number Data Type You saw that Java has four different integer data types. Integers can be declared from as small as 1-byte storage to as large as 8-byte memory allocation. Integers are nice and used for many purposes, but there are also many other computations that require fractions. In science, industry and business, fractions are a way of life. For instance, interest on bank loans and savings accounts are computed as percentages of the principal amount, and percentages involve computation with fractions. You probably remember from science that real numbers can be expressed in scientific notation. A real number like 12345.54321 can also be expressed as 1.234554321+04. Note that in the case of the scientific notation, the decimal point moved to a different location or perhaps you can say that the decimal point floats. A strange term perhaps but scientific notation is also known as floating point notation in computer science and real numbers are called floating point numbers. Why this long explanation? Without it you may not understand why Java uses the keyword float for a real number data type. The next program example also shows a second real number data type, called double. The reserved word double may seem even weirder to you than float. The naming actually is quite logical because a double variable has twice or double the precision of a float variable. Program Java0308.java, in figure 3.19, was designed intentionally to demonstrate that a double variable is more precise than a float variable. You cannot see this difference in accuracy by looking at the program, but the output should convince you that the double data type is superior. However, as you might suspect the superiority comes with the price of occupying extra space in memory. Java's real number constants default to double. Unless you append the constant with F for float, your program will get a compile error. This follows the same logic that you observed with long. The output shows that double is more precise than float. As a rule you want to use double for real number requirements in your programs. Figure 3.19 // Java0308.java // This program demonstrates the four real number operations. // using the float and double data types. Note that float // requires that constant values are appended with F.

public class Java0308 { public static void main (String args[]) { float f1 = 0F; float f2 = 10.0F; float f3 = 3.33333333F; double d1 = 0; double d2 = 10.0; double d3 = 3.33333333; f1 = f2 + f3; System.out.println(f2 + " + " + f3 + " = " + f1); f1 = f2 - f3;

System.out.println(f2 + " - " + f3 + " = " + f1); f1 = f2 * f3; System.out.println(f2 + " * " + f3 + " = " + f1); f1 = f2 / f3; System.out.println(f2 + " / " + f3 + " = " + f1); System.out.println(); d1 = d2 + d3; System.out.println(d2 + " + " + d3 + " = " + d1); d1 = d2 - d3; System.out.println(d2 + " - " + d3 + " = " + d1); d1 = d2 * d3; System.out.println(d2 + " * " + d3 + " = " + d1); d1 = d2 / d3; System.out.println(d2 + " / " + d3 + " = " + d1); System.out.println(); } } Java0308.java Output 10.0 10.0 10.0 10.0 10.0 10.0 10.0 10.0

+ * / + * /

3.3333333 = 13.333333 3.3333333 = 6.666667 3.3333333 = 33.333332 3.3333333 = 3.0 3.33333333 = 13.33333333 3.33333333 = 6.66666667 3.33333333 = 33.3333333 3.33333333 = 3.0000000030000002

3.7 Arithmetic Shortcut Notations

C started a shortcut trend with operators. This trend continued with C++, and Java adopted the popular shortcuts founded by the older C programming language. Shortcuts are popular with programmers and less popular with teachers. It is possible to create confusing code with C shortcuts and this section will show you the available shortcuts and give advice in both good and bad habits. Program Java0309.java demonstrates the Java unary operators, which are operators with a single operand. This could look strange to you because in your previous exposure to mathematical notation you probably only saw binary operators. The program example in figure 3.20 shows that unary operators can be done using postfix or prefix style. It may seem odd to provide two styles to accomplish the same goal, but the reality is that there is a subtle, but very significant difference between the postfix and prefix style. Check out the next program and see if the difference makes sense. You need to look carefully at every output line in the program and compare the output with the corresponding program statement. Failure to understand the difference between prefix and postfix notation can create logic errors. Figure 3.20 // Java0309.java // This program shows "unary" arithmetic shortcut notation in Java. // Note that "postfix" x++ and "prefix" ++x do not always have the same result. public class Java0309 { public static void main (String args[])

{ int num = 10; System.out.println("num equals " + num); num++; System.out.println("num equals " + num); ++num; System.out.println("num equals " + num); System.out.println("num equals " + num++); System.out.println("num equals " + num); System.out.println("num equals " + ++num); System.out.println("num equals " + num); System.out.println(); } } Figure 3.20 Continued Java0309.java Output num num num num num num num

equals equals equals equals equals equals equals

10 11 12 12 13 14 14

Both ++num; and num++; have the same meaning, which is num = num + 1;. The same is true with --num; and num--; which is the same as num = num - 1;. Now look at the output of program Java0309.java. The value of num starts out with 10 and then is incremented by 1 twice with the unary ++ operator. So far so good. Now it gets a little tricky and the operation is placed inside an output statement. Incrementing num by 1 and displaying the value of num are done in the same statement. This provides a dilemma for the computer. Should the computer first display the value of num and then increment the value or should the computer do the process in reverse? The answer is both. Yes both is true. In the case of the postfix operator, num++, the value of num is first displayed and then the value is incremented by 1. --num, on the other hand, first decrements the value of num by 1, and then displays the value. Java Unary Operators k++; is the same as: k = k + 1; ++k; is the same as: k = k + 1; k--; is the same as: k = k - 1; --k; is the same as: k = k - 1; Proper Usage: k++; System.out.println(k); --k; System.out.println(k); Problematic Usage: System.out.println(k++); System.out.println(--k);

Unary operators are lovely, but they are quite limited. Incrementing by one or decrementing by one can be quite boring. Sometimes you want to go for broke and increment by two, three or maybe even ten. Are there shortcuts for such type of operations? There sure are and every binary operations that was shown earlier in this chapter has a shortcut equivalent. Binary operators have shortcuts, and like unary shortcuts, there are potential pitfalls where program statements can be quite ambiguous. Shortcuts are good, but there is such a thing as too much of a shortcut and this can make a program difficult to debug, comprehend and update. This is a warning and a later program will demonstrate how confusing it can be to use too many shortcuts. Right now examine Java0310.java in figure 3.21 and observe the shortcut syntax of binary operations. Figure 3.21 // Java0310.java // This program shows arithmetic assignment operations in Java. // x+=10; is the same as x = x + 10; public class Java0310 { public static void main (String args[]) { int x = 10; System.out.println("x equals " + x); x += 10; System.out.println("x equals " + x); x -= 10; System.out.println("x equals " + x); x *= 10; System.out.println("x equals " + x); x /= 10; System.out.println("x equals " + x); x %= 10; System.out.println("x equals " + x); System.out.println(); } } Java0310.java Output x x x x x x

equals equals equals equals equals equals

10 20 10 100 10 0

Program Java0310.java did not seem so bad. None of the dire shortcut warnings appeared to be visible. Everything executed just nicely as expected, and it was done with less program code, courtesy of the clever shortcuts. So just what is this ambiguous stuff I am talking about? The next program example is a serious nono. Teachers will lobby for Singapore-style caning privileges if you dare program in this style. There are two important points to be made when you look at program Java0311.java, in figure 3.22. First, it is rather amazing that the compiler can digest this glob, and second how on Earth do you know what the output will be? Figure 3.22 // Java0311.java // This program demonstrates very bad programming style by // combining various shortcuts in one statement. It is difficult // to determine what actually is happening.

public class Java0311 { public static void main (String args[]) { int x = 10; System.out.println("Before: " + x); x += ++x + x++; System.out.println("After: " + x); System.out.println(); } } Java0311.java Output Before: 10 After: 32 Do you have a clue why the value of x equals 32 at the conclusion of this monstrosity? No clue. Excellent, because I will make no attempt to explain this program. The point is that it looks confusing, it is confusing and it is an awful way to create a program. Binary Operator Shortcuts No Shortcut Notation

Shortcut Notation


k += 5


k -= 5


k *= 5


k /= 5


k %= 5 Shortcut Warning Do not combine shortcuts in one program statement!!!

3.8 The char & String Data Types The very first Java program you saw in this book used only strings. Strings are extremely common. It is a string of characters that forms a word, and it is a string of words that forms a sentence. Java processes characters and strings with two data types. There is the char data type for processing individual characters, and there is the string data type for processing sets of one or more characters. In previous programs you have observed that a string of characters is contained between double quotes. That is still very true, There is a small difference for a single character, which needs to be contained between two single quotes. Program Java0312.java, in figure 3.23, starts by concentrating on the humble char data type. Three different character variables are declared and initialized. This program also demonstrates that chain assignment is possible. In one program statement the character 'Q' is assigned to all three variables. Figure 3.23 // Java0312.java // This program demonstrates the data types. // It also demonstrates how assignment can be "chained" with // multiple variables in one statement. public class Java0312 { public static void main (String args[]) { char c1 = 'A'; char c2 = 'B'; char c3 = 'C'; System.out.println("The three characters are: " + c1 + c2 + c3); c1 = c2 = c3 = 'Q'; System.out.println("The three characters are: " + c1 + c2 + c3); System.out.println(); } } Java0312.java Output The three characters are: ABC The three characters are: QQQ If excitement is your goal in life then char is not going to provide much. It is pretty much a dull data type. String is a great deal more interesting. Now you might argue that excitement has been seriously lacking from all this variable stuff. Like, where are the spaceships shooting photon torpedoes? Well those photon torpedoes are used a lot in a variety of Startrek episodes and students in AP Computer Science II might wish to create a program that performs that type of sophistication. Right now your excitement revolves around variables. The topic at hand is the String data type and watch with amazement as you see the next program in figure 3.24 combine various string variables together in seamless perfection. It is not the high of skiing in fresh powder, but it is much cheaper. Figure 3.24 // Java0313.java // This program demonstrates the data type. public class Java0313 { public static void main (String args[]) { String firstName = "Kathy" ; String lastName = "Smith"; System.out.println("firstName: System.out.println("lastName:

" + firstName); " + lastName);

System.out.println("Complete Name: " + firstName + " " + lastName); System.out.println(); } } Java0313.java Output First Name: Kathy Last Name: Smith Complete Name: Kathy Smith Did you observe that strings are performing addition here. At least the plus operator is used and it seems that some type of adding is going on. There is a form of addition shown here that is peculiar to strings, and a lovely name exists for this operation, known as concatenation. This is an example of "overloading" the plus operator. The same exact operator performs totally different functions with numbers and with strings.

String Concatenation Concatenation is the appending of a 2nd string to a 1st string. "Hello" + "World" = "HelloWorld" "Hello" + " " + "World" = "Hello World" "100" + "200" = "100200"

The plus operator ( + ) is used both for arithmetic addition and string concatenation. The same operators perform two totally different operations, called overloading. 3.9

The Boolean Data Type

More than a century ago there was a mathematician, George Boole, who developed a new branch of mathematics. His mathematics did not involve arithmetic nor Algebra, but logical statements that are either true or false. This new branch of mathematics was named Boolean Algebra after its founder. Today, in computer science, a data type that has only two values of true and false is a called a Boolean data type, and in Java you use the reserved word, boolean. The program example in figure 3.25 demonstrates the proper syntax to declare a Boolean variable, but it does not explain how to use Boolean variables. The boolean data type is included here to complete the simple data types. You will learn in later chapters how to use this very unique data type.

Figure 3.25 // Java0314.java // This program demonstrates the data type. // The boolean type can only have two values: true or false. public class Java0314 { public static void main (String args[]) { boolean value = true; System.out.println("value: " + value); value = false; System.out.println("value: " + value);

System.out.println(); } } Java0314.java Output value: true value: false

3.10 Declaring Constants We are done with simple data types. In more formal language Java's simple data types are called primitive data type. You have seen them all and they will provide a base for many of your programs in the beginning of this course. But you are not done with this chapter. There are a few related topics that link to simple data types. So far all the data types were used with a variable declaration and variable implies that some initialized value is able to change or vary. Now what if you want to store a value somewhere in memory for a specified data type, but you do not want the value to change? If you write a program that computes a variety of areas and volumes that involve curves, you will need to use PI. Now do you want the value of PI to change? Hardly, PI is a classic example of a constant. Java allows you to create programs with identifiers that store values, almost the same as variables, but with some minor change the variable is now a constant. Program Java0315.java, in figure 3.26, demonstrates this new and useful concept. Figure 3.26 // Java0315.java // This program demonstrates how to create "constant" identifier // values with the keyword. // Removing the comments from the three assignment statements // will result in compile errors. public class Java0315 { public static void main (String args[]) { final int intConst = 100; final double doubleConst = 3.14159; final char charConst = 'Q'; // intconst++; // doubleConst = 1234.4321; // charConst = 'A'; System.out.println("intConst: " + intConst); System.out.println("doubleConst: " + doubleConst); System.out.println("charConst: " + charConst); System.out.println(); } }

Figure 3.26 Continued Java0315.java Output intConst: 100 doubleConst: 3.14159 charConst: Q

You may feel that Java0321.java is no different from many of the programs shown in this chapter. There is some odd-looking final keyword thrown in, but the output is no different than anything you saw with variables. You do have a good observation and the program contains a feature to satisfy your curiosity. Notice how three lines are commented out. Each one of these three lines is meant to change the initial values of the intConst, doubleConst and charConst identifiers. Remove the comments and recompile the program. You will not get very far. The Java compiler is most displeased that you do not understand the seriousness of the situation. Look at the error message shown in figure 3.27. Personally, I think the error message is an oxymoron. It states that cannot assign a value to final variable A. If you cannot change the value than it is not a variable. Java has decided to call this feature a final variable. I am more comfortable with the term constant that is used in other program languages.

Figure 3.27 Java0315.java Output with comments removed C:\Java\Progs03\Java0315.java:17: cannot assign a value to final variable intConst intConst++; ^ C:\Java\Progs03\Java0315.java:18: cannot assign a value to final variable doubleConst doubleConst = 1234.4321; ^ C:\Java\Progs03\Java0315.java:19: cannot assign a value to final variable charConst charConst = 'A'; ^ 3 errors 3.11 Documenting Your Programs

Program documentation is a major big deal. Perhaps to you it is a big deal because some irritating computer science teacher keeps after you to document your programs. There also seems to be an irritating author of this Java book who should have stayed in Europe and harass European kids rather than get on a soap- box in the United States. You will not appreciate the need for documentation in a first year course. Once the programs you write reach a certain size, it is not possible to test, debug or alter such programs without proper documentation. The first form of documentation is to use meaningful identifiers. Many of the previous programs used single-letter variables. That may be nice for short program statements, but your program is not very readable. Take a little extra time and make your identifiers long enough to explain their purpose in life. Program Java0316.java, shown in figure 3.28, is a short payroll program that uses variables with names that help to explain the program's purpose. Figure 3.28 // Java0316.java // This program demonstrates the use of self-commenting identifiers. public class Java0316 { public static void main (String args[]) { double hoursWorked; double hourlyRate; double grossPay; double deductions;

double netPay; hoursWorked = 35; hourlyRate = 8.75; grossPay = hoursWorked * hourlyRate; deductions = grossPay * 0.29; netPay = grossPay - deductions; System.out.println("Hours Worked: " + hoursWorked); System.out.println("Hourly Rate: " + hourlyRate); System.out.println("Gross Pay: " + grossPay); System.out.println("Deductions: " + deductions); System.out.println("Net Pay: " + netPay); System.out.println(); } } Figure 3.28 Continued Java0316.java Output Hours Worked: Hourly Rate: Gross Pay: Deductions: Net Pay:

35.0 8.75 306.25 88.8125 217.4375

Self-documenting identifiers are an excellent start, but there is more. Programs also need to use well-placed comments. At the start of a program you need to use a heading that explains some general information about the program. At this place it makes sense to use the slash-star comments that can span multiple lines. Program Java0317.java, in figure 3.29, demonstrates both types of comments. In particular, note how the comments extend the meaning of the self-documenting identifiers. For instance, the identifier hoursWorked is descriptive, but it is the comment, which explains that it means the number of hours worked per week. Figure 3.41 // Java0317.java // This program is identical to the previous program and it // demonstrates the use of a header comment to explain the program. /**************************************************************** ****/ /** **/ /** Payroll Program **/ /** Written by Leon Schram 09-23-2001 **/ /** **/ /** This program takes the hours worked and hourly rate of **/ /** an employee and computes the gross pay earned. **/ /** Federal deductions are computed as 29% of gross pay. **/ /** Finally the take-home pay or net pay is computed by **/ /** subtraction deductions from gross pay. **/ /** **/ /****************************************************************

****/ public class Java0317 { public static void main (String args[]) { double hoursWorked; // hours worked per week double hourlyRate; // payrate earned per hour double grossPay; // total earnings in a week double deductions; // total federal tax deductions double netPay; // employee takehome pay hoursWorked = 35; hourlyRate = 8.75; grossPay = hoursWorked * hourlyRate; deductions = grossPay * 0.29; netPay = grossPay - deductions; System.out.println("Hours Worked: " + hoursWorked); System.out.println("Hourly Rate: " + hourlyRate); System.out.println("Gross Pay: " + grossPay); System.out.println("Deductions: " + deductions); System.out.println("Net Pay: " + netPay); System.out.println(); } } Figure 3.29 Continued Java0317.java Output Hours Worked: 35.0 Hourly Rate: 8.75 Gross Pay: 306.25 Deductions: 88.8125 Net Pay: 217.4375 3.12 Mathematical Precedence

Java may not use all the exact same symbols for mathematical operations, but the precedence of operations is totally identical. Rules like multiplication/division before addition/subtraction and parentheses before anything else apply in Java. Parentheses are also used in the same manner as they are in mathematics. You do need to be careful that operators are always used. In mathematics, operators are frequently assumed, but not used. This is especially true for the multiplication operator. A small chart in figure 3.30 helps to clarify this point.

Figure 3.30 Be Aware of Hidden Operators in Mathematics Mathematics Java Source Code 5XY


4X + 3Y

4*X + 3*Y

6(A - B)

6*(A - B)

5 7


A + B A - B

(A + B)/(A - B)


(A * B)/(X * Y)

Mathematical precedence usually is not a problem for students. However, leaving out operators or parentheses, which are not required in regular mathematical expressions, is a common problem for beginning computer science students. Program Java0324.java, in figure 3.31 demonstrates a variety of expressions that use mathematical precedence. You will also need to realize that mathematical accuracy is not always the same as computer accuracy. You saw earlier that the double type stores numbers more accurately than the float type. Numerical values are stored in memory and memory is frequently limited on purpose or accidentally. Either way, it is common that some mathematical accuracy may get sacrificed to save memory. Figure 3.31 // Java0318.java // This program demonstrates mathematical precedence in Java operations.

public class Java0318 { public static void main (String args[]) { double a,b,c, result; a = 1000; b = 100; c = 2.5; System.out.println("a = " + a + " b = " + b + " c = " + c); result = a + b * c; System.out.println("a + b * c = " + result); result = (a + b) * c; System.out.println("(a + b) * c = " + result); result = a / b * c; System.out.println("a / b * c = " + result); result = a * b / c; System.out.println("a * b / c = " + result); System.out.println(); } } Java0318.java Output A = 1000.0 A + B * C (A + B) * C A / B * C A * B / C

B = 100.0 C = 2.5 = 1250.0 = 2750.0 = 25.0 = 40000.0

3.13 Type Casting

Java does not get confused if you always make sure that you assign the correct data type to a variable. All the program examples in this chapter, up to this point, have carefully assigned correct data values. Now what happens if you are not very careful? Will the Java compiler get excited or simple ignore the problem. Program Java0319.java, in figure 3.32, is an average program. Three numbers, declared and initialized as integers, need to be averaged. The resulting average needs to be assigned to Mean, which is double. Will this program work correctly or will Java get confused?

Figure 3.32 // Java0319.java // This program demonstrates that the intended computation may not be // performed by Java. The expression on the right side of the assignment // operator is performed without knowledge of the type on the left side.

public class Java0319 { public static void main (String args[]) { int nr1 = 1000; int nr2 = 3000; int nr3 = 6000; double mean; mean = (nr1 + nr2 + nr3) / 3; System.out.println("The mean equals: " + mean); System.out.println(); } } Java0319.java Output The mean equals:


Java is not at all confused. Computers are never confused, because they follow instructions faithfully. The assignment statement on the right side of the equal sign shows three integer variables that need to be added and then divided by the integer 3. In other words, everything on the right side is integer business. It should come as no shocking surprise that Java treats the expression as an integer computation and performs integer division. This is not the desired computation. There is no need to argue that Mean is a double. Java computes the expression on the right side based on the information supplied on the right side. There is a solution to this problem that will communicate to the computer what your intentions are. The solution is called type casting, which is a major topic in the Java programming language. Program Java0320.java, in figure 3.33, is almost identical to the previous program. The only difference is the (double) keyword placed with the statement that computes the mean. The result is that Java now knows that the intended division is real number division.

Figure 3.33 // Java0320.java // This program corrects the logic error of Java0320.java. // Type casting is used to "force" real number division computation.

public class Java0320 { public static void main (String args[]) { int nr1 = 1000; int nr2 = 3000; int nr3 = 6000; double mean; mean = (double) (nr1 + nr2 + nr3) / 3; System.out.println("The mean equals: " + mean); System.out.println(); } } Java0320.java Output The mean equals:


With program Java0321.java, in figure 3.34, you will see the results of various variables type-casted to another data type. The output display is not exactly shocking. The int variable 65 becomes 65.0 when casted to a double type and letter A when casted to a char type. The double variable 70.1 becomes 70 when casted to an int type and F when casted to a char type. The char variable B becomes 66 when casted to an int type and 66.0 when casted to a double type.

Figure 3.34 // Java0321.java // This program demonstrates "type casting" between different data types.

public class Java0321 { public static void main (String args[]) { int intVal = 65; double dblVal = 70.1; char chrVal = 'B'; System.out.println("(double) intVal 65 becomes " + (double) intVal); System.out.println("(char) intVal 65 becomes " + (char) intVal); System.out.println("(int) dblVal 70.1 becomes " + (int) dblVal); System.out.println("(char) dblVal 70.1 becomes " + (char) dblVal); System.out.println("(int) chrVal B becomes " + (int) chrVal); System.out.println("(double) chrVal B becomes " + (double) chrVal); System.out.println(); } }

Java0321.java Output (double) (char) (int) (char) (int) (double)

IntVal IntVal DblVal DblVal CharVal CharVal

65 65 70.1 70.1 B B

becomes becomes becomes becomes becomes becomes

65.0 A 70 F 66 66.0

3.14 Escape Sequences

There are many different ways to generate output in Java. The variety of graphics output displays are especially impressive. Right now in your early text-output stage variety is limited. It is possible to control output to a small degree with escape sequences. An escape sequence is a single slash followed by some character placed between double quotes. Java recognizes the single slash and does not display it, as you would expect. After all, characters between double quotes are literally displayed. That is the whole point of a literal string. The character following the single slash determines the nature of the special output. For instance the sequence \n will generate a carriage-return, line-feed. Program Java0322.java, in figure 3.35 shows five of the more common escape sequences. You will especially find that the \n and \t sequences are particularly useful.

Figure 3.35 // Java0322.java // This program demonstrates escape sequences in Java

public class Java0322 { public static void main (String args[]) { // \n performs a carriage-return and a line-feed System.out.println("\nProgram Java0228.java\n"); // \t performs a horizontal tab System.out.println("\tONE\tTWO\tTHREE\n"); // \r performs only a carriage-return without a line-feed System.out.print("Hello John\r"); System.out.println("How are you doing?\n"); // \\ displays a single backslash System.out.println("Path C:\\Java14\\bin\n");

// \" displays double qoutes System.out.println("Enter the name \"Kathy Smith\" with double quotes\n"); } } Java0322.java Output Program Java0228.java ONE



How are you doing? Path C:\Java14\bin Enter the name "Kathy Smith" with double quotes 3.15 The AP Java Subset

This textbook can be viewed as an introductory computer science textbook, which uses the Java programming language. This is certainly true, but a deliberate effort is made to prepare students for the AP Computer Science dual Examinations. There is an "A" examination for the first course and an "AB" examination for the second course. Please be aware that both AP and Advanced Placement Program are trademarks or registered trademarks of the College Entrance Examination Board, which was not involved with the production of and does not endorse this book. AB is not currently being offered (2015) The College Board works together with Educational Testing Service to create the AP Computer Science Examination. In an effort to create a standardized test for all students, the College Board and ETS have created an AP Java Subset. The subset is very necessary. The number of available topics in Java is absolutely enormous and decisions need to be made which topics are more significant and should be tested. There is also a secondary consideration, some topics are very difficult to test in a manner that is fair to all students. The AP Java Subset created by the Test Development Committee of the College Board does not dictate what should be taught in an AP Computer Science course. The AP Java Subset indicates what will be tested. This textbook, like practically every other textbook on this subject, will include topics that are very worthwhile to know, but will not be explicitly tested. In an effort to clarify to teachers and students you will see special warning boxes in appropriate chapters, which indicate on the current chapter those topics that will be tested and which topics will not be tested. These alert tables will be used for various other reasons as well to help prepare students for the AP Computer Science Examination. The summary table, in figure 3.36, is the first example of such an examination alert. Figure 3.36 AP Computer Science Examination Alert The int, double, boolean and String data types will be tested. The byte, short, long, float and char data types will not be tested.

3.16 Summary

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: int-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, integerdivision and modulus-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. 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. 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 o 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 becomes 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.

Exposure Java 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24.

Name the three main areas where computers are superior to people. What are so called “computer errors” caused by? Finish this sentence: Morse code is based on In computer science, what means “on” and what means “off”? What number system do we use? What number system does the computer use? What does “ASCII” stand for? What does “BIT” stand for? How many BITs are in a Byte? What can one byte store? What did early computer scientists need to do to create a set of computer instructions? Early computers used vacuum tubes. What do today’s computers use? In computers the main board with all the primary computer components is called the Which 3 computer chips are we primarily concerned with? What does “ROM” stand for? What does “RAM” stand for? Which memory is permanent, RAM or ROM? About how many bytes are in a Tera Byte? Exactly how many bytes are in a Kilo Byte? What does “CPU” stand for? Information is stored on a disk as “iron oxide”. What is the commonly used name substance? List the three main things that can cause the information on your disk to be erased. What kind of “ROM” uses laser light to read information? What kind of information allows you to make a precise copy of the original?

Exposure Java 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12.

Exercises 1.1

Exercises 01.2

What is a program? Which computer language uses mnemonic names? What is the relationship between base 2 numbers and base 16 numbers? What are the 2 kinds of translator programs? What is the difference between “high level” languages and “low level” languages? What is the name of the first successful, wide-spread, programming language? Who helped develop compilers and the business language COBOL? What does “BASIC” stand for? Who developed “Pascal”? What does “OOP” stand for? Who combined the popularity of C, with OOP? What was this new language called?

Exercises 01 05-02-03



Exposure Java 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17.

What is bytecode? How do you recognize bytecode files? What type of translator creates bytecode files? What type of translator executes bytecode files? What is a Java Application? What is a Java Applet? What are the three basic tools required for developing Java programs? What is an IDE? Describe the javac.exe program. Describe the java.exe program. Describe the appletviewer.exe program. What is the College Board view on Java input/output issues? Explain the difference between the print and println keywords. Explain Java case sensitivity. List some Java keywords. What is significant about the program file name? Write the minimal Java program, which is a template for all programs.

Exposure Java 01. 02. 03. 04. 05. 06. 07. 08. 09. 10.

Exercises 3.1

How do you declare an integer variable, called num? How do you declare an integer variable, called num and assign value 100 What is an IDE? What are Java integer data types? What are the integer binary operations? Do computers always compute arithmetic correctly? What is memory overflow? What are Java real number data types? What are the real number binary operations? Which real number data type is more accurate?

Exposure Java 01. 02. 03. 04. 05. 06. 07. 08. 09. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20.

Exercises 2.1

Exercises 3.2

What are unary operators? Are the prefix and postfix operators the same? What is the meaning of num++? Is num = num + 10; the same as num + 10 = num; ? Why should unary operators only be used by themselves like num++; ? What are the arithmetic assignment operators? What does the statement num += 100; mean? What is string concatenation? How is string concatenation different from integer addition? What is it called when the same operator + has multiple functions? What is a literal constant? What is a "variable" constant/ How do you make an identifier, like number a constant integer? What are self-documenting identifiers? What comment style is available in Java? Describe mathematical precedence in Java? Are Java expression written the same as mathematical expression? What is type casting? Give an example of a statement that uses type casting. When do you need to use type casting? Exercises 01 05-02-03


English Department Freshmen English Summer Reading and

English Department    Freshmen English Summer Reading and Grammar Exercises All freshmen (College Prep, Honors, and High Honors) will read the novel ...

6MB Sizes 0 Downloads 0 Views

Recommend Documents

Freshmen English Summer Reading and Grammar Exercises 2016
1. The Boys in the Boat is the actual story of “nine Americans and their epic quest for gold at the. 1936 Berlin Olymp

English 10 2018 Summer Reading
at least ONE book and ONE of the research paper articles. You will be required to complete ... “Just One More Game”

Senior Summer Reading Assignment English 11 Summer
For your summer read, choose either ​Beyond the Beautiful Forevers​by Katherine Boo (note that this contains some pr

We will begin the year with a series of canonical works which explore representations of gender, sexuality, and social m

English 10 – Summer Reading Assignment
Your well-developed paragraph must include a claim, a minimum of two examples and analysis ... While you are only requir

Honors English III Summer Reading Assignment
A student's decision to take English III Honors reflects his or her deep commitment to going beyond the literal reading

AP English Literature & Composition Summer Reading Assignment
Advanced Honors & AP English Literature and Composition. Review Form for Major Works (eg Epic Poem, Drama, Novel). Full

Summer Reading Assignment 2014-2015 AP English Language and
Oct 30, 2009 - [email protected] Summer Reading Assignment 2014-2015. AP English Language and Composition. Dialec

AP English Language and Composition Summer Reading Assignment
Required reading: • Everything's an Argument, by Andrea Lunsford, John Ruszkiewicz, and Keith Walters. Bedford/St. Mar

AP English Language and Composition Summer Reading Assignment
On Dumpster Diving. Born in Texas in 1948, Lars Eighner became famous with the publica- tion of his memoir Travels with