Java

Anonymous Inner Classes

Having dealt with inner classes in earlier posts this post deals with anonymous inner classes – an even more different type of code that causes more confusion for the amateur programmer. What are anonymous inner classes? ‘Anonymous inner classes’ or ‘Anonymous classes’ as the name suggests is creating an inner class with no name. Here is a simple program that illustrates the working of the anonymous class. Program 1: //Program to illustrate anonymous inner class package whizlabs; class anon_1 {      public static void main(String args[]){               pgm p1=new pgm();                pgm p=new pgm(){ // start of […]

Anonymous Inner Classes Read More »

Inner Classes – II

Continuing with our discussion of inner classes, this post will deal with how to create inner classes from outside the outer class instance code and also deal with the next type of inner class (inner classes declared inside methods) Recalling a few crucial points from last post, it should be remembered that An instance of inner class always exists only if an instance of outer class exists. Inner classes never exist alone. Inner classes always have access to all the methods and members of the outer class even if they are declared private.   In the previous post, we learnt

Inner Classes – II Read More »

Inner Classes

We have discussed access modifiers, exceptions, features of Java 8 in previous Java related posts. We will discuss ‘Inner classes’ which is a part of SCJP/OCJP exam objective in this post. Inner classes are part of the code that often stumps a person who is taking the SCJP/OCJP exam. Definition of Inner classes: Inner classes are classes which are nested within the outer classes. Why is this done? This is done to promote good object oriented design principles.   According to the Oracle documentation website, inner classes promote: “Encapsulation Readable and maintainable code Logical grouping of classes which is used only

Inner Classes Read More »

Exceptions II

We will extend our discussion about ‘Exceptions’ which we had started in an earlier post. These were the key takeaways from our earlier post: Differences between checked and unchecked exceptions Important points regarding ‘finally’ clause Specific exceptions must be declared before the general exceptions In this post, we will discuss the legal and illegal forms of ‘try-catch’ constructs and more ways to declare exceptions. A.  Legal and Illegal forms of ‘try-catch’ constructs : It is illegal to use ‘try-catch-finally’ clause without the ‘catch’ clause or the ‘finally’ clause. In other words, it is illegal to use the ‘try’ clause alone.

Exceptions II Read More »

Whizlabs Announces Oracle Certified Associate, Java SE 8 Programmer (OCAJP 8) Certification

Whizlabs Software holds market leader position on a global arena and bestows professional certification courses from last 14 years. It has helped 2 million users across 125+ countries, including Fortune 500 companies in gaining expertise in Project Management and Technology through its certifications. After gaining huge success in bestowing professional certifications, Whizlabs now announces Oracle Certified Associate, Java SE 8 Programmer (OCAJP 8) Certification under Oracle Java Certifications. The entire curriculum of OCAJP 8 is designed by experts of the industry so as to benefit experienced participants along with fresh candidates or students. This is an ideal certification for students

Whizlabs Announces Oracle Certified Associate, Java SE 8 Programmer (OCAJP 8) Certification Read More »

Exception Handling in Java

‘Exceptions’, handling them, declaring them is yet another objective of the OCPJP exam.  We will be dealing with ‘Exceptions’ and more particularly ‘Handling Exceptions’ in this post. According to the Oracle website, “An exception is an event, which occurs during the execution of a program that disrupts the normal flow of the program’s instructions.” (Java Tutorials) When the normal flow is disrupted and an exception is thrown, the exception is handled by means of a “try-catch” block. Types of exceptions: There are three types of exceptions – Checked exceptions, Errors and Runtime exceptions. This is the hierarchy of exceptions:  

Exception Handling in Java Read More »

Overloading and Overriding

‘Overloading’ and ‘Overriding’ is yet another crucial concept which is part of the ‘Java SE Programmer I’ exam. This concept like the other concepts of core Java, are important from a developer’s standpoint as well as for the certification exam. We will first discuss overloading and then move onto overriding. Overloading: ‘Overloading’ as the name suggests is done by creating multiple methods with same name – but with different argument lists, return type and access modifier. Out of the three points mentioned, it is important to note that a method is considered overloaded ONLY when it has a different argument

Overloading and Overriding Read More »

Java Access Modifiers – II

The concept of ‘access modifiers’, understanding them and working with them are some of the key objectives of the SCJP/OCJP exam. It is also important to understand this concept to excel as a Java developer as well.  We have already started our discussion of ‘Access modifiers’ in our earlier post. We will continue our discussion by extending it to ‘private access modifier’. ‘private modifier’: Only methods and variables can use the ‘private access’ modifier’. The ‘private access modifier’ is the most restrictive access modifier. One of the interesting ways to think about the ‘private access modifier’ is to view it

Java Access Modifiers – II Read More »

Thread States In Java

As we already know, multithreading is the most important aspect of Java. Every Java program runs in a single thread called, ‘main’ thread. From within this main thread, multiple threads are spawned and each executes concurrently and each thread will have its own stack. A thread will undergo various stages during its life cycle. In this article, we’ll discuss what are all the stages a thread goes through, and which part of JVM is responsible for moving threads from one state to another state. The thread scheduler is part of JVM whose primary responsibility is to decide which thread should

Thread States In Java Read More »

Uses Of Synchronized Keyword In Java

Concurrency problems are most common problems among multi-threaded applications. If one single thread is executing, it can gracefully get access to the resources and complete its execution. The problem arises when multiple threads competing with each other to get hold of resources. Due to this variety of problems can occur like inconsistent data, dead lock situations etc. Java mitigates these problems by synchronizing resource access so that single thread get to access resources and releases the resource for the next thread to process. This process is known as “synchronization” and we achieve synchronization using keyword “synchronized”. The “synchronized” keyword can

Uses Of Synchronized Keyword In Java Read More »

Scroll to Top