Sunday, 3 November 2013

ARRAY

I don't think that i have to say what is Array as all of you have read it many times..I am staright away here with the program..So read it guys...

PROGRAM:-
public class Demo
{
public static void main(String args[])
{
int []mark=new int[3];
mark[0]=1;
mark[1]=2;
mark[2]=3;
System.out.println(mark[1]);
}
}

Output:-
2

Note:- The word new written in blue color in above program is used to create Array in a java program..
Hope you got it...

Tuesday, 29 October 2013

CAN WE EXECUTE A PROGRAM WITHOUT THE MAIN METHOD ???????

ANSWER TO THE ABOVE LINE IS YES...

I will explain you how it is possible later but before that i want to explain you a main concept of java program that is Static Block.

Static Block:-
            Whenever a block is declared with "static" keyword, it is known as static block in the program..

  • Nature:-
  1. The code inside static block get executed before the execution of main method.
  2. Static block cannot be declared inside any method.
  3. Static block is executed only once
Program:-
class Demo
{
static 
{
System.out.println("It is a static block");
}
public static void main(string args[])
{
System.out.println("It is main method");
}
}

Output:-
It is a static block.
It is main method.

Note:-The line written in pink color in the above program is a static block.

Hope you got the answer of the topic that can we execute a java program without the main method???
The answer is very clear..Yes we can execute a java program without main method with the help of Static Block..
I can give you an example in support of this explanation..
Example: A java program without main method.
class Demo
{
static
{
System.out.println("Hello my reader");
System.exit(0);
}
}

Output:-
Hello my reader

Hence it is clear that we can execute a java program without the main method..

PARAMETERIZED CONSTRUCTOR

Parameterized constructor is used to assign different values to different object of given class.

Program:-
class Rectangle
{
double width;
double height;
Rectangle(double w,double h)
{
width=w;
height=h;
}
double area()
{
return width*height;
}
}
public class RectangleDemo
{
public static void main(String args[])
{
Rectangle rec1=new Rectangle(10,20);
Rectangle rec2=new Rectangle(3,6);
double area;
area=rec1.area();
System.out.println("area is"+area);
area=rec2.area();
System.out.println("area is"+area);
}
}

Output:-
area is 200.0
area is 18.0

Saturday, 26 October 2013

INDIA STILL LACKS IN THE RACE OF INTERNET SPEED

It would be tidy to repeat the same line all the time that today internet is something that people can't live without it..But it has again hurted me that we indians are lacking in terms of internet speed in this days also...you would be shocked to hear that INDIA STANDS AT 116th POSITION in the ranking of speed of internet available in the world..South korea is at the top in this ranking with internet speed of 14.2mbps..
And you will be shivering to hear that India is having only 1.2mbps of internet speed..
Oh we are still having a huge margin in internet speed..Do you know whats the reason behind this...The main reason is that India does not have that much bandwith availble to support its large population and the next reason is that it does not have sufficient amount of towers(BTS). Hope india improves its internet speed and we enjoy intenet in a better manner... 

CONSTRUCTOR

A constructor is used to create object through new operator.

Program :-
class Rectangle
{
double width;
double height;
Rectangle()
{
System.out.println("constructing Rectangle");
width=10;
height=20;
}
double area()
{
return width*height;
}
}
class RectangleDemo
{
public static void main(String args[])
{
Rectangle rec=new rectangle();
double area;
area=rec.area();
System.out.println("area is"+area);
}
}

Output :-
constructing Rectangle
area is 200

Note :- In above program line written with blue line is code for creating constructor...i.e
Rectangle()
{
System.out.println("constructing Rectangle");
width=10;
height=20;
}

Friday, 25 October 2013

CLASS FUNDAMENTAL

A class is simply a template.
An object is created to give life to the various attributes of a class..

Note:- In Java a class template takes no memory, Memory is allocated when object is created.

Program :- Calculate Area of Rectangle


class Rectangle
{
double width;
double height;
double area();
{
return width height;
}
}
class RectangleDemo
{
public static void main(String args[])
{
Rectangle rec1=new Rectangle();
double area;
rec1.width=10;
rec1.height=20;
area=rec1.area();
System.out.println("Area"+area);
}
}

OUTPUT:-
Area 200.0

Note :- The line written in yellow line is used for creating object of a class..
             where
              rec1- Reference variable
              new- New operator
              Rectangle()- Constructor

Introduction of JAVA

                                              

                                           JAVA

  • History
  1. 1991- James Gosling- called "OAK".
  2. 1995- Developed by Sun Microsystem= Called it "JAVA".
  • Sun Microsystem Launched Different Versions Of Java Based on Different Purposes
  1. J2SE(Standard Edition)     :- Window based Application
  2. J2EE(Enterprise Edition)   :- Web based application
  3. J2ME(Mobile Application) :- Mobile based application
NOTE:- When a java file is compiled, a class file is created, A class file is a collection of Byte code.Bytes codes are then interpreted by JVM.

                 Two process done in execution of a java program:-
                      1) Compilation
                      2) Interpretation

Important features of JAVA :- Platform independent
                                                        means write once run  anywhere