Java - Basics

 


Compile
C:\Users\User1\IdeaProjects\HelloWorld\src>javac com\learnjava\Main.java

Run
C:\Users\User1\IdeaProjects\HelloWorld\src>java com.learnjava.Main
Hello World!

Types

Primitive Types: 8 Types (byte, short, int, long, float, double, char, boolean)
  • In Java whenever you deal with a large numbers (ex: 123456789), you can use underscore to separate every 3 digits (ex: 123_456_789 'just like separating with commas').
  • By default Java sees the numbers as integers, so if you create large numbers you need to add "L" as a suffix to the number.
  • Same with float if you don't add "F" it will be treated as 'Double' by default.

Reference Types: ex: date, mail message


Arrays:


for multi-dimensional arrays we need to use "Arrays.deepToString()" to see the values


Constant:

Type Casting:

- Implicit Casting (compatibility)
byte > short > int > long > float > double

Number Formatter:


How to run .jar file:

> java -jar HelloWorld.jar