Core Java Question List No1

Source: Internet
Author: User

  1. What is the most important feature of Java?

Java is a platform independent language.

  1. What do you mean by platform independence?

Platform independence means that we can write and compile the java code in one platform (e. g windows) and can execute the class in any other supported platform eg (Linux, Solaris, etc ).

  1. What is a JVM?

JVM is a Java Virtual Machine which is a run time environment for the compiled Java class files.

  1. Are JVM's platform independent?
    JVM's are not platform independent. JVM's are platform specific run the implementation by the vendor.

  2. What is the difference between JDK and JVM?

JDK is Java Development Kit which is for development purpose and it has des execution environment also. but JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

  1. What is a pointer and does Java Support pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.

  1. What is the base class of all classes?

Java. lang. object

  1. Does Java support multiple inheritances?

Java doesn' t support multiple inheritances.

  1. Is Java a pure object oriented language?

Java uses primitive data types and hence is not a pure object oriented language.

  1. Are arrays primitive data types?

In Java, Arrays are objects.

  1. What is difference between Path and ClassPath?

Path and Classpath are operating system level environment variables. Path is used define where the system can find the executable(.exe) files and classpath us used to specify the location. class files.

  1. What are local variables?

Local variables are those which are declared within a block of code like methods. local variables shocould be initialized before accessing them. local variables have the most limited scope. such a variable is accessible only from the function or block in which it is declared. the local variable's scope is from the line they are declared on until the closing curly brace of the method or code block within which they are declared.

Every local variable declaration statement is immediately contained by a block. local variable declaration statements may be intermixed freely with other kinds of statements in the block. A local variable declaration can also appear in the header of a for statement. in this case it is executed in the same manner as if it were part of a local variable declaration statement. local variables declaration have one and only one final modifier can be used. local variables are not given default initial values. they must be initialized explicitly before they are used. the scope of a variable determines where it can be used. syntactically, scope of any variable is the code between the curly braces of where it is declared.

Public class HelloApp

{

Public static void main (String [] args)

{

String helloMessage;

HelloMessage = "Hello, World! ";

System. out. println (helloMessage );

}

}

You don't specify static on a declaration for a local variable. If you do, the compiler generates an error message and refuses to compile your program.

  1. What are instance variables?

Instance variables are those which are defined at the class level. Instance variables need not be initialized before using them as they are automatically initialized to their default values.

  1. How to define a constant variable in Java?

The variable shoshould be declared as static and final. So only one copy of the variable exists for all instances of the class and the value can't be changed also.

Static final int PI = 3.14;

  1. Shocould be main () method be compulsorily declared in all java classes?

No not required main () method shocould be defined only if the source class is a java application.

  1. What is the return type of the main () method?

Main () method doesn't return anything hence declared void.

  1. Why is the main () method declared static?

Main () method is called by the JVM even before the instantiation of the class hence it is declared as static.

  1. What is the argument of main () method?

Main () method accepts an array of String object as argument.

  1. Can a main () method be declared final?

Yes. Any inheriting class will not be able to have it's own default main () method.

  1. Can a main () method be overloaded?

Yes. You can have any number of main () methods with different method signature and implementation in the class.

  1. Does the order of public and static declaration?

No. It doesn' t matter but void shoshould always come before main ().

  1. Can a source file contain more than one class declaration?

Yes. A single source file can contain in any number of Class declarations but only one of the class can be declared as public.

Public class test {

Public static void main (String [] args ){

}

Class test2 {

}

}

  1. What is a package?

Package is a collection of related classes and interfaces. Package declaration shocould be first statement in a java class.

  1. Which package is imported by default?

Java. lang package is imported by default even without a package declaration.

  1. Can a class declared as private be accessed outside it's package?

Not possible.


This article is from the "Mike Zhou's Garden" blog, please be sure to keep this source http://zmycoco.blog.51cto.com/3167754/1275123

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.