Simple Java Program-Some important points - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Simple Java Program-Some important points - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Wednesday, March 13, 2019

Simple Java Program-Some important points

Simple Java Program-Some important points


üpublic: Access specifier. main() must be made public, since it 
must be called by code defined outside it’s class.

üStatic: It is required because main() is called without creating
 an object of it’s class

üString args[]: An array of objects of type String class. Each
 object of type string contains a character string. It is used to 
manipulate command line argument.

üJava is case sensitive.

üSystem           predefined class that refers to system.

  out           It is static data member of System class

  println()      It is a member of out object

Second Java Program

class add_num
{
  public int add(int a, int b)
  {
  return a+b;
  }
}
public class test
{
  public static void main(String args[])
  {
  int a, b;
  a=100;
  b=23;
  add_num ob = new add_num();
  System.out.println(“The addition: “+ ob.add_num(a,b));
 
  }
}
Points to be Noted

üJava source code can contain multiple classes, the name of the source code must be the name of the only public class of the code.
üUsually public class contains the main() method, that is the starting point of program execution.
üObject of a class is created using new operator.
üMethod of a class is accessed through an object of that class.
ü+ in System.out.println() method concatenate two strings.

Java is a Strongly typed Language

üEvery variable and expression has a strongly defined type.
üAll assignments are checked for type compatibility.
üJava compiler checks all expressions and parameters to ensure that the types are compatible.

No comments:

Post a Comment

Post Top Ad