Advertisement
WhiteOfNotTheSea

fdg

Sep 28th, 2022
877
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 KB | None | 0 0
  1. import java.util.Date;
  2.  
  3. import java.awt.*;
  4.  
  5. public class App {
  6.     public static void main(String[] args) throws Exception {
  7.         /*
  8.         Two categories of types:
  9.         Primitive for storing simple values (Numbers, Characters and Booleans)
  10.         Non-primitive or reference for storing complex objects (Date and mail messages)
  11.          */
  12.  
  13.         // Primitive
  14.         //byte byteExample = 4; //don't worry about this too much, you can just use int
  15.         //short myNumber = 55 //use int
  16.         //int age = 55;
  17.         //int superLongNumber = 443_44;
  18.         //long veryLongNumber = 3_123_456_789L; //Don't forget to use, L
  19.  
  20.         float myFloat = 5.4F; //6 decimal digits F
  21.         double myDouble = 85.588888835D; //15 decimal digits D
  22.         //char letter = 'F';
  23.         //boolean myBool = false;
  24.         System.out.println(myDouble);
  25.         System.out.println(myFloat);
  26.  
  27.         //Non-primitive/Reference
  28.  
  29.         //Allocate the memory (this is necessary for non-prim/ref types)
  30.         Date now = new Date(); //this variable "now", also an object, is an INSTANCE of the Date() class.
  31.         //This class is a defined template or blueprint for creating new objects or instance.
  32.         //For example, we can create a class called human.
  33.         //Objects are INSTANCES of a class.
  34.         System.out.println(now); //System/out is a class, therefore we can use the dot operator
  35.  
  36.  
  37.         //Primitives and references 2
  38.         int firstNo = 1;
  39.         int secondNo = firstNo;
  40.         firstNo = 5;
  41.         System.out.println(secondNo);
  42.         //this will print out 1, despite assigning firstNo to secondNo. Primitives are independent from each other
  43.  
  44.         Point point1 = new Point(1, 1);
  45.     }
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement