Posts

Showing posts from January, 2022

Java Cheatsheet

Image
  Basics Basic syntax and functions from the Java programming language. Boilerplate class HelloWorld { public static void main ( String args [ ] ) { System . out . println ( "Hello World" ) ; } } Copy Showing Output It will print something to the output console. System . out . println ( [ text ] ) Copy Taking Input It will take string input from the user import java . util . Scanner ; //import scanner class // create an object of Scanner class Scanner input = new Scanner ( System . in ) ; // take input from the user String varName = input . nextLine ( ) ; Copy Primitive Type Variables The eight primitives defined in Java are int, byte, short, long, float, double, boolean, and char those aren't considered objects and represent raw values. byte the byte is a primitive data type it only takes up 8 bits of memory. age = 18 ; Copy long long is another primitive data type related to integers. long takes up 64 bits of memory. viewsCount = 3_123_456L ;