Java hashCode() and equals() methods. Learn contract between hashCode and equals methods. How to correctly override both methods and best practices.
Learn about Java wrapper classes, their usage, conversion between primitive and object; and autoboxing and unboxing with examples. 1. Java Wrapper classes Java provides type wrappers, which are classes that encapsulate a primitive type within an object. In Java, we have 8 primitive data types. A wrapper class wraps (encloses) around a data type and […]
Learn everything about Java comments, types of Java comments, Javadoc tool, performance impact of comments and best practices to follow. 1. Why write Java comments? Java comments, as the name suggests, are notes you write between the programs for various reasons. For example, you may write comments to – write information or explanation about the […]
Learn about Java variables, types of variables in Java, example of how to declare variables and best practices for Variable naming convention. The Java programming language uses both “fields” and “variables” as part of its terminology. Fields refer to variables declared outside methods, and variables are referred to declarations inside methods, including method arguments. 1. […]
JDK, JRE and JVM is very common words when developers talk about java applications and their development environments. Let’s find out the differeneces between these words.
Learn to compare double or compare float to avoid unexpected results caused by minor rounding errors during conversions at lower level program execution.
Static keyword in java can be applied on variables, methods, blocks, import and inner classes. Learn the effect of using static keyword in detail.
Use given syntax examples for setting CLASSPATH for any java application runtime, in windows and linux environments.
Java maintains a set of system properties for its operations. Each java system property is a key-value (String-String) pair such as “java.version”=”1.7.0_09“. You can retrieve all the system properties via System.getProperties() or you can also retrieve individual property via System.getProperty(key). Please note that Access to system properties can be restricted by the Java security manager […]
The normal import declaration imports classes from packages, so that they can be used without package reference. Similarly the static import declaration imports static members from classes and allowing them to be used without class reference. A static import declaration also comes in two flavors: single-static import and static-import-on-demand. A single-static import declaration imports one […]
Classes are the basic units of programming in the object-oriented paradigm. In this tutorial, learn to write Java class and how to create object in Java.
After learning break statements, lets quickly recap about another important keyword “continue” in java. In one sentence, the continue statement skips the current iteration of a for loop, while loop, or do-while loop. Let’s go deeper into continue statements. A continue statement can only be used inside the for-loop, while-loop, and do-while statements. There are […]
We have already learned about primitives, operators and control statements like if-else, for loop, switch statement and while loop. Now let’s learn about another important keyword i.e. break statement. A break statement is used to exit from a block. There are two forms of the break Statements: Unlabeled break statement Labeled break statement Unlabeled break […]
During learning “While Loop” we saw that it continually executes a block of statements while a particular condition is true. The difference between do-while loop and while loop is that do-while evaluates its expression at the bottom of the loop instead of the top. Therefore, the statements within the do block are always executed at […]
The while statement or loop continually executes a block of statements while a particular condition is true. Its syntax can be expressed as: The condition-expression must be a boolean expression and the statement can be a simple statement or a block statement. If the expression evaluates to true, the while statement executes the statement(s) in […]
In previous tutorial, we learned about for loop in java. Java 5 introduced an foreach loop, which is called a enhanced foreach loop. It is used for iterating over elements of arrays and collections. Java foreach loop syntax The general syntax for a for-each loop is as follows: Java foreach loop – array For example, […]
The for statement provides a compact way to iterate over a range of values. Programmers often refer to it as the “for loop” because of the way in which it repeatedly loops until a particular condition is satisfied. The general form of the for statement can be expressed as follows: Here : The initialization expression […]
As if-else statement tells your program to execute a certain section of code only if a particular test evaluates to true or false, the switch statement can have a number of possible execution paths. A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types, the String […]
The if-then statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true. The format of an if-else statement is : if (condition) statement1 else statement2 The condition must be a Boolean expression. That is, it […]
A block statement is a sequence of zero or more statements enclosed in braces. A block statement is generally used to group together several statements, so they can be used in a situation that requires you to use a single statement. In some situations, you can use only one statement. If you want to use […]