Best Way to Learn Java for a Beginner

Here you will know what is the best way to learn java for a beginner. Programming is the new vogue and a vogue which can make you earn wonders and at the same time make you utilize the capabilities of your brain to the fullest. Learning new programming languages however can sometimes turn out to be challenging especially when the language is one which holds immense importance in various fields. Java is definitely one of those languages which most of

Read more

Evaluate Postfix Expression in Java

In this article, we will look at how to evaluate a given Postfix expression to a result value. This is a problem related to Stack Data Structure. We will look at the algorithm with a step-by-step example along with the implementation in code. Let us first have a quick look at Postfix Expressions. So, Postfix Expressions are the mathematical expressions where for each pair of Operator and Operands, the operators come after operands. Hence, the evaluation order is from left

Read more

Java Reflection Invoke Static Method

This article will look at how we can use Java Reflection API to invoke a Static method. We will see the steps and the explanation with code. Let us first have a quick look at Reflection API. Reflection in Java is a process of examining or modifying the behavior of a class at run time. Moreover, It is an API or Application Programming Interface having its use in debugging. It is also used in testing tools, with the primary focus

Read more

Volatile vs Synchronized in Java

In this article, we will discuss volatile vs synchronized in Java. First, we will define what is synchronized. Synchronized Keyword Synchronized is the keyword which is applied on blocks and methods but not on the classes and variables. When multiple threads are trying to access the same Java object so this situation leads to a data inconsistency problem. So in this situation, we should go for a synchronized keyword. So we use synchronized keywords along with the name of the

Read more

One Dimensional Array in Java – 1D Array

Here, we will discuss what is a one-dimensional array and how to use it in Java. A one-dimensional array or 1D array is the list of variables of the same data type stored in the contiguous memory locations. We can access these variables of a 1-d array by an index value in square brackets followed by name of the array. So to declare the array we need the datatype of the values which we want to store, array name, and

Read more

Java Program for Employee Details using Class and Object

In this article, we will talk about the Java program for employee details using class and object. An Employee is a person or also be referred to as an entity that consists of various attributes such as – emp_id, emp_name, emp_salary, emp_department, emp_email, emp_address, and many more. We use the getter (to receive Employee details) and setter (to set Employee details) method in this program. In the main class, we will create an object of the EmployeeDetails class and with

Read more

Covariant Return Type in Java

In this article, we will learn about covariant return types in Java. Before Java version 5.0, we could not change the return type of an overridden method but a new method was introduced in JDK 5.0, called covariant where we could change the return type of the overridden method. The return type must be non-primitive. (i.e., it should be a sub-type of the overridden class). Program:

Output:

Explanation: In the above program, we created three classes: class ‘Employee’,

Read more

Static Import in Java with Example

In this article, we will discuss static import in Java. Just as import statements are used to access a class without its package qualification. In a similar manner, static imports are used to access static members without their class qualification. Some basic static methods used with the class names are as follows: Math.sqrt(4): It is used to find the square root of the given number. Math.max(4, 2): It is used to find the maximum of the given numbers. Math.min(4, 2):

Read more

Advantages and Disadvantages of Generics in Java

Generics in Java program was introduced in Java version 5. It is used to ensure the data type safety of objects. So, it constructs the code steady by detecting bugs at compile time. Why do we need generics in Java? When we write programs, errors occur. Some errors occur at run time while some errors occur at compile time. Those errors which occur at compile-time can be easily detected and rectified in the program. But, run time errors occur when

Read more
1 2 3 25