- upcasting vs downcasting
Java permits an object of a subclass type to be treated as an object of any superclass type. This is called upcasting.Upcasting is done automatically
downcasting must be manually
- What is a JVM?
JVM is Java Virtual Machine which is a run time environment for the compiled java class files.
- 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?
- Are arrays primitive data types?
- What is difference between Path and Classpath?
Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.
- What are local variables?
Local variables should be initialised before accessing them
- What are instance variables?
- How to define a constant variable in Java?
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 = 2.14; is an example for constant
- What is the return type of the main() method?
- What is the arguement of main() method?
- Can a main() method be overloaded?
- Does the order of public and static declaration matter in main() method?
- Can a source file contain more than one class declaration?
- What is a package?
package declaration should be first statement in a java class.
- Which package is imported by default?
- Can a class be declared as protected?
- What is the access scope of a protected method?
- What is the purpose of declaring a variable as final?
- What is the impact of declaring a method as final?
- I don't want my class to be inherited by any other class. What should i do?
But you can't define your class as final, if it is an abstract class final class can't be inherited, final method can't be overridden and final variable can't be changed.
- Can a class be declared as static?
- When do you define a method as static?
- What is the importance of static variable?
If one object changes the value then the change gets reflected in all the objects
- Can we declare a static variable inside a method?
If declared, the class will not compile.
- Can a abstract class be declared final?
- Can you create an object of an abstract class?
- Class C implements Interface I containing method m1 and m2 declarations. Class C has provided implementation for method m2. Can i create an object of Class C?
Since Class C didn't provide implementation for m1 method, it has to be declared as abstract. Abstract classes can't be instantiated.
- Can a method inside a Interface be declared as final?
public and abstract are the only applicable modifiers for method declaration in an interface.
- Which class is extended by all other classes?
- What is casting?
Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values.
Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.
- What do you understand by private, protected and public?
Private is the most restrictive, while public is the least restrictive.
There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.
- What is a native method?
- Is null a keyword?
- If a class is declared without any access modifiers, where may the class be accessed?
A class that is declared without any access modifiers is said to have package access. This means that the class can only be accessed by other classes and interfaces that are defined within the same package
- Are true and false keywords?
- What is the diffrence between inner class and nested class?
- What is the difference between a public and a non-public class?
- What is a Java package and how is it used?
- What is the difference between method overriding and overloading?
- How are this() and super() used with constructors?
this() is used to invoke a constructor of the same class.
super() is used to invoke a superclass constructor
- What is a transient variable?
- What is the difference between swing and Awt?
- What are pass by reference and pass by value?
On the other hand, pass by value means passing a copy of the value to be passed
- What is the difference between final, finally and finalize?
finally – handles exception
finalize – helps in garbage collection
- Name primitive Java types.
- What is super?
super is a keyword which is used to access the method or member variables from the superclass.
If a method hides one of the member variables in its superclass, the method can refer to the hidden variable through the use of the super keyword
- What is final modifier?
The final modifier keyword makes that the programmer cannot change the value anymore.
The actual meaning depends on whether it is applied to a class, a variable, or a method.
The actual meaning depends on whether it is applied to a class, a variable, or a method.
final Classes- A final class cannot have subclasses.
final Variables- A final variable cannot be changed once it is initialized.
final Methods- A final method cannot be overridden by subclasses
- What is the difference between static and non-static variables?
A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance.
http://forum.codecall.net/java-tutorials/20719-upcasting-downcasting.html
http://javarevisited.blogspot.com/2011/04/top-20-core-java-interview-questions.html
http://technical-interview.com/Java_Questions_1.aspx
- What is JNDI for?
directory services such as Lightweight Directory Access Protocol (LDAP),
distributed object systems such as the Common Object Request Broker Architecture (CORBA), Java Remote Method Invocation (RMI), and Enterprise JavaBeans (EJB).
- Classpath
Classpath is a parameter—set either on the command-line, or through an environment variable—that tells the Java Virtual Machine or the Java compiler where to look for user-defined classes and packages.
https://en.wikipedia.org/wiki/Classpath_%28Java%29
- An application with WEB-INF folder is a web application. Meaning it will be packed as a WAR file and deployed on a server
If you are using an IDE like eclipse, and you export the project as a WAR file, it will automatically take jars under the lib folder and pack them with the WAR and that will make them available for the application running on the server (jars under WEB-INF/lib are included in the application classpath).
If you just put them anywhere else and include them in the build path, when you export the project you have to declare that you want the jars in the build path to be included as well.
Basically, there is no big difference but if you know you need this jar in runtime (i.e. after deploying the application to the server), it is better to put it under the WEB-INF/lib folder.
What do you mean by build path?
Most of the JARs you use need to be available during building (compiling) because your code depends on them - otherwise it won't compile.
The real question is between placing JARs in WEB-INF/lib vs. your container /lib directory
In general you should always put your JARs inside an application in WEB-INF/lib
Placing them globally has several consequences:
singletons are now global to all web applications (one class loader) if multiple deployed
it's easier to introduce memory leak if a library holds a reference to any of your classes (see above)
you don't duplicate the same classes (each web application will reuse the same class as opposed to having a separate copy in each class loader
http://stackoverflow.com/questions/13679112/java-configuring-build-paths-or-web-inf-lib-folder
- By default, Tomcat container doesn’t contain any jstl library. To fix it, declares jstl.jar in your Maven pom.xml file if you are working in Maven project or add it to your application's classpath
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
http://stackoverflow.com/questions/15113628/java-lang-classnotfoundexception-javax-servlet-jsp-jstl-core-config