*** This course is designed to prepare students to take the AP Computer Science A Exam *** *** Excerpts from the course overview was taken from AP CollegeBoard ***
AP Computer Science A Course Overview¶
AP Computer Science A is an introductory college-level computer science course that introduces one of the more popular programming languages to students. Fundamental topics in this course include the design of solutions to problems, the use of data structures to organize large sets of data, the development and implementation of algorithms to process data and discover new information, the analysis of potential solutions, and the ethical and social implications of computing systems. The course emphasizes object-oriented programming and design using the Java programming language.
The following big ideas serve as the foundation of the course, enabling students to create meaningful connections among concepts: Modularity: Modularity in object-oriented programming allows us to use abstraction to break complex programs down into individual classes and methods. Variables: Variables create data abstractions, as they can represent a set of possible values or a group of related values. Control: Doing things in order, making decisions, and doing thesame process multiple times are represented in code by usingcontrol structures. Impact of Computing: Computers and computing haverevolutionized our lives. To use computing safely and responsibly,we need to be aware of privacy, security, and ethical issues.
For this course we will be using various Integrated Development Environment (IDE) software to help you manage your programs, data files, & images. Coding Rooms will be our primary online IDE for this course. For your personal development and collaboration, you may want to use an online IDE that will allow you to collaborate with peers. If you are using a personal laptop, a good desktop IDE to install is VS Code.
Java at a glance¶
Click Here
Every Java program will begin like this:
Syllabus¶
Click Here
Be on time for class. This includes but is not limited to having you log into your Canvas course, course website, and notebook. Students should be seated within the first five minutes of class to avoid being marked tardy or absent Be prepared for class. This includes having your notebook, assignments, pen/pencil, and paper. Have a good attitude about learning. Be prepared to actively participate in class. Accept feedback with a positive attitude. Be respectful of others and their property. Take care of the learning environment. Keep your area neat and clean. Always clean your space before you leave for the day. Put materials away in their proper place. Report any damaged equipment. Do not change any of the settings on the computers. Do not download/ install any programs (including games) to the computer. Do not access inappropriate content on the internet.Expectations¶
Policy on Academic Honesty¶
I encourage students to work with a peer on assignments. It can make learning fun! YOu may help with general problem-solving strategies, ideas, and algorithms, but all solutions should be your own. In practice, this means that, while students can discuss programs and questions, all lines of code should originate from your own mind. This course uses technology in ways no other course does. If you are unsure about the ethical implications of what you are doing, you should ask. Claiming ignorance is not a reasonable excuse.
If you use other sources for help (websites, LLM/ AI, friends, etc.), please cite them in the comments of your code indicating where you got help and whether certain sections of code came from that help. Please make sure you understand any code that you use from another source. I discourage you from copying my assignments into LLM/ AI tool to generate a complete solution. You can use LLM/ AI tools and other sources for idea generation, code debugging, and help with understanding or generating small parts of code to get you started, but you should not have them do the work for you. Be in charge of your own learning, and make sure you learn the goal(s) of the assignment is asking you to practice!
Assignments that are designated as team/ group assignments must have each student’s name within the block header. Other assignments students may collaborate with another student, but each student must submit their own work and the assignment cannot be a facsimile of their peer’s work. Submitted assignments that has another student’s name on it and not your name will be considered as cheating and subject to the district’s policy regarding plagiarism/ cheating.
Electronic Devices¶
Students should be engaged during class! From my experience, most students are using their electronic device(s) for activities not related to the class content. Thus, during instruction, assessment, classwork, discussions or group collaboration electronic devices should be placed in a secure location where it will not be a distraction. Specifically, students should not be accessing smart phones, tablets or any device during class without permission from the teacher. Phones should be set to silent or turned off in class.
CAMS provides Windows Laptops for student use. Personal Laptops are a privilege on our campus and not a right. Parent(s)/guardian(s) will be notified and conferences will be held should a student persist in using laptops for entertainment purposes.
Earphones, headphones, or other listening tools (excluding medically approved listening devices) should not be used during instruction or collaboration time.
Notes/ Notebook¶
Each student will be responsible for taking, organizing, and maintaining Unit notes (Purpose of Note-Taking). Notes should be hand-written. The method of note-taking will be Cornell Notes. Students will be provided with the formatted Cornell Notes document for each subsection of the Unit. Additional pages will be provided as needed. Students are encouraged to keep their notebooks up-to-date and organized.
Academic Support¶
Before school – 7:30 am – 8:30 am - please contact me prior to the date you need assistance as I may be meeting with another student or have a meeting
After school – Tuesday – Thursday: 3:45 pm – 4:15 pm
the DEN Peer Tutoring (Monday - Friday/ before and after school)
Weighted Grading¶
Grades are posted online using Canvas. Grades are weighted and assigned as detailed below. Each item is scaled on a point system.
Grading |
Percentage |
---|---|
Projects (IDP, Final Project) |
50% |
Test/ Quizzes |
30% |
Classwork/ Portfolio |
15% |
Notes (students may use the current unit hand-written notes for tests) |
5% |
Grading Scale¶
All projects, presentations, tests, quizzes, classwork, portfolio & notes will be used to calculate your final grade.
Projects, classwork, portfolio, and notes grading will follow this scale:
4 - Exceeded Expectations - The program is fully functional and the student has added functionality that exceeds the brief. (A)
3 - Met Expectations - All program functionality is evident. (B)
2 - Approaching Expectations - Most of the program is functional but there are still some functionality issues. (C).
1 - Below Expectations - Some of the work was completed but the program is not near functional standards. (D)
0 - Little to no work was Completed (F)
Students who score below 75% on a project, test or quiz (excluding finals) may retake the project, test, or quiz for up to a 75%. Students will have 1 week to review any feedback and/ or answers and schedule a time to retake the project, test, or quiz.
Grade Letter |
Percentage |
---|---|
A |
90% - 100% |
B |
80% - 89% |
C |
70% - 79% |
D |
60% - 69% |
F |
50% - 59% |
M(issing) |
45% |
Classroom Attendance, Conduct, & Participation Grade¶
It is crucial that students consistently attend class. Most classes will consist of activities and projects where students are learning the structure and implementation of a language. Consistent attendance is important to this class and poor attendance will affect their understanding and overall performance in this class. This grade is inclusive of attendance, participation, and behavior within the classroom. The items are additive.
Tardies, Sleeping, Playing Games, doing other classes’ assignments |
---|
0-5 Excellent(E) |
6-10 Satisfactory(S) |
11–15 Needs Improvement(N) |
16+ Unsatisfactory(U) |
Make-up & Late work policy¶
Students are responsible for makeup work when absent. Please refer to the district policy regarding make up work when students are absent.
To make up a quiz or a test, it is the student’s responsibility to contact the teacher with two weeks upon their return to set an agreed upon date & time.
Make-ups or retakes will be done either before or after school
Handouts will be placed in a makeup folder with the student’s name and it is the student’s responsibility to check this folder when they return before consulting the instructor.
Units & Topics¶
Click Here
Units |
Topics |
MCQ |
FRQ |
Project |
---|---|---|---|---|
Orientation & Structure |
||||
Unit 1 |
1.1 Why Programming? Why Java? |
MCQ |
||
Unit 1 |
1.2 Variables and Data Types? |
MCQ |
||
Unit 1 |
1.3 Expressions and Assignment Statements |
MCQ |
||
Unit 1 |
1.4 Compound Assignment Operators |
MCQ |
||
Unit 1 |
1.5 Casting and Ranges of Variables |
MCQ |
||
TBD |
Unit Exam |
MCQ |
Yes |
|
Unit 3 |
3.2 if Statements and Control Flow |
MCQ |
||
Unit 3 |
3.3 if-else Statements |
MCQ |
||
Unit 3 |
3.4 else if Statements |
MCQ |
||
Unit 3 |
3.1 Boolean Expressions |
MCQ |
||
Unit 3 |
3.5 Compound Boolean Expressions |
MCQ |
FRQ |
|
Unit 3 |
3.6 Equivalent Boolean Expressions |
MCQ |
||
Unit 3 |
3.7 Comparing Objects |
MCQ |
FRQ |
|
TBD |
Unit Exam |
MCQ |
FRQ |
Yes |
Unit 2 |
2.1 Objects: Instances of Classes |
MCQ |
||
Unit 2 |
2.2 Creating and Storing Objects (Instantiation) |
MCQ |
||
Unit 2 |
2.3 Calling a Void Method |
MCQ |
||
Unit 2 |
2.4 Calling a Void Method with Parameters |
MCQ |
||
Unit 2 |
2.5 Calling a Non-Void Method |
MCQ |
||
Unit 2 |
2.6 String Objects: Concatenation, Literals, and More |
MCQ |
||
Unit 2 |
2.7 String Methods |
MCQ |
||
Unit 2 |
2.8 Wrapper: Classes Integer and Double |
MCQ |
||
Unit 2 |
2.9 Using the Math Class |
MCQ |
FRQ |
|
TBD |
Unit Exam |
MCQ |
FRQ |
Yes |
Unit 4 |
4.1 while Loops |
MCQ |
||
Unit 4 |
4.2 for Loops |
MCQ |
||
Unit 4 |
4.3 Developing Algorithms Using Strings |
MCQ |
FRQ |
|
Unit 4 |
4.4 Nested Iteration |
MCQ |
FRQ |
|
Unit 4 |
4.5 Informal Code Analysis |
MCQ |
||
TBD |
Unit Exam |
MCQ |
FRQ |
Yes |
Unit 5 |
5.1 Anatomy of a Class |
MCQ |
||
Unit 5 |
5.2 Constructors |
MCQ |
||
Unit 5 |
5.3 Documentation with Comments |
MCQ |
||
Unit 5 |
5.4 Accessor Methods |
MCQ |
||
Unit 5 |
5.5 Mutator Methods |
MCQ |
FRQ |
|
Unit 5 |
5.6 Writing Methods |
MCQ |
||
Unit 5 |
5.7 Static Variables and Methods |
MCQ |
||
Unit 5 |
5.8 Scope and Access |
MCQ |
FCQ |
|
Unit 5 |
5.9 this Keyword |
MCQ |
||
Unit 5 |
5.10 Ethical and Social Implications of Computing Systems |
|||
TBD |
Unit Exam |
MCQ |
FRQ |
Yes |
Unit 9 |
9.1 Creating Superclasses and Subclasses |
|||
Unit 9 |
9.2 Writing Constructors for Subclasses |
MCQ |
||
Unit 9 |
9.3 Overriding Methods |
MCQ |
||
Unit 9 |
9.4 super Keyword |
MCQ |
||
Unit 9 |
9.5 Creating References Using Inheritance Hierarchies |
MCQ |
||
Unit 9 |
9.6 Polymorphism |
MCQ |
FRQ |
|
Unit 9 |
9.7 Object Superclass |
MCQ |
FRQ |
|
TBD |
Unit Exam |
MCQ |
FRQ |
Yes |
Unit 6 |
6.1 Array Creation and Access |
MCQ |
||
Unit 6 |
6.2 Traversing Arrays |
MCQ |
||
Unit 6 |
6.3 Enhanced for Loop for Arrays |
MCQ |
FRQ |
|
Unit 7 |
6.4 Developing Algorithms Using Arrays |
MCQ |
FRQ |
|
TBD |
Unit Exam |
MCQ |
FRQ |
|
———————– Semester 1 Ends ———————– |
||||
Unit 7 |
7.1 Introduction to ArrayList |
MCQ |
||
Unit 7 |
7.2 ArrayList Methods |
MCQ |
||
Unit 7 |
7.3 Traversing ArrayLists |
MCQ |
||
Unit 7 |
7.4 Developing Algorithms Using ArrayLists |
MCQ |
||
Unit 7 |
7.5 Searching |
MCQ |
FRQ |
|
Unit 7 |
7.6 Sorting |
MCQ |
||
Unit 7 |
7.7 Ethical Issues Around Data Collection |
|||
TBD |
Unit Exam |
MCQ |
FRQ |
Yes |
Unit 8 |
8.1 2D Arrays |
MCQ |
||
Unit 8 |
8.2 Traversing 2D Arrays |
MCQ |
FRQ |
|
TBD |
Unit Exam |
MCQ |
FRQ |
Yes |
Unit 10 |
10.1 Recursion |
MCQ |
FRQ |
|
Unit 10 |
10.2 Recursive Searching and Sorting |
MCQ |
||
TBD |
Unit Exam |
MCQ |
FRQ |
|
White Tower Final Project |
Yes |
|||
Practice Exam 2014 |
MCQ |
FRQ |
||
Practice Exam 2015 |
MCQ |
FRQ |
||
Practice Exam 2020 |
MCQ |
FRQ |
Note-taking in learning¶
Click Here
So, you have the powerpoint, video, textbook, website and/ or whatever other resources were provided to you for this particular lesson. Do you need to take notes as well?
Despite the vast amount of information available in electronic formats, taking notes is an important
learning strategy. In addition, the way that you take notes matters, and not all note-taking strategies lead to equal results. By considering your note-taking strategies carefully, you will be able to create a set of notes that will help retain the most important concepts from lectures and tests, and that will assist you in your exam preparation.
Two Purposes for Taking Notes¶
People take notes for two main reasons:
To keep a record of the information that was heard. This is also called the external storage function of note-taking.
To facilitate learning that you are currently studying.
The availability of information on the internet may reduce the importance of the external storage function of note-taking. When the information is available online, it may seem logical to stop taking notes. However, by neglecting to take notes, you lose the benefits of note-taking as a learning tool.
How Note-Taking Supports Learning¶
Taking notes during class supports your learning in several important ways:
Taking notes helps you to focus your attention and avoid distractions.
As you take notes in class, you will be engaging your mind in identifying and organizing the main ideas. Rather than passively listening, you will be doing the work of active learning while in class, making the most of your time.
Creating good notes means that you will have a record for later review. Reviewing a set of condensed and well-organized notes is more efficient than re-reading longer texts and articles.
Everybody takes notes, or at least everybody claims to. But if you take a close look, many who are claiming to take notes on their laptops are actually surfing the Web, and paper notebooks are filled with doodles interrupted by a couple of random words with an asterisk next to them reminding you that “This is important!” In college and university, these approaches will not work. Your instructors expect you to make connections between class lectures and reading assignments; they expect you to create an opinion about the material presented; they expect you to make connections between the material and life beyond school. Your notes are your road maps for these thoughts. Do you take good notes? Actively listening and note-taking are key strategies to ensure your student success.
Effective note-taking is important because it:
supports your listening efforts.
allows you to test your understanding of the material.
helps you remember the material better when you write key ideas down.
gives you a sense of what the instructor thinks is important.
creates your “ultimate study guide.”
There are various forms of taking notes, and which one you choose depends on both your personal style and the instructor’s approach to the material. Each can be used in a notebook, index cards, or in a digital form on your laptop. No specific type is good for all students and all situations, so we recommend that you develop your own style, but you should also be ready to modify it to fit your needs of a specific class or instructor. To be effective, all of these methods require you to listen actively and to think; merely jotting down words the instructor is saying will be of little use to you.
Note-taking methods¶
Method |
Description |
When to Use |
---|---|---|
Lists |
A sequential listing of ideas as they are presented. Lists may be short phrases or complete paragraphs describing ideas in more detail. |
This method is what most students use as a fallback if they haven’t learned other methods. This method typically requires a lot of writing, and you may find that you are not keeping up with the professor. It is not easy for students to prioritize ideas in this method. |
Outlines |
The outline method places most important ideas along the left margin, which are numbered with roman numerals. Supporting ideas to these main concepts are indented and are noted with capital letters. Under each of these ideas, further detail can be added, designated with an Arabic number, a lowercase letter, and so forth. |
A good method to use when material presented by the instructor is well organized. Easy to use when taking notes on your computer. |
Concept Maps |
When designing a concept map, place a central idea in the center of the page and then add lines and new circles in the page for new ideas. Use arrows and lines to connect the various ideas. Great method to show relationships among ideas. |
Also good if the instructor tends to hop from one idea to another and back. |
Cornell Method |
The Cornell method uses a two-column approach. The left column takes up no more than a third of the page and is often referred to as the “cue” or “recall” column. The right column (about two-thirds of the page) is used for taking notes using any of the methods described above or a combination of them. After class or completing the reading, review your notes and write the key ideas and concepts or questions in the left column. You may also include a summary box at the bottom of the page, in which to write a summary of the class or reading in your own words. |
The Cornell method can include any of the methods above and provides a useful format for calling out key concepts, prioritizing ideas, and organizing review work. Most universities recommend using some form of the Cornell method. |
The Cornell Method¶
Example: The Cornell Method of Note-taking
The Cornell method was developed in the 1950s by Professor Walter Pauk at Cornell University. It is recommended by many universities because of its usefulness and flexibility. This method is simple to use for capturing notes, is helpful for defining priorities, and is a very helpful study tool.
The Cornell method follows a very specific format that consists of four boxes: a header, two columns, and a footer.
The header is a small box across the top of the page. In it you write identification information like the course name and the date of the class. Underneath the header are two columns: a narrow one on the left (no more than one-third of the page) and a wide one on the right. The wide column, called the “notes” column, takes up most of the page and is used to capture your notes using any of the methods outlined earlier. The left column, known as the “cue” or “recall” column, is used to jot down main ideas, keywords, questions, clarifications, and other notes. It should be used both during the class and when reviewing your notes after class. Finally, use the box in the footer to write a summary of the class in your own words. This will help you make sense of your notes in the future and is a valuable tool to aid with recall and studying.
“I used to tape my lecture classes so I could fill in my sketchy notes afterwards. Now that I’m using the Cornell system, my notes are complete and organized in much less time. And my regular five-minute reviews make learning almost painless. No more taping and listening twice.” — A student at Southern Methodist University
All note-taking methods end with the same step: reviewing your notes as soon as possible after class. Any review of your notes is helpful (reading them, copying them onto your computer, or even recasting them using another note-taking method). But THINK! Make your review of notes a thoughtful activity, not a mindless process. When you review your notes, think about questions you still have and determine how you will get the answers. (From the next class? Studying with a friend? Looking up material in your text or on the net?) Examine how the material applies to the course; make connections with notes from other class sessions, with material in your text, and with concepts covered in class discussions. Finally, it’s fun to think about how the material in your notes applies to real life. Consider this both at the very strategic level (as in “What does this material mean to me in relation to what I want to do with my life?”) as well as at a very mundane level (as in, “Is there anything cool here I can work into a conversation with my friends?”).
Teacher Handouts¶
Some Teachers hand out or post their notes or their PowerPoint slides. These handouts should never be considered a substitute for taking notes in class. They are a very useful complement and will help you confirm the accuracy of your notes, but they do not involve you in the process of learning as well as your own notes do. After class, review your notes with highlighter in hand and mark keywords and ideas in your notes. This will help you write a summary of the class in your own words.
General Tips on Note-Taking¶
Regardless of what note-taking method you use, there are some note-taking habits you should get into for all circumstances and all courses:
Be prepared: Make sure you have the tools you need to do the job. If you are using a notebook, be sure you have it with you and that you have enough paper. Also be sure to have your pen (as well as a spare) and perhaps a pen with different-coloured ink to use for emphasis. If you are taking notes on your laptop, make sure the battery is charged! Select the application that lends itself best to your style of note-taking. Microsoft Word works very well for outline notes, but you might find taking notes in Excel to work best if you are working within the Cornell method. (It’s easier to align your thoughts in the cue or recall column to your notes in the right column. Just be sure you keep one idea per row!)
Write on only one side of the paper: This will allow you to integrate your reading notes with your class notes.
Label, number, and date all notes at the top of each page: This will help you keep organized.
When using a laptop, position it such that you can see the instructor and white board right over your screen: This will keep the instructor in your field of vision even if you have to glance at your screen or keyboard from time to time. Make sure your focus remains with the instructor and not on your laptop. A word of caution about laptops for note-taking: use them if you are very adept at keyboarding, but remember that not all note-taking methods work well on laptops because they do not easily allow you to draw diagrams and use special notations (scientific and math formulas, for example).
Don’t try to capture everything that is said: Listen for the big ideas and write them down. Make sure you can recognize the instructor’s emphasis cues and write down all ideas and keywords the instructor emphasizes. Listen for clues like “the four causes were…” or “to sum up.…”
Copy anything the instructor writes on the board: It’s likely to be important.
Leave space between ideas: This allows you to add additional notes later (e.g. notes on the answer to a question you or one of your classmates asked).
Use signals and abbreviations: The ones you use are up to you, but be consistent so you will know exactly what you mean by “att.” when you review your notes. You may find it useful to keep a key to your abbreviations in all your notebooks.
Use some method for identifying your own thoughts and questions to keep them separate from what the instructor or textbook author is saying: Some students use different colour ink; others box or underline their own thoughts. Do whatever works for you.
Create a symbol to use when you fall behind or get lost in your note-taking: Jot down the symbol, leave some space, and focus on what the instructor is covering now. Later you can ask a classmate or the professor to help you fill in what you missed, or you can find it in your textbook.
Review your notes as soon after class as possible (the same day is best): This is the secret to making your notes work! Use the recall column to call out the key ideas and organize facts. Fill in any gaps in your notes and clean up or redraw hastily drawn diagrams.
Write a summary of the main ideas of the class in your own words: This process is a great aid to recall. Be sure to include any conclusions from the lecture or discussion.
Use notes when preparing for a test or doing an assignment: Your notes usually have a summary of the most important points and are useful for making sure you incorporate important concepts in your assignments and for focusing on the main concepts when studying for tests and exams.
What If You Miss Class? Clearly the best way to learn class material is to be at the class and to take your own notes. Regular attendance is expected, but life happens. On occasion, you may miss a class. When this happens, here are some strategies you can use to make up for it:
Never ask: “Did I miss anything important?” (Think about what that is saying and you’ll see it’s rather insulting.)
If the notes or powerpoint is posted online… take notes. If the teacher uses PowerPoint slides, request a copy (or download them if posted) and review them carefully, jotting down your own notes and questions. Review your notes with a classmate who did attend.
You may want to borrow class notes from a classmate. If you do, don’t just copy them and insert them in your notebook. They will not be very helpful. When you borrow notes from a classmate, you should photocopy them and then review them carefully and mark your copy with your own notes and questions. Use other provided resources to try and fill in the gaps. Finally, schedule a study session with the person who gave you the notes to review the material and confirm your understanding.
If none of these options are available for you, use the course syllabus to determine what was covered in the class, then write a short paper (two pages or so) on the material using the class readings and reliable online sources. See your teacher during office hours to review your key findings and to answer any questions you still may have.
Group Notes: A Collaborative Approach¶
Groups within a class can take notes together using file-sharing software on the Cloud. The individuals in the group can add to the document in real time as different individuals are adding themselves. This creates a collaborative document that all can use, download, (or adapt). This won’t work for all situations but can be very useful especially in a fast-moving classroom.
Keep Your Notes¶
Class is over, and you have a beautiful set of notes in your notebook or saved in your laptop. You have written the summary of the class in your own words. Now what? Start by organizing your notes. We recommend you use a three-ring binder for each of your subjects. Print your notes if you used a computer. If you used note cards, insert them in plastic photo holders for binders. Group all notes from a class or unit together in a section; this includes class notes, reading notes, and instructor handouts. You might also want to copy the instructor’s syllabus for the unit on the first page of the section.
Next, spend some time linking the information across the various notes. Use the recall column in your notes to link to related information in other notes (e.g. “See class notes date/page”). If you have had a quiz or test on the unit, add it to your binder, too, but be sure to write out the correct answer for any item you missed. Link those corrections to your notes, too. Use this opportunity to write “notes on your notes.” Review your summary to see if it still is valid in light of your notes on the reading and any handouts you may have added to your notes package. You don’t need to become a pack rat with your notes. It is fairly safe to toss them after the end of a course except in the following cases:
If the course you took is a prerequisite for another course, or when the course is part of a standard progression of courses that build upon each other (this is very common in math and science courses), you should keep them as a reference and review for the follow-up course.
If the course may pertain to your future major, keep your notes. You may not realize it now that they may have future value when you study similar topics or even the same topics in more depth.
If you are very interested in the course subject and would like to get into the material through a more advanced course, independent study, or even research, keep your notes as a prep tool for further work.
Key Takeaways:
Good note-taking is a key strategy for academic success.
Choose among effective note-taking styles for what works best for you and modify it to meet the needs of a specific class or instructor.
List notes are generally less effective and not prioritized.
Outlines work well for taking notes on a laptop when the instructor is well organized.
Concept map notes are good for showing the relationships among ideas.
The Cornell method is effective for calling out key concepts and organizing notes for review.
Instructor handouts and PowerPoint presentations help with—but do not replace the need for personal note-taking.
If you miss a class, explore your options for replacing your missing notes.
Keep your notes organized in a way that makes it easy to study for tests and other uses in the future.
Exercise: Note-taking
Name two advantages of the Cornell system over the list method of note-taking.
Describe the benefits of—and potential problems with—taking class notes on a laptop.
List at least three ways to make up for missing notes because you miss a class.
Text Attributions
This chapter was adapted from “Got Notes?” in University Success by N. Mahoney, B. Klassen, and M. D’Eon. Adapted by Mary Shier. CC BY-NC-SA.
The first two paragraphs and text under the “Two Purposes for Taking Notes” heading are from “Take Notes from Lectures – That You’ll Actually Use” in University 101: Study, Strategize and Succeed by Kwantlen Polytechnic University. CC BY-SA.
Video Attributions
“How to Take Great Notes” by watchwellclass. Standard YouTube Licence.
Pauk, W. & Owens, R.J.Q. (2013). How to Study in College. Boston, MA: Wadsworth, Cengage Learning. ↵
AP Computational Thinking Practices: Skills¶
Click Here
Practice 1: Program Design and Algorithm Development |
---|
1.A Determin an appropriate program design to solve a problem or accomplish a task (not assessed) |
1.B Determine code that would be used to complete code segments |
1.C Determine code that would be used to interact with completed program code |
Practice 2: Code Logic |
---|
2.A Apply the meaning of specific operators |
2.B Determine the result or ouput based on statement execution order in a code segment without method calls (other than output) |
2.C Determin the result or output based on the statement execution order in a code segment containing method calls |
2.D Determine the number of times a code segment will execute |
Practice 3: Code Implementation |
---|
3.A Write program code to create objects of a class and call methods |
3.B Write program code to design a new type by creating a class |
3.C Write program code to satisfy method specifications using expressions, conditional statements, and iterative statements |
3.D Write program code to create, traverse, and manipulate elements in 1D or ArrayList objects |
3.E Write program code to create, traverse and manipulate elements in 2D array objects |
Practice 4: Code Testing |
---|
4.A Use test-cases to find errors or validate results |
4.B Identify errors in program code |
4.C Determine if two or more code segments yield equivalent results |
Practice 5: Documentation |
---|
5.A Describe the behavior of a given segment of program code |
5.B Explain why a code segment will not compile or work as intended |
5.C Explain how the result of program code changes, given a change to the initial code |
5.D Describe the initial conditions that must be met for a program segment to work as intended or described |
Units |
Exam Weighting |
---|---|
Unit 1: Primitive Types |
2.5 - 5% |
Unit 2: Using Objects |
5 - 7.5% |
Unit 3: Boolean Expressions and if Statements |
15 -17.5% |
Unit 4: Iteration |
17.5 - 22% |
Unit 5: Writing Classes |
5 - 7.5% |
Unit 6: Array |
10 - 15% |
Unit 7: ArrayList |
2.5 - 7.5% |
Unit 8: 2D Array |
7.5 - 10% |
Unit 9: Inheritance |
5 - 10% |
Unit 10: Recursion |
5 - 7.5% |
AP Computer Science A Vocabulary¶
Click Here
Below is a comprehensive list of vocabulary words every AP Computer Science A student should be familiar with.
Did I miss a word? Please let me know…
Term |
Definition |
---|---|
! |
A logical operator that reverses the state of a boolean value |
&& |
A logical operator that evaluates to true only if both sides are true |
== |
An operator to compare two pieces of primitive data or two addresses |
A logical operator that evaluates to true if either side is true |
|
abstract |
A class that is never meant to be instantiated except through a concrete subclass |
accessor |
A method that returns the value of a private instance variable (aka getter) |
add |
The method for putting a new item in a list |
addresses |
The location in memory at which an object is stored |
Aggregation |
Has - A Object relation |
algorithm |
A step by step process for solving a problem |
AND |
Only true if both inputs are true |
arithmetic operators |
+, -, *, /, % |
array |
A collection of pieces of data stored as indexed items under one name |
ArrayIndexOutOfBoundsException |
An error that happens when you refer to an element number larger than your array |
arrayList |
A template class for keeping track of collections of data with a changing size |
assembler |
The part of the IDE that turns your code into assembly code |
assembly language |
The instruction set used by the CPU (aka machine code) |
assign |
Set a variable to a value |
attribute |
A variable property of an object (aka field) |
autoboxing |
A feature of Java that converts primitive types to their class counterpart |
base 2 algorithm |
A mathematical operation that returns what power of 2 a number is |
base case |
A condition that triggers a recursive process to end |
base class |
A class that another class inherits from (aka superclass) |
behavior |
An ability of an object (aka method) |
Binary Search |
A search technique on ordered data that cuts the list in half on each check |
bit |
A binary digit |
block |
A piece of code that is separated from the code around it |
body |
The code inside of a method |
boolean |
A type of variable or operation that evaluates to true or false |
braces |
Symbols that define the start and end of a block of code |
break |
A statement to jump outside of a loop or conditional branch |
bugs |
Problems that prevent code from working properly |
byte |
Eight bits |
bytecode |
The Java code that is ready to be processed by an interpreter |
capacity |
The amount of space allocated for a List |
case |
Identifies a code choice of a switch statement |
cast |
Forcing an expression of one data type to fit into a variable with a different type |
catch |
A keyword used to collect and handle specific types of exceptions |
change |
Setting a part of the condition to a different value so the code doesn’t loop infinitely |
char |
A data type for holding a single letter, digit or symbol |
class |
Code that defines the attributes and behaviors of an object |
class |
definition All of the method headers and instance variables that make up a class |
class |
declaration The header line of a class |
class |
variable A variable that is shared among all instances of a class (aka static field) |
client |
A class that uses another class |
column |
A vertical organization of items in a 2D array, the second set of brackets |
comments |
A written description of what code does for human readers |
Comparable |
An interface requiring compareTo that allows built-in sort and searches to be used on a class |
comparator |
A class implementing compare that creates a tool for sorting and searching |
compare |
A tool that is used to check the order between two objects passed as parameters |
compareTo |
A method that is used to check the order between an object and a single parameter |
comparisons |
When an expression or constant is checked for a relationship with another |
compatible |
Data types that contain similar enough values that they can be cast to each other |
compiler |
The part of an IDE used to change turn code into software |
compound |
A complex line of code with made of multiple expressions |
compound assignment operator |
+=, -=, *=, /=, %= |
concatenation |
An operation that creates a new string out of other strings by sticking them together |
concrete |
A class that can be instantiated, a non abstract class |
condition |
A statement that can be evaluated to determine if a piece of code will be run |
conditional |
A statement that is dependent on an expression that evaluates to true or false |
console application |
A piece of software that runs without a GUI |
conspicuous |
Variable names that clearly describe the value they represent |
constant |
A variable that cannot change once its initial value is assigned |
constructor |
A piece of code that is run when an object is instantiated/created |
contents |
What is inside of a data set or element |
convention |
An agreed upon way of coding that is not required by the computer |
convert |
Changing values of one type into another |
copy constructor |
A special constructor that takes a parameter of the same type as the class being created |
CPU |
The “brain” of your computer |
data type |
The kind of information that can be held in a variable |
debugger |
The part of an IDE that helps you find errors in your code |
declaration |
The line where a class, method or variable is first created |
decrement |
Decreasing a value by 1 |
default constructor |
A constructor provided by the compiler when no constructor is coded |
DeMorgan’s Laws |
Rules that describe how logical operations relate and transform into each other |
derived class |
A class that inherits from another class (aka subclass) |
digital |
Using whole numbers |
direct manipulation interface |
An interface that allows the user to interact with program constructs manually |
do-while |
A type of loop with the condition at the end that always executes at least once |
document |
To create help files and comments to make notes for future users and editors |
dot notation |
A way of referencing a method or variable that is part of a class |
double |
The most common data type for decimal numbers |
editor |
The part of an IDE used to type code |
element |
A individual item in an array or list |
empty string |
A string variable that has memory allocated but no text (“”) |
encapsulation |
The practice of using setters and getters to control access to private variables |
equals |
A method that compares objects to see if they are the same |
equation |
A mathematical statement that two expressions have the same value |
evaluate |
Determine the current value of an expression |
exception |
An problem that occurs while a program is running that causes it to crash |
exception handling |
Code intended to catch runtime errors and handle them to prevent a crash |
executable |
A file ready to be run as a program by an operating system |
expression |
A piece of code that will be evaluated when it is run |
extends |
A keyword that is used to cause a class to inherit from another class |
false |
The opposite of true |
field |
A variable created and stored at the object level (aka instance variable) |
final |
A keyword used for creating a constant |
finally |
A keyword that attempts to run code after an exception has happened |
flowchart |
A graphic showing the paths that execution of a program may follow |
for |
A type of loop with the initialization, condtion and chage built into the header. A fixed number of times loop. |
for-each loop |
A special code block for traversing an array or list |
formatting |
Making numbers appear in as text in a particular way |
gate |
A component that does simple binary calculations |
generic type |
A superclass type shared by multiple subclass types |
getter |
A method that returns the value of a private instance variable (aka accessor) |
GUI |
The graphical user interface for interacting with a user |
hardware |
Physical component of a device |
HAS-A |
A relationship between classes where one class is used by another |
hierarchy |
A system for organizing in which each item is a superclass and/or subclass of another item |
high level language |
A language like Java that is converted to machine code before it is executated |
IDE |
An integrated development environment that contains the tools you need to write a program |
if-else |
The keywords used for conditional branching |
immutable |
A value that cannot be changed once created |
implementation |
The final code used to solve a programming problem |
implements |
A keyword that indicates a class will perform the job of an interface |
implicit |
Something that is assumed to be the case if not stated otherwise |
import |
A keyword that allows you to use code from another package in your code |
increment |
To increase a value by a set amount |
indentation |
Shifting code to the right to indicated that it is inside a block |
index |
The number that represents each letter or element in a String, array or a List |
IndexOutOfBoundsException |
An error that happens when code accesses an element in an array that doesn’t exist |
infinite loop |
A piece of code that repeats itself forever |
information hiding |
The practice of making instance variables private to protect the internals operations of the code |
inheritance |
When a subclass gets code and variables originally created in the parent class |
initialize |
Allocate the memory for an array and set up beginning values |
Insertion Sort |
A sort with O(n^2) speed that finds the correct position of each element swapping as needed |
instance |
An object based on a class that exists when a program is running |
instance variable |
A variable stored at the class level (aka field) |
instantiate |
Creating and setting up and actual instance of a class to link to its variable, uses “new” keyword |
int |
The most common data type for non decimal numbers |
integer division |
The answer for why 7/2 is 3 and not 3.5 |
interface |
A programming construct that provides headers of required methods, but no code or variables |
interpret |
Preparing a Java application to be run for a specific operating system |
invoke |
A word meaning to call a method and run its code |
IS-A |
A subclass/superclass relationship between classes |
iteration |
One of many times executing the same piece of code |
iterative statements |
Sections of code that repeat in a predictable order |
JavaDoc |
A tool that creates documentation for code using comments with special syntax and keywords |
JDK |
The Java Development Kit needed for writing Java code |
key |
A piece of data in an object used to sort on |
length |
The number of items in an array |
length() method |
Used to find the number of characters in a string |
literal strings |
Text that is written in code between quotation marks |
local variable |
A variable created inside a method or other block of code |
logic error |
A coding mistake that causes code to act differently than planned |
logical operators |
Operators that combine or compare boolean expressions (eg. &&, |
loop invariant |
A relationship between variables that is checked to determine whether to loop again |
loops A |
ny piece of code that repeats when it reaches the end |
machine code |
A CPU specific binary language (aka assembly code) |
Mergesort |
A sort with O(n log n) speed that breaks the data set in half calling itself recursively |
method |
Code that defines an ability or behavior of an object |
minimized |
Code that takes the least space possible |
modifier |
A method used to change the value of a private variable (aka setter, mutator) |
modulus (%) |
An operator for finding the remainder from integer division |
motherboard |
Computer component all other parts connect to |
mutator |
A method used to change the value of a private variable (aka setter, modifer) |
nested |
Code that is inside another block of code |
nested loop |
A piece of repeating code inside another piece of repeating code |
new operator |
A keyword used when calling the constructor for an object being instantiated |
newline |
A character that tells the console to move the cursor to the next line |
no-args constructor |
An empty constructor, one that takes no parameters |
NOT |
Reverses value of the input |
null |
A keyword meaning “has no value” |
O notation |
A way of showing the relative theoretical speed of a search or sort algorithm |
object |
An instance of a class that exists when a program is running |
object model |
A planning tool used to design a class before coding it |
object oriented programming |
A programming philosophy in which code is written to represent real world things or ideas |
OR |
True if any input is true |
order of operators |
The rules that determine how the computer chooses which operations are evaluated first |
overloaded |
When a method is written in different ways with two or more possible parameter sets |
package |
A collection of java classes |
parameter |
A variable whose value or reference is passed into a method |
parse |
Move through a string one letter or word at a time |
partitioning |
The process of breaking a set into two or more pieces |
pass by reference |
When a parameter is sent as a memory location |
pass by value |
When a parameter is sent as data |
pattern recognition |
The ability to recognize a form of organization in a data set |
peripheral |
Computer part not inside the chassis |
pivot |
A value in a set used to split the set into two parts on which the data will be sorted |
polymorphism |
The concept that a single named behavior can be performed differently by various subclasses |
primitive type |
One of the built-in non-object data types that is stored by value Ex. Boolean, char, byte, int, short, long, float, and double |
printf |
A special method for Strings that includes formatting characters in the string literal |
private |
A keyword that makes a variable or method accessible from only inside the class |
procedural language |
A language where programs are expected to operate in a predictable order |
pseudocode |
A way of designing a program using written descriptions of what the code will be |
public |
A keyword that makes a variable or method accessible from outside the class |
Quicksort |
A sort with O(n log n) speed that splits the data using a randomly chosen pivot |
RAM |
Computer component that stores currently in-use data |
readability |
A measure of how easily something is understood by others |
recursive |
A piece of code that uses itself to solve the problem |
redundancy |
Allows a something to be understood even if some of it is missing or wrong |
reference |
An address that holds the memory location of the variable’s data |
regular expression |
A predefined set of codes for limiting parse and search type String operations |
relational operators |
Operators that compare two expressions (eg. <>, !=, ==) |
remove |
A method for taking an item out of a list and filling any gap |
reserved word |
Special words used by the Java language that cannot be used for naming |
return |
A statement that causes a method to end and may send back a value to the calling code |
return type |
The kind of data that will be sent back by a method |
row |
A horizontal section of a 2D array, the first set of square brackets |
scope |
The part of code in which a variable exists or is accessible |
search |
Finding a particular item in a list, array or other collection |
Selection Sort |
A sort with O(n^2) speed that checks each element against every other element |
Sequential Search |
A search that checks each element from beginning to end |
set |
A method for changing the value of an item in a list |
setter |
A method that is used to change the value of a private variable (aka modifier) |
short-circuit evaluation |
A chain of relational or conditional expressions that stops evaluating as soon as the result is known |
signature |
The header line of a method that defines its return type, name and parameter list |
size |
The number of items in an ArrayList |
software engineering |
Planning, designing, building and testing computer programs |
sorting |
Putting a collection of data in order |
source code |
The original code created by the programmer |
square brackets |
Used to create arrays and refer to a specific element |
stack T |
he part of the computer that keeps track currently running layers of code |
statement |
A complete and syntactically correct line of code |
static field |
A variable that is shared among all instances of a class (aka class variable) |
static method |
A method that uses no (non-static) instance variables and can be called without an instance of the class |
String |
A built-in class for holding words, sentences, parahraphes, etc. |
style |
The conventions agreed upon by programmers for how to write code to be understood by others |
subclass |
A class that inherits from another class |
subinterface |
An interface that inherits from another interface |
subscript |
A way of writing an index to an array in pseudocode |
substring |
There are 2 ways to use the substring method. The first returns a substring of the original string. The second method returns a new string from a specified index and extends to a defined end or up to |
super |
A keyword that is used to access methods and fields from a base class |
superclass |
A class that another class inherits from (aka base class) |
superinterface |
An interface that another interface inherits from |
switch |
A keyword that chooses what code to run based on a single value |
symbolic |
A name that represents another value |
syntax |
The rules for how code must be entered to compile and work |
syntax error |
A coding mistake that prevents code from compiling |
testing |
Checking the condition on a piece of code |
this |
A keyword that refers to the current instance of the class |
transistor |
A tiny on-off switch |
transmission |
Moving something from one place to another |
traversal |
The process of interacting with each element in an array or list in order |
true |
The opposite of false |
try |
A keyword that begins a block code that could cause an exception |
Two-Dimensional Array |
An array of arrays |
uninitialized string |
A string variable that is named but has nowhere to store its data |
value |
Data represented by a variable or expression |
variable |
A named value in a program that can contain a specific type of data |
visual prototyping and design tools |
Tools that allow an engineer to plan their software through drawings and flow models |
while |
A type of loop that runs as long as its condition is true |
whitespace |
Any space, tab or new line charcter in the code |
wrapper class |
A class designed to add behaviors to a primitive type |
Java Style Guidelines¶
Click Here
Please review the Java Style Guidelines
Block Comment Templates with Examples¶
Main() Block method¶
At the top of the file containing your program’s main() block method, place an `external’ block comment containing the following content.
/*=============================================================================
| Assignment: Program #[n]: [Assignment Title]
| Author: [Your Name ]
| Partner: [Partner's Name ]
|
| Course Name: [Course Name]
| Instructor: John Smith
| Due Date: [Due Date and Time]
|
| Description: [Describe the program's goal, IN DETAIL.]
|
| Language: [ Java version 8]
| Ex. Packages: [List names and sources of all external packages
| required by this program.]
|
| Deficiencies: [If you know of any problems with the code, provide
| details here, otherwise clearly state that you know
| of no unsatisfied requirements and no logic errors.]
*===========================================================================*/
An internal block comment belongs immediately ahead of each method of your program, with two exceptions. First, main() is assumed to be covered by the external block comment. Second, if your class has a group of getters and setters, you may cover the entire group with one block comment.
Method Block¶
/*---------------------------------------------------------------------
| Method [Method Name]
|
| Purpose: [Explain what this method does to support the correct
| operation of its class, and how it does it.]
|
| Pre-condition: [Any non-obvious conditions that must exist
| or be true before we can expect this method to function
| correctly.]
|
| Post-condition: [What we can expect to exist or be true after
| this method has executed under the pre-condition(s).]
|
| Parameters:
| parameter_name -- [Explanation of the purpose of this
| parameter to the method. Write one explanation for each
| formal parameter of this method.]
|
| Returns: [If this method sends back a value via the return
| mechanism, describe the purpose of that value here, otherwise
| state 'None.']
*-------------------------------------------------------------------*/
Each class you write, except the class containing main(), must have a block comment of this form ahead of it.
/*+----------------------------------------------------------------------
||
|| Class [Class Name]
||
|| Author: [Your Name]
||
|| Purpose: [A description of why this class exists. For what
|| reason was it written? Which jobs does it perform?]
||
|| Inherits From: [If this class is a subclass of another, name it.
|| If not, just say "None."]
||
|| Interfaces: [If any predefined interfaces are implemented by
|| this class, name them. If not, ... well, you know.]
||
|+-----------------------------------------------------------------------
||
|| Constants: [Name all public class constants, and provide a very
|| brief (but useful!) description of each.]
||
|+-----------------------------------------------------------------------
||
|| Constructors: [List the names and arguments of all defined
|| constructors.]
||
|| Class Methods: [List the names, arguments, and return types of all
|| public class methods.]
||
|| Inst. Methods: [List the names, arguments, and return types of all
|| public instance methods.]
||
++-----------------------------------------------------------------------*/
Examples of Good and Bad Block Comments
Contrary to popular student opinion, I don’t require all of the commenting as an annoyance to you. It has been estimated that about 70% of programming effort is put into the maintenance of old code, and the rest into the development of new code. It is safe to assume that, should you do some programming in your career, you will be needing to modify someone else’s code to fix an old bug or to extend the code’s functionality. Commenting exists to help those unfortunate programmers who have to look at the code months or years after it was written. When you write comments for your code, keep that in mind and include useful information rather than details that are plainly obvious. The future programmers will know the language; you don’t need to explain what “i ≤ j” means! Instead, explain why it’s important that this condition be checked at this point in the code. Do you understand the difference?
As an example, let’s imagine that you’re going to write a subprogram that searches a list of earthquake intensities to find the most powerful quake. I am not going to show any code for this routine; this is intentional! The internal block comment is meant to give an overview of the construction and operation of the routine. If the reader wants more detail, he or she can move on to read the code, which will have its own comments about the code itself.
A Bad Internal Block Comment
Here’s our first example of a block comment for our earthquake intensity search routine. This is not an actual example from a student program, but it does (I hope!) capture most of the mistakes students make when they wait until the last minute to write a comment:
/*---------------------------------------------------------------------
| Method FIND_BIGGEST_QUAKE
|
| Purpose: Find the biggest earthquake.
|
| Pre-condition: Earthquakes are available.
|
| Post-condition: We found the biggest one.
|
| Parameters:
| quakeList -- the quakes
| size -- size of the list
|
| Returns: The biggest quake
*-------------------------------------------------------------------*/
What’s wrong with this comment? Most everything! Where to start?
The description of the purpose of the function is useless; we could have figured as much from the name of the method alone! What we really need to know is exactly what job this method performs. For instance, it would be really nice to know what “biggest” means in this context. Largest measure on the Richter Scale? Most damage caused?
Pre- and Post-conditions are supposed to tell us what needs to be true before (Pre-) and after (Post-) this method executes. They need to be clear and unambiguous, not wishy-washy. These are wishy-washy.
The structure of the quake_list parameter is not even mentioned.
How is the list size measured? By number of items or by index position of the last item?
Exactly what about the biggest earthquake is being returned? Its position in the list? Its measured size? The entire entry from the list?
Again, the point is that anyone reading this comment will have learned almost nothing about this method. You are forcing the reader to wade through the code to learn anything of substance.
A Good Internal Block Comment
Compare the first attempt to this one:
/*---------------------------------------------------------------------
| Method FIND_BIGGEST_QUAKE
|
| Purpose: Identify the earthquake from the list of earthquake
| intensities (quakeList) that has the largest magnitude.
| It is assumed that the given list of quake intensities is
| an array-based list of unordered Richter Scale
| magnitudes; this function performs a simple sequential
| search through the array to locate the position of the
| largest magnitude (the largest value) in the list.
|
| Pre-condition: quakeList holds 1 or more intensities; the
| intensities are in no particular order; numEntries holds
| the exact number of entries currently in the list.
|
| Post-condition: quakeList and numEntries are unchanged; the
| list position of the entry with the largest magnitude has
| been identified; the position is within the boundaries
| of the array.
|
| Parameters:
| quakeList -- the array of earthquake magnitudes. This
| is an array of real numbers; the first magnitude
| is assumed to be at index 0.
| numEntries -- the quantity of magnitudes in quakeList.
|
| Returns: The index (position) of the largest earthquake
| magnitude in the quakeList array.
*-------------------------------------------------------------------*/
Java Style Guidelines
Here are guidelines for writing Java programs in this course.
Spaces¶
Put spaces on both sides of arithmetic operators.
// Incorrect
a=(b*4+7.5/c);
// Correct
a = (b * 4 + 7.5 / c);
The keywords if, else, for, do, and while are always followed by a space. Put a space between a closing parenthesis and an opening brace. When a closing brace is on the same line as an else, follow it with a space.
// Incorrect
if(a < b){
for(int i = 0; i < 10; i++){
j += i * a;
}
}else{
j = b * 9;
}
// Correct
if (a < b) {
for (int i = 0; i < 10; i++) {
j += i * a;
}
} else {
j = b * 9;
}
Do not put spaces after an opening parenthesis or before a closing parenthesis:
// Incorrect
for ( int i = 0; i < 5; i++ ) {
sum = ( sum + i ) * Math.sqrt( 2 );
}
// Correct
for (int i = 0; i < 5; i++) {
sum = (sum + i) * Math.sqrt(2);
}
Braces and Indenting¶
There are several ways of placing braces in your Java source code. One thing they all have in common: closing braces are always the first non-whitespace character on a line. They are never placed at the end of a line:
// Incorrect
if (a < b) {
result = 22; }
else
result = 99; }
Any of these are correct; the book we are currently using uses the third style:
// Correct
if (a < b) {
result = 22;
} else {
result = 99;
}
// Correct
if (a < b)
{
result = 22;
}
else
{
result = 99;
}
// Correct
if (a < b) {
result = 22;
}
else {
result = 99;
}
Always enclose the body of an if clause, else clause, or loop in braces, even when there is only one statement in the body:
// Incorrect
if (a < b)
result = 22;
else
result = 99;
for (int i = 0; i < 7; i++)
result += i * i;
// Correct
if (a < b) {
result = 22;
} else {
result = 99;
}
for (int i = 0; i < 7; i++) {
result += i * i;
}
You may indent either two or four spaces, and you may use the TAB character instead of spaces. You have to be correct and consistent in your indenting and placement of braces. Note how the if-else-if chain is aligned in the correct example:
//Incorrect
if (a < b) {
if (c >= d) {
result = 2;
} else if (e == f)
{
result = 99;
}
}
//Correct
if (a < b) {
if (c >= d) {
result = 2;
} else if (e == f) {
result = 99;
}
}
Names and Declarations¶
Variable names begin with lower case letters. If you have a multi-word variable name, prefer camelCase to snake_case. If you have a final (constant), use all upper case for its name, and, if it is a multi-word name, use SNAKE_CASE. Names of Java classes begin with a upper case letter:
// Incorrect
class example {
int Counter;
double unitprice;
final double salestaxrate = 0.075;
// ...
}
// Correct
class Example {
int counter;
double unit_price; // acceptable
double unitPrice; // preferred
final double SALES_TAX_RATE = 0.075;
// ..
}
Put only one declaration per line:
// Incorrect
double cut, clarity, caratWeight, color;
// Correct
double cut;
double clarity;
double caratWeight;
double color;
Long Lines¶
Limit line length to 75, no more than 79, characters. Many IDEs will let you display a “line length marker” and set its limit. They might also show the current column number in the status bar at the bottom of the editor window.
Prefer multiple println() calls to one print() or println() with multiple \n:
// difficult to read and edit
System.out.print("Weight: " + weight + "\nVolume: " + volume + "\nSurface Area: " + area + "\n");
// better
System.out.println("Weight: " + weight);
System.out.println("Volume: " + volume);
System.out.println("Surface Area: " + area);
If you break a formula across lines, you can break with the operator at the end of a line or beginning of the next line. Just be consistent.
// Either of these is correct
double first = (weight * volume) / (length + width / 2 *
height * height);
double second = (weight * volume) / (length + width / 2
* height * height);
Loops¶
Avoid break and continue whenever possible; instead, carefully think through the loop condition. Do not use while (true) with break to substitute for thinking through the correct condition! Consider the following code to read into an array until it is full or the user enters zero:
// Very bad style
final int MAX = 4;
int [] ages = new int[MAX];
int value = -1;
int count = 0;
while (true) {
System.out.print("Enter age or 0 to quit: ");
value = input.nextInt();
if (value == 0) {
break;
}
ages[count] = value;
count++;
if (count == MAX) {
break;
}
}
// better
final int MAX = 4;
int [] ages = new int[MAX];
int value = -1;
int count = 0;
while (value != 0) {
System.out.print("Enter age or 0 to quit: ");
value = input.nextInt();
if (value != 0) {
ages[count] = value;
count++;
if (count == MAX) {
break;
}
}
}
// best
final int MAX = 4;
int [] ages = new int[MAX];
int value = -1;
int count = 0;
while (count < MAX && value != 0) {
System.out.print("Enter age or 0 to quit: ");
value = input.nextInt();
if (value != 0) {
ages[count] = value;
count++;
}
}
Methods¶
Do not put a space between the method name and the parameter list.
// Incorrect
static double cube ( double value ) {
return value * value * value;
}
// ...
double result = cube ( 12.0 );
// Correct
static double cube(double value) {
return value * value * value;
}
// ...
double result = cube(12.0);
It is a good idea to put comments before a method that describes the method’s purpose, inputs, and return value (if any):
/*
* Calculate monthly payment on a loan, given:
* principal: amount of the loan
* interestRate: annual percentage rate as a decimal (0.075 for 7.5%)
* years: number of years of the loan
* returns the monthly payment amount of the loan
*/
static double payment(double principal, double interestRate, int years) {
//...
}
Output¶
When lining up output, prefer spaces and specific formatting over tabs:
// OK
System.out.printf("Height (cm):\t\t%.2f\n", height);
System.out.printf("Weight (kg):\t\t%.2f\n", weight);
System.out.printf("Blood alcohol:\t%.3f%%\n", bac);
Height (cm): 160.30
Weight (kg): 50.40
Blood alcohol: 0.032%
// Better
System.out.printf("Height (cm): %6.2f\n", height);
System.out.printf("Weight (kg): %6.2f\n", weight);
System.out.printf("Blood alcohol: %7.3f%%\n", bac);
Height (cm): 160.30
Weight (kg): 50.40
Blood alcohol: 0.032%
Comments¶
The code tells you what the program does. Comments should tell you why or how. (The book will often have “what” comments because the book has to explain what a concept is.)
The exception to this guideline is the comments at the start of your program. These must have your name, the date, and a description of the purpose of the program. The description must be clear enough that someone who has not read the assignment will understand what the program does. These comments are incorrect:
This one is correct: