w3resource

Java Programming Exercises, Practice, Solution

Java Exercises

Java is the foundation for virtually every type of networked application and is the global standard for developing and delivering embedded and mobile applications, games, Web-based content, and enterprise software. With more than 9 million developers worldwide, Java enables you to efficiently develop, deploy and use exciting applications and services.

The best way we learn anything is by practice and exercise questions. Here you have the opportunity to practice the Java programming language concepts by solving the exercises starting from basic to more complex exercises. A sample solution is provided for each exercise. It is recommended to do these exercises by yourself first before checking the solution.

Hope, these exercises help you to improve your Java programming coding skills. Currently, following sections are available, we are working hard to add more exercises .... Happy Coding!

List of Java Exercises:

Java Basics Java Data Types Java Control Flow Java Math and Numbers Object Oriented Programming Exception Handling Functional Programming Multithreading Data Structures Strings and I/O Date and Time Advanced Concepts Algorithms Regular Expressions

Note: If you are not habituated with Java programming you can learn from the following :

More to Come !

Popularity of Programming Language
Worldwide, Sept 2023 compared to a year ago:

`
Rank Change Language Share Trend
1 Python 27.99 % +0.1 %
2 Java 15.9 % -1.1%
3 Javascript 9.36 % -0.1%
4 C# 6.67 % -0.4%
5 C/C++ 6.54 % +0.3 %
6 PHP 4.91 % -0.4 %
7 R 4.4% +0.2%
8 TypeScript 3.04 % +0.2%
9 up arrow Swift 2.64 % +0.6%
10 Objective-C 2.15% +0.1%
11 up arrow Rust2.12% +0.5%
12 down arrow Go 2.0% -0.1%
13 down arrow Kotlin 1.78 % -0.0%
14 Matlab 1.58 % +0.1%
15 Ruby 1.05% -0.1%
16 up arrow Ada 1.02 % +0.3 %
17 up arrow Dart 0.95 % +0.1 %
18 down arrow Powershell 0.94 % +0.0 %
19 down arrow VBA 0.91 % -0.1 %
20 Scala 0.64 % -0.1 %
21 Lua 0.59 % -0.0 %
22 Visual Basic 0.58 % -0.0 %
23 Abap 0.57 % +0.1 %
24 Julia 0.38 % -0.1 %
25 Groovy 0.37 % -0.0 %
26 Perl 0.28 % -0.1 %
27 Cobol 0.27 % -0.1 %
28 Haskell 0.23 % -0.1 %
29 Delphi/Pascal 0.15 % +0.2 %

Source : https://pypl.github.io/PYPL.html

TIOBE Index for September 2023

Sep 2023 Sep 2022 Change Programming Language Ratings Change
1 1 Python 14.16% -1.58%
2 2 C 11.27% -2.70%
3 4 up arrow C++ 10.65% +0.90%
4 3 down arrow Java 9.49% -2.23%
5 5 C# 7.31% +2.42%
6 7 up arrow JavaScript 3.30% +0.48%
7 6 down arrow Visual Basic 2.22% -2.18%
8 10 up arrow PHP 1.55% -0.13%
9 8 down arrow Assembly language 1.53% -0.96%
10 9 down arrow SQL 1.44% -0.57%
11 15 up arrow Fortran 1.28% +0.26%
12 12 Go 1.19% +0.03%
13 14 up arrow MATLAB 1.19% +0.13%
14 22 up arrow Scratch 1.08% +0.51%
15 13 up arrow Delphi/Object Pascal 1.02% -0.07%
16 16 Swift 1.00% +0.02%
17 26 up arrow Rust 0.97% +0.47%
18 18 R 0.97% +0.02%
19 20 up arrow Ruby 0.95% +0.30%
20 34 up arrow Kotlin 0.90% +0.59%

Source : https://www.tiobe.com/tiobe-index/

List of Exercises with Solutions :

[ Want to contribute to Java exercises? Send your code (attached with a .zip file) to us at w3resource[at]yahoo[dot]com. Please avoid copyrighted materials.]

Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.



Follow us on Facebook and Twitter for latest update.

Java: Tips of the Day

Handling Null Pointer Exception

Null pointer exception is a runtime exception that is thrown when an application is trying to use an object reference with a null value.

String fruit;
spellChecker(fruit);

Here a null reference variable is passed as an argument of a method.

positionLocator(null);

In the above code snippet, null is directly passed to a function. In both these instances, there is a high possibility of throwing the NullPointerException.

This exception can be fixed by using the if-else condition.

public class NullPointerExceptionExample{
    public static void main(String args[]){
        String fruit = "apple";
        positionLocator(null);
}//Using an if-else condition
    static void positionLocator(String fruit){
        if(fruit != null){
           System.out.println("Second character: "+fruit.charAt(0));
        }
        else {
           System.out.println("NullPointerException thrown");
        }
    }}

Ref: https://bit.ly/3mi39Nr

 





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook