Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

JAva

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1. A local variable cannot be defined with "static" keyword.

2. Instance variable is not declared as static.


3. The case variables can be int, short, byte, char, or enumeration. String type is also
supported since version 7 of Java
4. Constructor name must be the same as its class name
5. A Constructor must have no explicit return type
6. A Java constructor cannot be abstract, static, final, and synchronized
7. The static method can not use non static data member or call non-static method
directly.
8. this and super cannot be used in static context.
9. Java static block
 Is used to initialize the static data member.
 It is executed before the main method at the time of classloading.
10. Call to this() must be the first statement in constructor.
11. In java programming, multiple and hybrid inheritance is supported through interface
only.
12. A static method cannot be overridden. It is because the static method is bound with
class whereas instance method is bound with an object. Static belongs to the class
area, and an instance belongs to the heap area.
13. super keyword in Java is a reference variable
14. Usage of Java super Keyword
 super can be used to refer immediate parent class instance variable.
 super can be used to invoke immediate parent class method.
 super() can be used to invoke immediate parent class constructor.
15. There are mainly three rules for the instance initializer block. They are as follows:
 The instance initializer block is created when instance of the class is created.
 The instance initializer block is invoked after the parent class constructor is
invoked (i.e. after super() constructor call).
 The instance initializer block comes in the order in which they appear.

16. Final keyword :


 If you make any method as final, you cannot override it.
 If you make any class as final, you cannot extend it.
 A final variable that is not initialized at the time of declaration is known as blank
final variable. It can be initialized only in constructor.
 A static final variable that is not initialized at the time of declaration is known as
static blank final variable. It can be initialized only in static block.

Can we declare a constructor final?


 No, because constructor is never inherited.
17. Runtime polymorphism can't be achieved by data members.
18. A class which is declared as abstract is known as an abstract class. It can have
abstract and non-abstract methods. It needs to be extended and its method
implemented. It cannot be instantiated.
19. A method which is declared as abstract and does not have implementation is known as an
abstract method.
20. If there is an abstract method in a class, that class must be abstract.
21. If you are extending an abstract class that has an abstract method, you must either
provide the implementation of the method or make this class abstract.
22. An interface is declared by using the interface keyword. It provides total
abstraction; means all the methods in an interface are declared with the empty
body, and all the fields are public, static and final by default. A class that
implements an interface must implement all the methods declared in the interface.
23. The Java compiler adds public and abstract keywords before the interface method.
Moreover, it adds public, static and final keywords before data members.
24. If you import a package, subpackages will not be imported.
25. A class cannot be private or protected except nested class.
26. The Object class is the parent class of all the classes in java by default.
27. Java strictfp keyword ensures that you will get the same result on every platform if
you perform operations in the floating-point variable. The strictfp
keyword cannot be applied on abstract methods, variables or constructors.
28. The Java String is immutable. For mutable strings, you can use StringBuffer and
StringBuilder classes.
29. String objects are stored in a special memory area known as the "string constant
pool".
30. String s=new String("Welcome");//creates two objects and one reference variable

In such case, JVM will create a new string object in normal (non-pool) heap memory,
and the literal "Welcome" will be placed in the string constant pool. The variable s
will refer to the object in a heap (non-pool).

31. String s=50+30+"Sachin"+40+40;


System.out.println(s);//80Sachin4040
After a string literal, all the + will be treated as string concatenation operator.

Java String compare :


 By Using equals() Method : The String class equals() method compares
the original content of the string. It compares values of string for
equality.
 By Using == Operator : The == operator compares references not
values.
 By compareTo() Method : The String class compareTo() method
compares values lexicographically and returns an integer value that
describes if first string is less than, equal to or greater than second
string.

32. Java StringBuffer class is thread-safe i.e. multiple threads cannot access it
simultaneously. So it is safe and will result in an order.
33. The capacity() method of the StringBuffer class returns the current capacity of the
buffer. The default capacity of the buffer is 16. If the number of character increases
from its current capacity, it increases the capacity by (oldcapacity*2)+2.
34. Java StringBuilder class is used to create mutable (modifiable) String. The Java
StringBuilder class is same as StringBuffer class except that it is non-synchronized.
It is available since JDK 1.5.
35. Also, observe that a string literal can also invoke the concat() method .
String s = "India is my ".concat(str);
36. Java String Contains() method does case sensitive search.
37. The contains() method only checks for the presence or absence of a string in
another string.
38. Java String endsWith() method check for case sensitivitiness and also it returns
true if we pass empty string(str.endsWith(“”)) as an argument because every string
ends with “” but if we pass null (str.endsWith(null)) as argument then it returns
false.
39. A thread is a lightweight sub-process, the smallest unit of processing.
Multiprocessing and multithreading, both are used to achieve multitasking. Threads
are independent. Thread class extends Object class and implements Runnable
interface.
40. If you want to make a user thread as Daemon, it must not be started otherwise it
will throw IllegalThreadStateException.
41. The Garbage collector of JVM collects only those objects that are created by new
keyword. So if you have created any object without new, you can use finalize
method to perform cleanup processing (destroying remaining objects).
42. If you make any static method as synchronized, the lock will be on the class not on
object.
43. If parent class constructor throws any checked exception, compulsory child class
constructor should throw the same checked exception as its parent, otherwise code
won’t compile.
44. this() and super() cannot be used in a method. This throws compile time error.
45. If a static method is present in the program then it will be executed first, then main
will be executed.
46. Recursion is always managed by operating system.
47. Type IV JDBC driver is a driver which communicates through Java sockets.

You might also like