/** * Basic Java type/operator/function demo. * * @author Sean Barker */ public class Lec2 { /** * Adds two ints together. * * @param num1 The first number. * @param num2 The second number. * @return The sum of the two numbers. */ public static int addTwoNumbers(int num1, int num2) { return num1 + num2; } /** * Prints the sum of two numbers. * * @param num1 The first number. * @param num2 The second number. */ public static void printSum(int num1, int num2) { System.out.println(num1 + num2); } /** * Entry function to the program. */ public static void main(String[] args) { // primitive types (lowercase) // not full objects -- operators, not methods int x = 0; double d = 8.52; boolean b = true; char c = 'x'; // reference types (uppercase) // first-class objects -- methods String str = "Bowdoin College"; int strLen = str.length(); // calling a method // Arithmetic operators // +, -, *, /, % int counter = 0; counter++; // same as counter += 1 counter--; // same as counter -= 1 // Relational operators // < <= > >= == != boolean b1 = true; boolean b2 = false; boolean andTest = b1 && b2; // true if both b1 and b2 are true boolean orTest = b1 || b2; // true if either b1 or b2 is true boolean notTest = !b1; // true if b1 is false String s = "\tfirst line\nsecond line"; // escape sequences String part1 = "Bowdoin"; String part2 = "College"; String name = part1 + " " + part2; // string concatenation String s1 = "abc"; String s2 = "xyz"; boolean stringsEqual = s1.equals(s2); // NOT s1 == s2 // null indicates a reference variable with no assigned object String some_str = null; } }