java lecture 01rggt
DESCRIPTION
nice oneTRANSCRIPT
![Page 1: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/1.jpg)
Introduction to Java Types, Variables, Operators
![Page 2: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/2.jpg)
Goal Learn enough Java to do something
useful Examples: • Simulate a natural/engineering process • Draw pretty graphics
Assignments • Write your own code • Must submit the assignments
![Page 3: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/3.jpg)
The Computer
Central Processing Unit
(CPU)
Input/Output (IO) Devices
Memory
![Page 4: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/4.jpg)
CPU Instructions
z = x + y Read location x Read location y Add Write to location z
![Page 5: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/5.jpg)
Programming Languages
• Easier to understand than CPU instructions
• Needs to be translated for the CPU to understand it
![Page 6: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/6.jpg)
Java
• “Most popular” language • Runs on a “virtual machine” (JVM) • More complex than some (eg. Python) • Simpler than others (eg. C++)
![Page 7: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/7.jpg)
Compiling Java
Source Code (.java)
Byte Code (.class)
javac java
![Page 8: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/8.jpg)
First Program class Hello {
public static void main(String[] arguments) { // Program execution begins here
System.out.println("Hello world."); }
}
![Page 9: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/9.jpg)
Program Structure class CLASSNAME {
public static void main(String[] arguments) { STATEMENTS
} }
![Page 10: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/10.jpg)
Output
System.out.println(some String) outputs tothe console
Example: System.out.println(“output”);
![Page 11: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/11.jpg)
Second Program class Hello2 {
public static void main(String[] arguments) { System.out.println("Hello world."); // Print once System.out.println("Line number 2"); // Again!
} }
![Page 12: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/12.jpg)
Types
Kinds of values that can be stored and manipulated.
boolean: Truth value (true or false). int: Integer (0, 1, -47). double: Real number (3.14, 1.0, -2.1). String: Text (“hello”, “example”).
![Page 13: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/13.jpg)
Variables
Named location that stores a value of one particular type.
Form: TYPE NAME;
Example: String foo;
![Page 14: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/14.jpg)
Assignment
Use = to give variables a value.
Example: String foo; foo = “IAP 6.092”;
![Page 15: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/15.jpg)
Assignment
Can be combined with a variable declaration.
Example: double badPi = 3.14; boolean isJanuary = true;
![Page 16: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/16.jpg)
class Hello3 { public static void main(String[] arguments) {
String foo = "IAP 6.092"; System.out.println(foo); foo = "Something else"; System.out.println(foo);
} }
![Page 17: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/17.jpg)
Operators Symbols that perform simple computations
Assignment: = Addition: + Subtraction: - Multiplication: * Division: /
![Page 18: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/18.jpg)
Order of Operations Follows standard math rules:
1. Parentheses 2. Multiplication and division 3. Addition and subtraction
![Page 19: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/19.jpg)
class DoMath { public static void main(String[] arguments) {
double score = 1.0 + 2.0 * 3.0; System.out.println(score); score = score / 2.0; System.out.println(score);
} }
![Page 20: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/20.jpg)
class DoMath2 { public static void main(String[] arguments) {
double score = 1.0 + 2.0 * 3.0; System.out.println(score); double copy = score; copy = copy / 2.0; System.out.println(copy); System.out.println(score);
} }
![Page 21: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/21.jpg)
String Concatenation (+) String text = "hello" + " world"; text = text + " number " + 5; // text = "hello world number 5"
![Page 22: Java Lecture 01rggt](https://reader034.vdocument.in/reader034/viewer/2022051413/553eb6834a7959f8128b45b8/html5/thumbnails/22.jpg)
Assignment: GravityCalculator
Compute the position of a falling object:
x(t) = 0.5 × at2 + vit + xi