Core Java Tutorial in Hindi – Programming Tutorials & Technical Guide

0
501
views
top 200 Core Java Interview Questions and Answers 2017-18
top 200 Core Java Interview Questions and Answers 2017-18

Core Java Tutorial for Beginners

Wheather the class contains main or not & wheather the main() is properly declared or not. These checkings are not responsibilities of compiler at rauntime, JVM is responsible for these checking.

 If the JVM unable to find required main(). Then we will get runtime exception saying NoSuchMethod Error: main

class Core_Java_Tutorial

{

}

Compile:  javac   Core_Java_Tutorial.java

Run: java  Core_Java_Tutorial 

NoSuchMethodError: main

JVM always searches for the main() with the following syntax

public static void main(String args[])

Explanation :-

  • public- to call by JVM from anywhere
  • static- without existing object also JVM has to call it’s method
  • void- main method can’t return anything to jvm
  • main- name of the method which is configured inside JVM
  • String[] args – String is a class name & use to pass command line arguments
core java tutorial, Programming language and Technical guide in hindi, Core java Guide
Core java Tutorial
  1. If we are performing to changes in above signature then we will get runtime exception saying ”NoSuchMethodError: main”.
  2. Any where the following changes are acceptable
  3. We can change the order of modifiers. Instead of public static we can take static public
  4. We can declare String[ ] in any valid form

String[ ]  args

String  [ ]args

                String  args[ ]

  1. Instead of args we can take any valid java identifier
  2. Instead of String[ ] we can take Var-Arg String Parameter is String…

main(String[ ] args)          ->       main(String… args)

main() can be declared with the following modifiers also

final

synchronized

strictfp

class Core_Java_Tutorial

{

Final static strictfp synchronized public void main(String…  A)

{

 System.out.println(“Core Java Tutorial  with Hindi Support”);

}

}

Question->  Which of the following main() declarations are valid

Answer – >

public static int main(String[ ] args)      //not valid

Static Public Void Main(String[ ] args)   //not valid

public synchronized strictfp final void main(String[ ] args)  //not valid

public final static void main(String args) //not valid

public strictfp synchronized static void main(String[ ] args)   //valid

Question-> in which of the above classes we will get compile time error

Answer  -> no where, all cases will compile

Inheritance concept in applicable for static methods including main() also. Hence If the child class doesn’t  contain main() then parent class main() will be executed while executing child class.

class  Core_Java_Tutorial

{

public static void main(String[ ]  args)

{

System.out.println(“Core Java Tutorial in Hindi and Programming and Technical tutorials”);

}

}

class c extend  Core_Java_Tutorial

{

}

javac  Core_Java_Tutorial.java

java  Core_Java_Tutorial

Output: Core Java Tutorial in Hindi and Programming and Technical tutorials

java  c

Output: Core Java Tutorial in Hindi and Programming and Technical tutorials

class Core_Java_Tutorial

{

public Static void main(String[ ]  args)

{

System.out.println(“ Core java Tutorial”)

}

}

class c extends  Core_Java_Tutorial

{

public Static void main(String[ ] args)

{

System.out.println(“Core Java Tutorial in Hindi- Programming language and Technical Guide”);

}

}

javac  Core_Java_Tutorial.java

java  Core_Java_Tutorial

Output: Core java Tutorial

java c

Output: Core Java Tutorial in Hindi- Programming language and Technical Guide

It seems to be overriding concept is applicable for static methods, but it’s not overriding but it is methodhidding.

Overloading concept is applicable for main() but JVM always calls String arguments method only. The other method we have to call explicitly.

class Core_Java_Tutorial

{

public static void main(String[ ] args)

{

System.out.println(“Core java Tutorial in Hindi language”);

}

public static void main(int[ ] args)

{

System.out.println(“Core java Tutorial in Hindi – Programming tutorials and Technical Guide”);

}

}

Output: Core java Tutorial in Hindi language

Question– >Instead of main method is it possible to configure any other method as main method?

 Answer– > yes inside JVM we have to configure some changes then it is possible.

Explain about System.out.println

class  Core_java_tutorial

{

static String name=”CoreJavaGuide”;

}

Core_java_tutorial. name.length( )

Explanation:-     Core_java_tutorial- it is class name

                             name- static variable of type staring present in  Core_java_tutorial class

length()- it is method present in String class

class Core_java_tutorial

{

static printStream out;

}

System.out.println( )

Explanation-  System – it is class name present in java.lang package

out-     static variable of type printstream present in system class

println- it is method present in printstream class

you may like to check –Introduction about Core java and Go4Vidhya in Hindi

LEAVE A REPLY

Please enter your comment!
Please enter your name here