A Simple Java program?

class Sample
public  static void main (String args[] )

{

  System . out .println (“ java  is better  than  c++);

}

Class  declaration:

The first  line

class  Sample

  • Declaration   a class  which  are  an object  oriented construct.
  • Java  is  true  object   oriented language  and   there fore  every thing  must be placed  in side  class
  • Class  is  a  keyboard  declares  that  a new class  definition  follows. Simple  is  a  java  identifies  that specific the no of  the  class  to be  defined.

Opening  brace :-

Every  class  definition  in  java  beginnings  with  an opening   brace ( ) and  ends  with    a  matching brace(}), appening   in the  last line.

The main line :-
                        The  third  line 
  public  static void  main (String args[])
Defines  a  method name main. This   is similar to  the  main function  in  c  language. Every  java application  program    must  be  include   the  main method. This   is  the starting point  for the  interpreter  to  begin  the   execution  of  the  program.  A  java  application can  have  any  number  of  classes  but  only  one  of  them  must   include  a  main  method, to  initiate  the execution.

This   line  contains  a number  of keywords  public, static, void

Public:-
 The keyboard  public  is  an  axis specifics   that declares  the  main  method  has  un  protected  and  there  fore  making  it  accessible   to all other  classes.

Static:-
Next  appears   the keyboard  static. Which  declares  this  method  as  one  that  belongs  to  the  entire  class, and not 4 part of any  objects  of  the class. The main  must  always  be  declared  as static since  the  interpreter uses  this  method before  any objects  are  created.

Void:-
The  type  modifier  void  states  that  the main method  doesn’t  return  any value.

The output  line :-
The  only  executable  statement  in  the  above program is
System. out. println
This  is  similar  to the  printing  statement in since  java  is a  true object  oriented   package , every method must be  a  part  of  an  object. the  println   method  is  a member  of  the out object, which is  a  data member  of  system  class. This  line prints  the scan.

Java   is  better  than  C ++ 

The  method  print  is  always  appends  a new line  character.
This  means  any  sub request  output  will  start  on  a  new line.


Related

Explain Operator precedence in Java

Operator                                     Description             ...

Explain Some Commonly used String Methods

S2 = S1 . to lowercase: Converts the string S1 to all lower case. S2 = S1 to upper case: Converts the string S1 to all upper S2 = S1. Replace (...

What are the Benefits of Organizing Classes in to Packages

1. The classes contained in the packages of other programs can be easily reused. 2. In packages, classes can be unique compared with classes in other packages. That is, two classes in two differe...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item