The Best Technical Blog Ever


Important Key Points in java

  1. Java is a high level, robust, secured , platform independent and object oriented programming language.

  2. Java is a case sensitive language. Here, uppercase and lowercase characters are treated as different.

  3. Java Virtual Machine(JVM) interprets the byte code into the machine code depending upon the underlying operating system and hardware combination.

  4. Class is a group of objects that has common properties. The class is a template or blueprint from which objects are created. Ex. Student.

  5. Object is an entity that encapsulates state and behavior. A software object's state is stored in fields (data members) and behavior is explained via methods. It is an instance of a class created using a new operator. Ex. student1.

  6. We can access data members and methods by using objects. Ex. objName.datamember , objName.Method().

  7. Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.

  8. Anonymous object is an object that have no reference (nameless object) .

  9. Access modifier defines who can access the class and it's members of the class.

  10. A java class can contain fields, methods and constructors.

  11. Methods are the group of operations that carry out a certain functions together. They are used to expose behavior of an object. Main advantage is code reusability.

  12. Constructors are used to initialize the objects. It is executed when an object of that class is created. It has the same name as the class. A constructor has no return value. A constructor is always called with the new operator.

  13. Every class has a constructor. If we do not explicitly write a constructor for a class, then the compiler builds a default constructor for that class.

  14. The data type defines the kind of data stored in a variable. There are two types of data types. 1).primitive data type 2).non-primitive data type.

  15. Variable is used to provide some named storage allocated in memory that can be manipulated by our programs.

  16. Local variables don't have any default value. hence, before using that variable, they needs to be initialized.

  17. Local variables are visible only within the declared block. So access modifiers cannot be used for local variables.

  18. Instance variables are created when an object is created and destroyed when the object is destroyed. They used to store object's states. They are visible for all methods, constructors and blocks in the class. Default value is 0.

  19. In static variable, all objects of the same class share a single copy of static variables. They are created when the program starts and destroyed when the program stops. Default value is 0.

  20. Static variables are usually used as constants. Static variables can be accessed in two ways 1) using object of the class 2)using class name ClassName.VariableName.

  21. The static final variables are constants. This constant variable's name should be in upper case but you can use underscore(_) between it.

  22. A private access modifier is accessible only within class. The main usage the private modifier is hiding the data from the outside world.

  23. A private access modifier is accessible only within class. The main usage the private modifier is hiding the data from the outside world.

  24. A protected access modifier is accessible within package (all classes) and sub classes of other package through inheritance. The protected access modifier can be applied on the data member, method and constructor. It can't be applied on the class.

  25. The public access modifier is accessible from everywhere.

  26. if(condition): The code inside the if statement is executed only if a condition is true. It only takes a boolean expression( TRUE / FALSE) as its condition.

  27. The switch statement allows execution of different statements depending on the value of an expression. Here, the variable being switched on is checked for each and every case.

  28. A while loop is a control structure that allows you to repeat a task a certain number of times. It executes statement(s) until a condition holds true.

  29. The do while loop is guaranteed to execute at least one time. It is similar to while loop. Here, condition appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested.

  30. A for loop is a repetition control structure that allows you to efficiently execute a loop for a specific number of times. A for loop is useful when you know how many times a task is to be repeated.

  31. Enhanced for loop/ foreach loop is another version of for loop. Here also, we use for keyword. Foreach loop is used, when we want to iterate on the elements inside an array.

  32. Break is used to stop the iterations in control statements. It will stop the execution and transfers control to the line immediate outside of loop. The break keyword must be used inside any loop or a switch statement.

  33. Continue statement is used when we want to skip the rest of the statement in the body of the loop and continue with the next iteration of the loop. It continues the iteration when the conditional statement is true.

  34. The return statement is used in methods to return a value and transfers the control back to the calling method. To use return, give the value of an expression after the return keyword. The data type of the returned value must match the type of the declared method.

  35. If the method is declared void, we can't return any value. In that case, use return that doesn't return a value.

  36. An array is a collection of similar type of elements that can be accessed by a numerical index. It is a way to store many values under the same name. The length of an array is established when the array is created. First element of the array is stored at index 0. Indices start from 0 to arrayVar.length-1. Array elements are stored in contiguous memory location.

  37. Array allows random accessing of elements i.e. any element of the array can be randomly accessed using indexes.

  38. We can store only fixed size of elements in the array. So the memory which is allocated to array cannot be increased or reduced at run time.

  39. The elements of array are stored in consecutive memory locations. So insertions and deletions are very difficult and time consuming process. To delete one element in the array, we need to traverse throughout the array.

  40. If you create String object using String literal , JVM first checks the string pool. If it already exists, it will return an existing object from String pool. Otherwise new String object will be created and placed in string pool for future use.

  41. When you create String object using new() operator, it always create a new object in heap memory.

  42. Exceptions Handling is used to catch an exception using a combination of the try and catch blocks. A try block can be followed by multiple catch blocks.

  43. If a method does not handle a checked exception, then it must declare it using the throws keyword.

  44. Java does not support multiple inheritance.

  45. For inheriting a class to another class, Java uses the extends keyword.

  46. Method overriding means redefining the method of base class in derived class with the same signature.

  47. A final class cannot be extended by any other class. So no class can inherit any feature from the final class.

  48. A final method cannot be overridden by any subclass.

  49. The final varibles can be explicitly initialized only once. It's value cannot be changed. Final variables are like constants.

  50. finalize() method is used just before an object is destroyed and can be called just prior to garbage collection.

  51. finally is a key word used in exception handling. The finally block will execute whether or not an exception is thrown.

  52. static defines that you can run the method without creating an instance of class.

  53. Abstract class is declared using ' abstract ' keyword. The purpose of abstract class is to be extended. If a class contains abstract methods then the class should be declared abstract. Otherwise compiler will throw error. We can't create objects using abstract class. An abstract class has at least one abstract method.

  54. Abstract class is used when there are some common features to be implemented in the same way in all of its objects. A programmer writes an interface when the features having different implementation in different objects.

  55. An abstract class can have abstract as well as nonabstract methods in it.

  56. Abstract methods doesn't have a method body. Abstract method is declared without any implementation. The method body is provided by sub class. These methods can never be final and it can't be used as private. Any class that extends an abstract class must implement all the abstract methods of the super class unless the subclass is also an abstract class.

  57. super() is used to call the constructor of the super class from the sub class. But, superclass constructor call must be the first statement in subclass constructor. If you want to run any method of the superclass from subclass, use super keyword like, super.methodnameInsuperclass(arg)

  58. this() is used to invoke a constructor of the same class.

  59. this keyword can be used to refer current class instance variable.

  60. When a method is synchronized, it can be accessed by only one thread at a time. These type of methods have synchronized keyword. It can be applied with any of the four access modifiers.

  61. The transient modifier tells the Java object serialization subsystem to exclude/skip the field when serializing an instance of the class. When the object is then deserialized, the field will be initialized to the default value. The transient modifier applies to variables only and it is not stored as part of its object's Persistent state. Transient variables are not serialized.

  62. The volatile modifier is used to inform the compiler that a thread accessing the variable must always merge its own private copy of the variable with the master copy in the memory. It also tells the compiler that the volatile variable can be changed unexpectedly by other parts of your program.

  63. Native Methods are specified in the class as method prototypes with prefix native keyword, no method body is defined in the Java class. But that method is implemented on a platform dependent code. They are also called as Foreign methods.

  64. The Vector class provides the capability to implement a growable array of objects.

  65. An automatic garbage collector deallocates memory for objects that are no longer needed by your program.

  66. Multithreading manages multiple tasks simultaneously. Main advantage is that it shares the same memory.

  67. Hash code is the unique ID number given to every object by the JVM. Hash code is also called reference number.

For a complete detail of the Java Programming language, it is recommended to visit Java Tutorial.

Keypoints to remember in java

1. Java is a high level, robust, secured , platform independent and object oriented programming.... more info

Back to Basics:- Java Syntax

In this session, you are going to refresh some basic set of rules(java syntax), defining how a ... more info

Total Visits
Traffic feed status