Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Date;
- import java.awt.*;
- public class App {
- public static void main(String[] args) throws Exception {
- /*
- Two categories of types:
- Primitive for storing simple values (Numbers, Characters and Booleans)
- Non-primitive or reference for storing complex objects (Date and mail messages)
- */
- // Primitive
- //byte byteExample = 4; //don't worry about this too much, you can just use int
- //short myNumber = 55 //use int
- //int age = 55;
- //int superLongNumber = 443_44;
- //long veryLongNumber = 3_123_456_789L; //Don't forget to use, L
- float myFloat = 5.4F; //6 decimal digits F
- double myDouble = 85.588888835D; //15 decimal digits D
- //char letter = 'F';
- //boolean myBool = false;
- System.out.println(myDouble);
- System.out.println(myFloat);
- //Non-primitive/Reference
- //Allocate the memory (this is necessary for non-prim/ref types)
- Date now = new Date(); //this variable "now", also an object, is an INSTANCE of the Date() class.
- //This class is a defined template or blueprint for creating new objects or instance.
- //For example, we can create a class called human.
- //Objects are INSTANCES of a class.
- System.out.println(now); //System/out is a class, therefore we can use the dot operator
- //Primitives and references 2
- int firstNo = 1;
- int secondNo = firstNo;
- firstNo = 5;
- System.out.println(secondNo);
- //this will print out 1, despite assigning firstNo to secondNo. Primitives are independent from each other
- Point point1 = new Point(1, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement