Introduction An exception represents an error condition that can occur during the normal course of program execution. When an exception occurs, it is said to be thrown. When it is thrown, the normal flow of the program terminates and the exception handling block will be executed. The execution handling block is the catch block. This …
Tag Archives: java
Javadoc – Documentation made easy
Java standardized the documentation process so everyone follows the same convention when documenting their code. You can easily read the required documentation instead of scratching your head on other people’s documentation. Javadoc is created using a JDK javadoc tool. The tool converts the documentation to fresh, standard and easy HTML page.No hassle! Example Order of …
Can a Semaphore act as a Mutex?
ANSWER: Let’s define both these terms. Semaphore: A semaphore control access to a shared resource using a counter. The counter measures the number of permits that are allowed. If a counter is zero, then access to the resource is denied. If it is greater than zero, then access to the resource allowed. Every time a …
What is meant by Java being platform independent.
ANSWER: Java is platform independent as it can be used on any system regardless of having different operating systems and file systems. The way it does this by using the Java virtual machine (“JVM”). Look at the flow chart below for how it does it.
What’s the difference between a class method and an instance method?
ANSWER: Class methods are declared as static hence they can be called without creating an instance of a class. Class methods can only operate on class members and not on instance variables since they are unaware of the instance members. In order to use an instance method, you must create a instance of a class …
Continue reading “What’s the difference between a class method and an instance method?”
Difference between Abstract vs. Interface
Abstract An abstract class can’t be instantiated, but it can be subclassed. An abstract class usually contains abstract and non-abstract methods that subclasses are forced to provide an implementation for. Abstract class doesn’t support multiple inheritance Abstract class can have final, non-final, static and non-static variables Abstract class can have static methods, main method and …
Continue reading “Difference between Abstract vs. Interface”
Java – While Statements
What is the difference between while and do while loop? Do while The do while loop will check the condition at the end of the loop. This way, the code inside the loop will be executed atleast once. Example Control-Flow While Loop The while loop checks a given condition. If the statement is true, the …
Java – Loop-and-a-half repetition control
Loop-and-a-half repetition control statements are used to control the flow of the loop. You wouldn’t want to run a loop forever. There will come a time when you need to stop a loop earlier and you can use the following statements to implement it: break; if statement while statement Example The break statement breaks out …
Continue reading “Java – Loop-and-a-half repetition control”
Java Interview Questions
1. What’s the difference between Abstract vs. Interface? ANSWER: An abstract class can’t be instantiated, but it can be subclassed. An abstract class usually contains abstract and non-abstract methods that subclasses are forced to provide an implementation for. An interface is a completely “abstract class” that is used to group related methods with empty bodies. …
Java: Access Modifiers
What is an Access modifier? Access modifiers are keywords used to specify the accessibility of a class (or type) and its members. These modifiers can be used from code inside or outside the current application. Private Default Protected Public Private: Data members and methods that are declared private are used on within that specific class it …