Java- For Beginners


 What is Java?

Java is a Purely Object Oriented Programming Language. Developed by Sum Microsystem of USA in 1991.It was originally called oak of James Gaslin.

How Java works?

Java is compiled into the bytecode and then it is interpreted to Machine code.

Java installation:

JDK- Java Development Kit is collection of tools used for developing and running Java program.

JRE- Java Runtime Environment it helps in executing programs developed in Java.

Basic structure of a Java Program:

       package Com.company; => Group of class

       public class Main{

          public static Void main(String  []args) => Entry point into the Application

          {

           System.out.println("Hello World"); => Hello World

           }}                         

Naming Conventions:

  • For class, we use PascalConvention. First and Subsequent character from a word are Capital Letter(Uppercase). 
             Ex- Main, MyScanner, MyEmployee
  • For Function and Variables , we use CamelcaseConvention. Here first character is Lowercase and the subsequent character are in Uppercase.
              Ex- main, myScanner, myMarks

Variable and Data Type:

We have some rules to follow while writing a java program. The set of these rules is called Syntax.

Variables:- A variable is a container that stores a value. This Value can be changed during the execution of the Program.

           int number = 55;

int=Data Type 
number=Variable Name  
55= Value store

 Rules for declaring a Variables name:

We can choose while declaring a Java.

  1. Must not begin with a digit.
  2. Name is case sensitive.
  3. Should not be a Keyword.
  4. Whitespace is not allowed.
  5. Can contain alphabets, $character, _character and digit if the other condition are specified.

Data Type:

Data type in Java fall under the following condition:

  1. Primitive Data Type(Intensic)
  2. Non-Primitive Data Type(Derived)

Primitive Data Type(Intensic):

Java is statically typed=> Variable must be declared before use

There are 8 primitive data type supported by Java
1. Byte
  • Value ranges from -128 to 127
  • Takes 1byte
  • Default value is 0
2. Short
  • Value ranges from -32768 to 32768
  • Takes 2 byte
  • Default value is 0
3. int
  • Value ranges from -2,147,483,648 to 2,147,483,647
  • Takes 4 bytes
  • Default value is 0
4. float
  • Value ranges from (docs)
  • Takes 4 bytes
  • Default value is 0.0f
5. Long
  • Value range from(docs)
  • Takes 2 byte
  • Default value is 0
6. double
  • Value range from(docs)
  • Takes 8 bytes
  • Default value is 0.0d
7. char
  • Value ranges from 0 to 65535
  • Takes 2 bytes
  • Default value is '\u0000'
8. Boolean
  • Value can be true or false
  • Size depends on Java
  • Default value is false
How to choose data types for our variables?

In order to choose the data type we first need to find the type of data we want to store. After that we need to analyze the min & max value we might use.

Literals: A  constant value which can be assigned to the variable is called as a literals. 

101=>    Integral Literal
10.1f=> Float Literal
10.1=>  double Literal
'A'=>    Character Literal
true=> boolean Literal
"Sumit"=> String Literal

Keyword: Words which are reserved and used by the Java compiler. They cannot be used as an Identifier.



No comments:

Post a Comment