// DrJava saved history v2 8 + 4 * 2 / 1.6 'a' 'a' + 0 '!' // 'a' is a character literal (character value) // 8 is an integer literal // 56.32 is a double literal char myVariable; // this is a variable declaration // ; myVariable = 'r'; // this is a variable assignment // = ; myVariable myVariable = 's'; myVariable // = is assignment operator // the value on the right-hand side is assigned to the // variable on the left-hand side myVariable = 'a'; myVariable + 0 double a; a a = 45.32; a (int) 'a' // Typecast: convert a value from one type to its equivalent // value in another type (double) 78 (int) 45.6 // the conversion from double to int truncates the decimal // part of the number (int) true int myInt; int myInt; // Cannot have multiple variables with the same name. double myInt; myInt = 98; (char) myInt (double) myInt int test; char test1; double test2; test = 4; int test char test1 double test2 test = 4 // Write an initializing declaration for an int variable // hello with the value 27. int hello = 27; // Alternatively, we could do the declaration and initialization // separately: // int hello; // hello = 27; // == is the comparison operator 23 == 78 12 + 5.3 23 == 78.0 23 == 23.0 23 == 23.4 23 == 23.4 + 1 !(24 == 45) 24 != 45 // this is simpler to write // Operator precedence: // Unary + - ! // Binary * / + - // Equality == != < <=, etc // Logical and: && // Logical or: || 2 + -6 // Primitive types: int, double, float, char, boolean, // short, byte, long // Non-primitive types are also called class types. // Example: String String = "hello"; String myString = "hello"; myString myString = "hi"; myString.length() myString = "hi again"; myString.length() // length() is a method in the String class. myString = hi again; myString = "hi again"; String name="Have you read the course info sheet?" name.substr(1,2) name.indexOf("ead") name.indexOf("dedsafdsalkfjar") name.indexOf("Ha") ' '+0 name.indexOf("H") name.indexOf("H",2) name.rindexOf("h",2) name.length() import javax.swing.JFrame; JFrame j; j = new JFrame(); // create a new JFrame window j.setVisible(true); // make the window appear on screen JFrame j1 = new JFrame(); // create a new JFrame window j1.setVisible(true); // make the window appear on screen j.setSize(100,200) j.setVisible(true) j.setSize(300,400) j.setVisible(false) j.setVisible(true) j.setLocation(100,100) j.setLocation(50,10)