Java- What is the main( ) method in JAVA / Chapter - 7 /Language Fundamental


java main

java main method


You must be thinking that a particular line which always there in every java program is:-                            
public static void main(String [ ] args)

Q.what is this ???
A.The answer is this the main( ) method of java. The starting point from where the JVM starts reading &
     executing the java program.

  1. Whether a class contains main( ) method or not and whether main( ) method declared according to requirements or not these things won't checked by Compiler.

Java- What is the main( ) method in JAVA / Chapter - 7 /Language Fundamental

javabychetan.blogspot.com
You must be thinking that a particular line which always there in every java program is:-                            
public static void main(String [ ] args)

Q.what is this ???
A.The answer is this the main( ) method of java. The starting point from where the JVM starts reading &
     executing java program.
  1. Whether a class contains main( ) method or not and whether main( ) method declared according to requirements or not these things won't checked by Compiler.

Java - varargs Method / Chapter - 6 /Language Fundamental (1.5v)



java varargs





var-arg method    (variable number of argument method )




  1. Until 1.4 we can't declare a method with the variable number of arguments.If there is a change in the number of arguments compulsory we should go for the new method.But this increases the length of the code & readability.

  2. To overcome this problem java makers introduced the var-args method in 1.5 version of JDK(java).According to this, we can declare a method which can take the variable number of arguments, such type of method are called var-arg methods.

  3. we can declare a var-arg method as follows:-

Java - var-arg Method / Chapter - 6 /Language Fundamental (1.5v)

       
 

var-arg method    (variable number of argument method )




  1. Until 1.4 we can't declare a method with the variable number of arguments .If there is a change in the number of arguments  compulsory we should go for the new method.But this increases the length of the code & readability.
  2. To overcome this problem java makers introduced the var-args method in 1.5 version of JDK(java).According to this, we can declare a method which can take the variable number of arguments, such type of method are called var-arg methods.
  3. we can declare a var-arg method as follows:-
Syntax:
                        m1(int...   x)
       where m1 is a method name & int .... x as an arguments type (we can take any type)

Java-Types of Variables / Chapter - 5 /Language Fundamental



Java Types Of Variables


Based on the position of declaration & behavior all variables are divided into three parts.


1.instance variable


2.static variable


3.local variable




 


1.instance variable:-



  • If the value of a variable varied from object to object is called Instance variable.

  • For every object, a separate copy of instance variable will be created.

  • Instance variable should be declared within the class directly, but outside of any method/block/constructor.

Java-Types of Variables / Chapter - 5 /Language Fundamental


javabychetan.blogspot.com

Based on the position of declaration & behavior all variables are divided into three parts.


1.instance variable

2.static variable

                                   3.local variable


1.instance variable:-

  • If the value of a variable varied from object to object are called Instance variable.
  • For every object, a separate copy of instance variable will be created.
  • Instance variable should be declared within the class directly, but outside of any method/block/constructor.
  • Instance variable will be created at the time of object creation & destroyed at the time of object destruction. So the scope of the instance variable is exactly same as the scope of the object.
  • Instance variable will be stored in the HEAP memory as the part of an object.
  • We can't access the instance variable directly from STATIC area, but we can access it by using "object reference".
  •  We can   access the instance variable directly from instance area.  

How to Find Java Array Length


java array length Java Array Length 


We can find the length of an array by using length variable.


1. length  variable:-


length is a final variable applicable only for arrays.


length variable represents the size of an array.


 example:


                                   int [ ] x = new int [6]; 


 System.out.println(x.length);    o/p    is  6 .


                                int [ ] x =new int [10];


System.out.println(x.length);    o/p    is  10 .


System.out.println(x.length());  


Compile-Time Error:cannot find symbol
Symbol: method length()
location: class int [ ]

Java - How to find length of an Array

We can find the length of an array by using length variable.

1. length  variable:-

length is a final variable applicable applicable for arrays.

length variable represent the size of an array.

 example:

                                   int [ ] x = new int [6]; 

 System.out.println(x.length);    o/p    is  6 .

                                int [ ] x =new int [10];

System.out.println(x.length);    o/p    is  10 .

System.out.println(x.length());  

                                            Compile-Time Error:cannot find symbol
                                                 Symbol: method length()
                                                  location: class int [ ]

Array Shortcut Method

array shortcut methodArray Shortcut Method



1.For 1-D Array:-
We can declare, create & initialize an array into a single line.
This is the short cut method what we are discussing here.
let's go...example :
int [ ] x= new  int [3];
x[0]=10;
x[1]=20;
x[2]=30;

Java-Shortcut method for Array Declaration,Creation,Initialization into a single line

1.For 1-D Array:-
We can declare ,create & initialize an array into a single line.
This is the short cut method what we are discussing here.
let's go...

example :
                  int [ ] x= new  int [3];
                        x[0]=10;
                        x[1]=20;
                        x[2]=30;

Java Array Initialization


Array InitializationJava Array Initialization


Once we create an array every element by default initialize by default values.


example 1:

         int [ ] x =new int [ 3];

          System.out.println(x[0]);         o/p is    0            (default initial value)

          System.out.println(x[1]);          o/p is    0            (default initial value)

          System.out.println(x[2]);         o/p is    0            (default initial value)

          System.out.println(x);               o/p is      [ I@3e25a5


surprise What is this number???

Java Array Initialization

Once we create an array every element by default initialize by default values.

example 1:
         int [ ] x =new int [ 3];
          System.out.println(x[0]);         o/p is    0            (default initial value)
          System.out.println(x[1]);          o/p is    0            (default initial value)
          System.out.println(x[2]);         o/p is    0            (default initial value)
          System.out.println(x);               o/p is      [ I@3e25a5

surprise What is this number???

Java - 2-D Array Creation

To create a 2-D array or multidimensional Array we have to specify the base size of the Array.Because we are using new operator for allocating memory to array so Compulsory we should provide size at least base.For Array, creation java follows Array of Array Approach.


example 1:
       

JAVA- 1-D Array Creation

array creationHow to Create an Array:-


Every Array in java is an object.
Hence we can create an array by using new operator or keyword.
example:-


    int [ ] a=new int [3] ;
array

Rules For Creating 1-D Array:-

JAVA- 1-D Array Creation

How to Create an Array:-

Every Array in java is an object.
Hence we can create an array by using new operator or keyword.
example:-

    int [ ] a=new int [3] ;

Java - Array Declaration


Array DeclarationWhat is an Array:-


An array is an index collection of fixed number of homogeneous data elements.

The main advantage of an array is we can represent a huge number of elements by a single variable.

But the main disadvantage of an array is it is fixed in size so that once the array is created then there is no chance of increasing the size of the array based on our requirement.

Hence to use an array, we should know the size in advance.



How to declare an array?

Let's see in how many ways we can declare an array.


1-D Array Declaration:-


int [ ]    x;       (Recommended to use)


int    [ ]x;


int      x[ ];


 Above all three declaration of the 1-D array is valid.If we are using other than this then we will get compile time error.


 


2-D Array Declaration:-


 int [ ][ ]     x;


 int          [ ][ ]x;


 int         x[ ][ ];


 int  [ ]   x [ ];


int [ ]        [ ]x;


int       [ ]x [ ];


Above all declaration of 2-D array is valid.If we are using other than this than we will get compile time error.

Java- Arrays / Chapter - 4 / Language Fundamental


array java

Array:-


An array is an index collection of fixed number of homogeneous data elements.

The main advantage of an array is we can represent a huge number of elements by a single variable.

But the main disadvantage of an array is it is fixed in size so that once the array is created then there is no chance of increasing the size of the array based on our requirement.

Hence to use an array, we should know the size in advance.

Array Declaration;-


How to declare an array?

Let's see in how many ways we can declare an array.


1-D Array Declaration:-


int [ ]    x;       (Recommended to use)


int    [ ]x;


int      x[ ];


 Above all three declaration of the 1-D array is valid.If we are using other than this then we will get compile time error.


 


2-D Array Declaration:-


 int [ ][ ]     x;


 int          [ ][ ]x;


 int         x[ ][ ];


 int  [ ]   x [ ];


int [ ]        [ ]x;


int       [ ]x [ ];


Above all declaration of 2-D array is valid.If we are using other than this than we will get compile time error.

 

3-D Array Declaration:-

Java - Array Declaration

Array:-

An array is an index collection of fixed number of homogeneous data elements.
The main advantage of an array is we can represent a huge number of elements by a single variable.
But the main disadvantage of an array is it is fixed in size so that once the array is created then there is no chance of increasing the size of the array based on our requirement.
Hence to use an array, we should know the size in advance.

Array Declaration;-

How to declare an array ?
Let's see in how many ways we can declare an array.

1-D Array Declaration:-

int [ ]    x;       (Recommended to use)

int    [ ]x;

int      x[ ];

 Above all three declaration of the 1-D array is valid.If we are using other than this then we will get compile time error.


2-D Array Declaration:-

 int [ ][ ]     x;

 int          [ ][ ]x;

 int         x[ ][ ];

 int  [ ]   x [ ];

int [ ]        [ ]x;

int       [ ]x [ ];

Above all declaration of 2-D array is valid.If we are using other than this than we will get compile time error.

 

3-D Array Declaration:-

Java- Data types / Chapter - 3 /Language Fundamental


javabychetan.blogspot.com


Data Types:-



In Java, every variable and every expression have some type.
Each and every data type is clearly defined.

Every assignment should check by the compiler for Type compatibility.

Now because of above reasons, we can conclude that java is strongly typed language.

Now let's see what are the data type available in java.





1. byte
size = 1 byte(8 bits)
MAX_VALUE = 127
MIN_VALUE = -128
Range = -128 to 127





 

Java- Arrays / Chapter - 4 / Language Fundamental

javabychetan.blogspot.com

Array:-

An array is an index collection of fixed number of homogeneous data elements.
The main advantage of an array is we can represent a huge number of elements by a single variable.
But the main disadvantage of an array is it is fixed in size so that once the array is created then there is no chance of increasing the size of the array based on our requirement.
Hence to use an array, we should know the size in advance.

Array Declaration;-

How to declare an array ?
Let's see in how many ways we can declare an array.

1-D Array Declaration:-

int [ ]    x;       (Recommended to use)

int    [ ]x;

int      x[ ];

 Above all three declaration of the 1-D array is valid.If we are using other than this then we will get compile time error.


2-D Array Declaration:-

 int [ ][ ]     x;

 int          [ ][ ]x;

 int         x[ ][ ];

 int  [ ]   x [ ];

int [ ]        [ ]x;

int       [ ]x [ ];

Above all declaration of 2-D array is valid.If we are using other than this than we will get compile time error.

 

3-D Array Declaration:-

Java- Data types / Chapter - 3 /Language Fundamental

javabychetan.blogspot.com

Data Types :-


In Java, every variable and every expression have some type.
Each and every data type is clearly defined. 
Every assignment should check by the compiler for Type compatibility.
Now because of above reasons we can conclude that java is strongly typed language.
Now let's see what are the data type available in java.


1. byte
size = 1 byte(8 bits)
MAX_VALUE =  127
MIN_VALUE =  -128
Range = -128   to   127



2. short

Java-Keywords or Reserved Words /Chapter - 2 /Language Fundamental


javabychetan.blogspot.com



There are total 53 Keyword or Reserve words in java


keyword, java keywords

These Keywords are divided into 8 categories according to their acceptance.

1.Datatypes Related Keywords (8)



 byte 

 short

 int 

 long

 float

double

char

boolean 


2. Flow Control Related Keyword(11)



if

else

switch

case

while

do

default

break

continue

for

break

return

3.Modifiers Related Keyword(11)

Java-Reserved Words or Keywords /Chapter - 2 /Language Fundamental



javabychetan.blogspot.com





There are total 53 Reserve words in java

Keywords

These Keywords are divided into 8 categories according to their acceptance.



1.Datatypes Related Keywords (8)


 byte 
 short
 int 
 long
 float
double
char
boolean 


2. Flow Control Related Keyword(11)

Java- Identifiers /Chapter - 1 /Language Fundamental



Que: What is Identifier in JAVA?
Ans:  Any name in a java program is called identifier. It can be a class name, variable name, method name, label name.

example:-
Q. How many identifiers are in the following program?



 Ans is
(D)
Description:-

Test, String & System are class names means 3.
main()  & println()are methods means 2.
args is a reference variable of String[] means 1
Hence there are total 3+2+1= 6 identifiers..Rules For Defining Java Identifier

Rules For Defining Java Identifier




Rule 1.
a to z
A to Z
0 to 9
$ and _



example:-
total_number           (valid)

total#                      (invalid) 


If we are using other than this we will get compile time error.

Java- Identifiers /Chapter - 1 /Language Fundamental

javabychetan.blogspot.com



 Que: What is Identifier in JAVA?
Ans:  Any name in a java program is called identifier. It can be a class name, variable name,method name,label name.







example:-
Q. How many identifiers are in the following program?



 Ans is
(D)
Description:-

Test,String & System are class name means 3.
main()  & println()are methods means 2.
args is a reference variable of String[] means 1
Hence there are total 3+2+1= 6 identifiers..


Rules For Defining a Java Identifier

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com