<pre><codeclass="language-java">public class NameOfClass {
public static void main(String[] args) {
// All program code
}
}</code></pre>
<p>It is important that <code>NameOfClass</code> is named meaningfully for the code. It is convention to use CamelCase when using classes. (Capitalize your class names!)</p>
<p>All methods have a method signature, it is unique to it. For main it is the words <code>public static void</code> and the argument <code>String[] args</code>.</p>
<p><code>public</code> means that any other piece of code can reference it.</p>
<p><code>void</code> means that the method returns nothing</p>
<p><code>main</code> is the name of the method. It is important to have <code>main</code> since that tells the Java Interpreter where to start in your program.</p>
<p><code>String[] args</code> is the command line arguments inputted into the program. For this part of the class, we don't need to worry about it.</p>
<p>If you noticed <code>String</code> is a class, it is not a primitive type. This is denoted in Java by having it capitalized.</p>
<h2>Arithmetic Expressions</h2>
<p>There is an order of operations in programming as well. It goes like this:</p>
<ol>
<li>Parenthesis</li>
<li>Unary Operations</li>
<li>*, /, %</li>
<li>+, -</li>
</ol>
<p>And from there you read from left to right.</p>
<h2>Constant Variables</h2>
<p>These are variables that can never be changed</p>
<pre><codeclass="language-java">final int MINUTES_PER_HOUR = 60</code></pre>
<p>The keyword <code>final</code> indicates to the Java compiler that it is a constant variable.</p>
<p>By convention, constants are in all caps with underscores being separated between the words</p>
<h2>Java Math Library</h2>
<p>There are some arithmetic expressions that we want to be able to do and we cannot achieve that simply with the standard operations</p>
<table>
<thead>
<tr>
<th>Method</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>Math.sqrt(x)</td>
<td>square root</td>
</tr>
<tr>
<td>Math.abs(x)</td>
<td>absolute value</td>
</tr>
<tr>
<td>Math.pow(a, b)</td>
<td>exponentiation $a^b$</td>
</tr>
<tr>
<td>Math.max(a, b)</td>
<td>returns the maximum of a or b</td>
</tr>
<tr>
<td>Math.min(a, b)</td>
<td>returns the minimum of a or b</td>
</tr>
<tr>
<td>Math.round(x)</td>
<td>rounds to the nearest integer</td>
</tr>
</tbody>
</table>
<h2>Example: Finding Areas</h2>
<pre><codeclass="language-java">public class MoreVariables
public static void main(String[] args) {
// Decrate a variable
int x;
// Initialize ia variable
x = 5;
// Area of a square
int squareArea = x * x;
System.out.println("Area of a square: " + squareArea);
double newSquare = Math.pow(x, 2);
System.out.println("Area of square: " + newSquare);
// Area of Circle
final double PI = 3.14159;
double radius = 3;
double circleArea = radius * radius * PI;
System.out.println("Area of circle: " + circleArea);