Introduction - Java

Operator

  • Arithmetic
    • Unary => ++n, --n, n++, n--
    • Binary => +, -, *, /, %
  • Relational/Comparison => Returns Boolean value
    • ==, !=, >, <, >=, <=
  • Assignment
    • =, +=, -=, *=, /=
  • Logical => Used to connect multiple expressions or conditions together
    • &&, ||, !
  • Bitwise => Operate on bits and perform bit-by-bit operations
    • & => AND
    • | => OR
    • ~
    • ^ => XOR
    • n >> N
    • n << N

Enum

  • Theory
    • It is a special data type that enables for a variable to be a set of predefined constants
  • Syntax
      public enum Var {
        VALUE1, VALUE2, VALUE3
      }
    

Math Class

  • Math.max(n1, n2) => Returns the maximum among 2 given numbers
  • Math.min(n1, n2) => Returns the minimum among 2 given numbers
  • Math.random() => Returns a random number
  • (int)Math.random()*100 => Returns a random integer number between 1 to 100

Theory

  • Comment written at the top
      /**
        * META Data
        * @author: Manav Goyal
        * @version: 1.0
        * @since: 06-01-2022
        * @return: a string while calling the function called message()
      **/
    
  • Memory
    • Stack
      • Variables is stored here
      • Till compilation time stack memory is used
    • Heap
      • User created Class, Object using new keyword is stored here
      • During run-time heap memory is allocated
      • Pointer based reference
  • Java Language Tokens – Identifiers, Literals, Reserved Words
  • Predicate => Return a predicate, negation of supplied predicate
    • Predicate not(Predicate<? super T> target)
  • Optional.isEmpty()
  • Stream API
  • Incubators
  • Installation
    • Download JDK from Oracle => Install it
    • Open cmd to check if it is installed
      • Java –version
      • Javac –version
    • Install extension "Extension pack for Java" in VS Code
    • Ctrl + shift + P => To create a new Java project
    • Compilation for Create Java Project
      • javac App.java -d ../bin => For creating .class file in bin folder
      • Run java => Using Code Runner
  • Features of Java
    • Compiled & Interpreted
      • Interpreter => Checks 1 line at a time
      • Compilation => Checks whole code together to find error
    • Platform (Hardware) Independent
    • Object-Oriented
  • Java Tools
    • The VM that runs the compiled Java bitecode (.java → .class using the Java compiler). This is platform-dependent (i.e., you cannot copy a JVM for Windows to Linux and expect it to run), but ensures the independence of the Java code itself, Java runs on JVM and JVM runs on OS
      • Working of JVM => fileName.java > Compiler > fileName.class > Interpreted (Java VM) > Program
    • The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language
    • The JDK is a superset of the JRE, and contains everything that is in the JRE, plus tools such as the compilers and debuggers necessary for developing applets and applications
      • First LTS is Java 8 then Java 11
      • Oracle JDK can only be used in development & testing environments with Java 11, unless you buy commercial support
    • Java
    • JDK
      • JRE => JVM
      • Compiler – javac
      • Interpreter – java
      • Archiver - jar
Share: