Core Java Question List No1
2013-05-27 22:05
253 查看
What is the most important feature of Java?
Java is a platform independent language.
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).
What is a JVM?
JVM is a Java Virtual Machine which is a run time environment for the compiled Java class files.
Are JVM’s platform independent?
JVM’s are not platform independent. JVM’s are platform specific run the implementation by the vendor.
What is the difference between JDK and JVM?
JDK is Java Development Kit which is for development purpose and it includes 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.
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.
What is the base class of all classes?
Java.lang.object
Does Java support multiple inheritances?
Java doesn’t support multiple inheritances.
Is Java a pure object oriented language?
Java uses primitive data types and hence is not a pure object oriented language.
Are arrays primitive data types?
In Java, Arrays are objects.
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.
What are local variables?
Local variables are those which are declared within a block of code like methods. Local variables should 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.
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.
How to define a constant variable in Java?
The variable should 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;
Should be main() method be compulsorily declared in all java classes?
No not required main() method should be defined only if the source class is a java application.
What is the return type of the main() method?
Main() method doesn’t return anything hence declared void.
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.
What is the argument of main() method?
Main() method accepts an array of String object as argument.
Can a main() method be declared final?
Yes. Any inheriting class will not be able to have it’s own default main() method.
Can a main() method be overloaded?
Yes. You can have any number of main() methods with different method signature and implementation in the class.
Does the order of public and static declaration?
No. It doesn’t matter but void should always come before main().
Can a source file contain more than one class declaration?
Yes. A single source file can contain 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{
}
}
What is a package?
Package is a collection of related classes and interfaces. Package declaration should be first statement in a java class.
Which package is imported by default?
java.lang package is imported by default even without a package declaration.
Can a class declared as private be accessed outside it’s package?
Not possible.
Java is a platform independent language.
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).
What is a JVM?
JVM is a Java Virtual Machine which is a run time environment for the compiled Java class files.
Are JVM’s platform independent?
JVM’s are not platform independent. JVM’s are platform specific run the implementation by the vendor.
What is the difference between JDK and JVM?
JDK is Java Development Kit which is for development purpose and it includes 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.
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.
What is the base class of all classes?
Java.lang.object
Does Java support multiple inheritances?
Java doesn’t support multiple inheritances.
Is Java a pure object oriented language?
Java uses primitive data types and hence is not a pure object oriented language.
Are arrays primitive data types?
In Java, Arrays are objects.
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.
What are local variables?
Local variables are those which are declared within a block of code like methods. Local variables should 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.
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.
How to define a constant variable in Java?
The variable should 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;
Should be main() method be compulsorily declared in all java classes?
No not required main() method should be defined only if the source class is a java application.
What is the return type of the main() method?
Main() method doesn’t return anything hence declared void.
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.
What is the argument of main() method?
Main() method accepts an array of String object as argument.
Can a main() method be declared final?
Yes. Any inheriting class will not be able to have it’s own default main() method.
Can a main() method be overloaded?
Yes. You can have any number of main() methods with different method signature and implementation in the class.
Does the order of public and static declaration?
No. It doesn’t matter but void should always come before main().
Can a source file contain more than one class declaration?
Yes. A single source file can contain 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{
}
}
What is a package?
Package is a collection of related classes and interfaces. Package declaration should be first statement in a java class.
Which package is imported by default?
java.lang package is imported by default even without a package declaration.
Can a class declared as private be accessed outside it’s package?
Not possible.
相关文章推荐
- Core Java Interview Question Answer
- Core Java Question List No3
- Core Java Question List No2
- Difference Between Arraylist And Vector : Core Java Interview Collection Question
- Android的ROS开发环境配置(Android+ROS+rosjava+android_core)
- Core Java学习笔记【1】-界面编程
- Websphere产生大量javacore与heapdump文件的分析
- javacore文件及heapdump文件分析
- spark core之java和scala版本——电影受众分析系统--得分最高的10部电影;看过电影最多的前10个人
- 2月1日 Core Java 周四
- iOS7 JavaStriptCore
- 事件处理 - core java
- jd-core java反编译工具
- corejava 面向对象
- corejava_OOP
- Core Java第九章知识点总结——接口
- FCKeditor_2.6.2.zip和fckeditor-java-core-2.4.jar的使用
- 【Java.Spring.Core】【IoC】ApplicationContext的附加功能(国际化,未完待续)
- [core Java学习笔记][第一二三章基本语法]
- Core Java基础知识之一(线程私房菜)