Java Examples

Related Tags

Tutorials

HowToDoInJava AMP Logo

Java Program to Add Two Integers

Learn to write a simple Java program to add two integers and display their sum in the console. 1. Java example to add two integers In given Java exmple, we have three int type variables i.e. firstInteger, secondInteger and sum. We have assigned values to the first two integers, and then we have added them. …

[Solved] Error: Could not find or load main class

We may get this error (Could not find or load main class) while running the Java class (e.g. Hello world application) from the system console. We get this error because we are incorrectly trying to run the main() inside the class using java command. 1. Reason for error – could …

Java Examples

To learn Java or any other programming language, the only best way is to practice and practice more. The more you do the coding, the better you get as time passes. These listed Java examples cover some very basic Java fundamentals and present you few alternative solutions to any single …

Program to calculate average of N numbers

Learn to calculate the average of the given N numbers in Java using three different methods. All methods are different based on how they provide the input to the program. 1. Algorithm for calculating the average In simple words, to calculate the average of N numbers we have to add …

Java – Set Classpath from Command Line

Learn to use the -classpath or -cp option to set the Java classpath from the command prompt in Windows and Linux OS. 1. Java Classpath The classpath is the list of directory locations that the Java runtime environment searches for the classes and other resource files, during program execution. The …

Count Vowels and Consonants in Java

Learn the different ways of counting the number of vowels and consonants in a given string using the Java 8 Streams and simple iteration.

Java program to reverse words in string without using functions

In these java programs, learn to reverse the words of a string in Java without using api functions. We can reverse the words of string in two ways: Reverse each word’s characters but the position of word in string remain unchanged. Reverse the string word by word but each word’s …

Java program to swap two numbers

Learn to swap two numbers in given two Java programs. First program uses a temporary variable while second program does not uses any temp variable.

Java Program to Check Deficient number

Learn to write a simple java program to verify if a given number is deficient number or not. The value 2n − σ(n) is called the number’s deficiency.

Usage of class sun.misc.Unsafe

This post is next update in sequence of discussions regarding little known features of java. Please subscribe through email to get updated when next discussion goes live. And do not forget to express your views in comments section. Java is a safe programming language and prevents programmer from doing a …

Java – Internal Caching in Wrapper Classes

1. Object Creation is Expensive We know to create objects in java using the new keyword. A new instance created in Java allocates the memory in the heap, so creating new objects is considered an expensive operation. To avoid this expensive object creation process, many of the frameworks have been …

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.