"For every success of a man there will be a countless pain in his heart and that pain makes him a successful person in life"

When You are at the Peak of Concentration, You don't feel whether u r programming in C/C#/JAVA or any other, You just type the keys on keyboard and your sub-conscious mind does the rest...!

Myspace GlittersMyspace GlittersMyspace GlittersMyspace GlittersMyspace GlittersMyspace GlittersMyspace GlittersMyspace Glitters




 
   

Java Fundamentals

   
 


 

 

Home

Guestbook

GALLERY

MySQL

C/C++ Interview Questions

C/C++ Test Paper 1

C/C++ Test Paper 2

C Tricky Snippets

C - Pointers

C - Functions

C - Iterations, Operators

Java Interview Questions

Java Fundamentals

Java FAQs

J2EE - FAQs

Java - Best Collection Ever

Java/J2EE Test 1

Java Test 2

Java Servlets - FAQs

SCJP 5.0 Syllabus

SCJP Exam 1

SCJP Exam 2

SCJP Exam 3

SCJP Exam 4

SCJP Exam 5

Relational Database Management Systems(RDBMS) Imp. Concepts

SQL Server - Interview Questions

SQL Server 2

Data Structures

OOPS - FAQs

Object Oriented Programming (OOP) Concepts

Operating Systems - FAQs

Operating System Concepts

Networking Concepts

UML - Quick Reference

VB - FAQs

Secrets About Windows Operating Systems

 


     
 

General Questions about JaVa

Language Fundamentals

Q. Is Java a pure OO language?

 

A: No, it is not.

neither are C++/C#/etc. SmallTalk is general considered as a pure OO language. In SmallTalk, everything is an object, including int or even + sign. Java is one step more close to SmallTalk than C++, but it is still not pure OO language. 

 

Q. What are Java key words and reserved words? What are the differences?

A:

Key words are reserved words. but not vice versa. See Java Language Keywords for details.

 

Q. What are Java key words this?

A:

this is a keyword used in Java/C++ code to refer the current instance object itself.

 

Q. What modifiers should be used for main method? Why could I violate the rule, and it still works?

A:

The official modifiers and signature for main method is

public static void main(String[] args){}

You should remember it, and use this for your SCJP test.

However, if you miss public or even use private instead, some JVM might let you launch your Java application without complaining or error messages. Why?
Because some JVMs just make themselves more tolerant then they should be. This kind of practice is very common in Microsoft world.

 

Q. What will happen if I omit static modifier for main method? Should I do that?

A: The code will compile, but not functional as you wanted (if you want something normal, of course).

The main() method is supposed to be the entrance of the entire application.

However, if you omit static, it is just another instance method, happen to be called main. It will not work as you expected. It will make yourself and your coworker confused. also make yourself confused. It will become maintenance hazard.

Q. How does Java compiler resolve the ambiguity to decide which methods to call?

A:

In the following example, four test() methods, if we pass ambiguous b{null} to the test, which one should (will) be called? The 3 on top has super/subclass/sub-subclass relationship. The most specific one (down hierarchy) will be called. The 4th with String as a parameter, but it is a sibling of Tester. Ambiguity compile time error results.

class Tester { 

 void test(Object s) { System.out.println ("Object version"); }

 void test(Tester s) { System.out.println ("Tester version"); }

 void test(SubTester s) { System.out.println ("SubTester version"); }



 // Not compilable any more if you uncomment the line

 // since String and Tester are siblings

 // void test(String s) { System.out.println ("String version"); }



 public static void main (String args[]) {

 Tester c = new Tester ();

 // Ambiguous, the most specific one which fit will be call

 c.test (null); // SubTester version

 c.test (new Object()); // Object version

 }

}



class SubTester extends Tester{

}

"The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error." Quotation from JLS2

 

Q. What is the return type of constructor, if any?

A: constructor has no return type.

 

Q. Is null the same as void in Java? Can I return null in a void return type method?

A: No! Another No!

void means return nothing. null in Java means it is a reference type, but refers nothing. null and void are very different things. For further interest, read here.

 

Q. What are the rules to name a Java file without public class defined in it?

A:

Everyone knows one Java file only can contain one public class, and the file must be named as the name of the public class name. But how about Java file with no public class?

No restrictions on name of Java file without public class defined. If you have a class with a main, you'd better name the file with that class name for your own convenience. However, this is not required. Test this out!

// D.java

class A {}

class B {}

class C {}

class E {

 public static void main(String[] args) {

 System.out.println("Strange thing in E.");

 }

}

class F {

 public static void main(String[] args) {

 System.out.println("Strange thing in F.");

 }

}

It is called D.java. You can run it in 2 ways:
java E //output: Strange thing in E.
java F //output: Strange thing in F.

 

Q. Where can I find Java Grammar?

A:

The best answer is to read the JLS, THE JAVA LANGUAGE SPECIFICATION from the source. Java grammar is officially defined there.
For your academic type, there is an interesting site, called Lykkenborg eZine. The author tried to make Java grammar easier to navigate.

 

 

 

 
 

 

 

Thank You.. Visit Again

This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free