Fundamentals of Java | Variables & Data Types | Arithmetic Expressions & Data Conversions | Review | Resources
Java is a high level, object orientated, platform independent programming language. "Write once, run anywhere" (WORA) is one of the benefits of writing a program using Java, which means it can be run on any hardware. This hardware includes all computers, Android phones and tablets, implanted medical devices, and small kitchen appliances.
Directions: After watching and studying the video on the Fundamentals of Programming, complete the Fundamentals of Programming video check in itsLearning. You will only have a few minutes to complete the check as it is expected that you have reviewed the material before beginning the check.
Directions: After watching and studying the video on the Working with Java, complete the Working with Java video check in itsLearning. You will only have a few minutes to complete the check as it is expected that you have reviewed the material before beginning the check.
Directions: Create your first program, HelloWorld, in BlueJ. Download the step-by-step HelloWorld document to assist you with writing your program. Note, that there is also a how-to video on the lesson in itsLearning. Please submit your terminal window screenshot and a .java file for grading with all of your labs.
Directions: Write a Java program that prints the message: "Roses are red". Your program will be a class definition containing a main method. See the HelloWorld example if you need guidance. Download Poem document for the instructions.
Directions: When you make syntax errors in your program the compiler gives error messages and does not create the bytecode file (Java bytecode is the instruction set of the Java virtual machine). It saves time and frustration to learn what some of these messages are and what they mean. Unfortunately, at this stage in the game many of the messages will not be meaningful except to let you know where the first error occurred. Your only choice is to carefully study your program to find the error. Watch this video:
No matter what level of experience - everyone gets bugs! Download the Errors document to practice in BlueJ. Submit your answers to questions 2-6 in the assignment in itsLearning.
Java's name-formatting convention for identifiers is so widely used that if you don't follow it, people will probably complain about it. A Java identifier can be any combination of letters, numbers, underscores, and dollar signs, as long as the identifier doesn't start with a number. Spaces are not allowed, and certain patterns have become so widely used that programmers expect to see them.
It is important to understand the name conventions for different parts of the overall program. Once you have learned the convention, you will be able to easily recognize their meaning when you are looking at Java code (as long as the programmer knew what they were doing.)
Programs: Don't start program names with dollar signs or underscores. Those are usually reserved for system names, not document names. A name should describe the document's purpose, so use names like accountNumber, firstName, etc.
Classes: Class names are nouns that describe the entity they represent. They start with an uppercase letter, and all words after also start with uppercase letters (this style is known as UpperCamelCase). String, Math, and BankAccount are examples of class names.
Variables: There are a few rules to follow when naming variables.
Sometimes variables are referred to as identifiers. Think of a variable or identifier as your name. It is a way to identify yourself. It's the same with variables. If I have two integer variables, I will want to have two different names to tell them apart. Also be aware that Java is case sensitive. It will interpret upper and lower case letters differently. For example, Angelina does not equal angelina.
Style is important to your future as a programmer. Starting an identifier with an underscore is a valid identifier name but it is consider bad style, meaning that the programming community frowns upon underscore as a first letter use. Another example is camelCase; camelCase is style and not validity. It is a preferred naming convention that is expected in the programming community but Java does not care either way so it will not throw an error if you don't follow style.
Methods: Method names are verbs that describe the action they provide. They should follow the same formatting rules as variable names, but method names always have parentheses after them. Some examples are setColor() and getText().
Constants: Constant names are for values that can't change such as the value of PI. These are nouns and they're all uppercase. Separate words with underscore since we can't use camel case. Java constant names look like this: PI, MAX_VALUE, and MIN_VALUE.
The last thing to know about identifiers, is that you cannot use any of the Java keywords (also known as reserve words) as variable names. Some of the keywords that we have studied so far are:
There are many more. For a complete listing of Java keywords visit http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html.
Directions: An identifier is a letter followed by zero or more letters and digits. A Java Letter includes the 26 letters of the English alphabet in both uppercase and lowercase, the $ and the _ (underscore) characters, as well as alphabetic characters from other languages. A Java Digit includes the numbers 0 through 9. Identifiers cannot begin with a digit.
Study each of the identifiers listed in the itsLearning worksheet and indicate whether each is valid or invalid. For each invalid identifier, be prepared to tell why it is invalid.
In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. Comments are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters.
You should always include comments in your code:
The goal of a software comment is readability. Make sure:
We have seen multi-line comments at the top of BlueJ. But there are also single line comments and end of line comments.
// This is a single line comment.
The comment above would sit on a line by itself above the line of code it refers too. However, the same type of comment can follow the line of code like this:
System.out.println("Hello World!"); //Output demonstrating the use of a string literal
Directions: Inline comments should explain the processing or the purpose of a programming code without restating the obvious.
Write an appropriate single line comment for the following programming statement and post it to a new thread. Read your classmates single line comment and offer suggestions to make the comment more effective:
System.out.println("Forsyth Virtual Academy");
Directions: On paper, write an application that prints, on separate lines (using multiple println methods):
Use comments to label each piece of information in the output. Now, input your application into BlueJ and correct any errors so that your code compiles. Submit to itsLearning a picture of your handwritten code, the .java file, and a screenshot from the BlueJ terminal window demonstrating that the program worked as intended.
Java has eight primitive data types. They have not changed much over time--there are six numeric primitives, one character primitive, and one logical primitive as shown in the picture on the right. These are the only types actually built into the programming language.
Directions: After watching and studying the video on the Introduction to Primitive Data, complete the Introduction to Primitive Data Video check in itsLearning. You will only have a few minutes to complete the check as it is expected that you have reviewed the material before beginning the check.
Directions: Review the different data types by completing the Data Types Review in itsLearning.
A variable is a simple data structure that allows the programmer to store a value in the computer. The programmer can retrieve or modify the variable at any time in the program.
Directions: After watching and studying the video on the Variables, complete the Variables Video check in itsLearning. You will only have a few minutes to complete the check as it is expected that you have reviewed the material before beginning the check.
Directions: Explain what an Escape Sequence is and why it is necessary. Give an example of a line of code using an escape sequence but do not repeat the same line as another classmate.
Directions: The goal in this exercise is to develop a program that will print out a list of student names together with other information for each. The tab character (an escape sequence) is helpful in getting the list to line up nicely. A program with only two names is in the file Names.java. Download the Names and Places directions and upload the .java file along with a screenshot of your code from the BlueJ terminal window.
Directions: Write a Java program that prints a table with a list of at least 5 students together with their grades earned (lab points, bonus points, and the total) in the format shown in the Student Grades assignment sheet. Upload the .java file and a screenshot of your programming running from the BlueJ terminal window. Don't forget to update the comment at the top of the page with your name and the date.
Java does its calculations in program code called expressions. An expression is a combination of one or more operands and their operators and follow the order of operations similar to other forms of math. Expressions use operators to indicate what calculations to do and operands to provide information for the calculation.
Directions: After watching and studying the video on the Arithmetic Expressions & Data Conversions, complete the Arithmetic Expressions & Data Conversions Video check in itsLearning. You will only have a few minutes to complete the check as it is expected that you have reviewed the material before beginning the check.
Directions: What is the numeric value of each of the following expression as evaluated by Java? This is not a graded assignment. It is a practice worksheet on expressions. Remember that Java's order of operations is similar to the order of operations in your Mathematics class but slight different as Java uses levels of operator precedence known as associativity. Here is a chart of Operator Precedence in Java.
Java is a strongly typed language, which means the type of a name is very important to how we use it. We can't mix most types, and for some that seem like we should be able to, we can't without telling Java that we really mean to. For example, I can't assign a double value to an integer variable without telling Java that is exactly what I want to do.
Java allows you to convert a value of one data type to another data type in a process called casting. There are two kinds of casting:
Pay close attention to where the cast is located. If the cast is one of the terms of the expression the overall result of the expression will be different that if the cast is on the result of the expression. To learn more about casting visit Javarevisited.
Directions: Complete the Modulus Operator worksheet located in itsLearning. Modulus is a concept that will appear on the AP test and is often used in decision statement when determining even or odd. With modulus, you have to think "long division". Modulus divides the two operands and returns the remainder. Remember that any time the second operand is larger than the first operand in the expression, the modulus operator will return the first operand.
Directions: You will be given declarations and asked to indicate the results of the presented expressions. You should review int division and casting. Make sure you correctly follow the order of operations. Make sure integer answers are indicated by having no decimal, and that floating point answers are indicated by having a decimal. For example, the values 0 and 0.0 are two different values.
Directions: Complete the Expressions & Casting quiz. This quiz will cover the concepts of expressions, order of operation, casting, and modulus.
Directions: Log on to MyAp on the College Board website and complete the Unit 1 Personal Progress Check.
Directions: Free response questions on the AP Exam are handwritten. We will practice writing code by hand in this class as well. To submit this assignment, hand write your code on paper. Your work must be hand written in order to receive credit. Create a Letter class that prints a letter. Put your name and the date in comment lines at the start of your class. See itsLearning for the full assignment and requirements for submitting your assignment for grading.
Directions: Complete the Unit 1 Study Guide worksheet in itsLearning to review for the unit assessment. The results of this worksheet are not a part of your grade.
Fundamentals of Programming presentation
Working with Java presentation
Introduction to Primitive Data types presentation
High-Level Language image: https://corejava25hours.com/category/java/
Platform Independent image: https://corejava25hours.com/category/java/
Software Development: https://en.wikipedia.org/wiki/Software_development
Primitive Data Types - Summary image: https://corejava25hours.com/category/java/
Autoboxing image: https://corejava25hours.com/category/java/
Type Casting image: https://javarevisited.blogspot.com/2012/12/what-is-type-casting-in-java-class-interface-example.html