Tutorials
References
Exercises
Videos
Menu
Log in
Create Website
Get Certified
Upgrade
HTML
CSS
JAVASCRIPT
SQL
PYTHON
JAVA
PHP
BOOTSTRAP
HOW TO
W3.CSS
C
C++
C#
REACT
R
JQUERY
DJANGO
TYPESCRIPT
NODEJS
MYSQL
Dark mode
Dark code
×
Tutorials
HTML and CSS
Learn HTML
Learn CSS
Learn RWD
Learn Bootstrap
Learn W3.CSS
Learn Colors
Learn Icons
Learn Graphics
Learn SVG
Learn Canvas
Learn How To
Learn Sass
Data Analytics
Learn AI
Learn Machine Learning
Learn Data Science
Learn NumPy
Learn Pandas
Learn SciPy
Learn Matplotlib
Learn Statistics
Learn Excel
XML Tutorials
Learn XML
Learn XML AJAX
Learn XML DOM
Learn XML DTD
Learn XML Schema
Learn XSLT
Learn XPath
Learn XQuery
JavaScript
Learn JavaScript
Learn jQuery
Learn React
Learn AngularJS
Learn JSON
Learn AJAX
Learn AppML
Learn W3.JS
Programming
Learn Python
Learn Java
Learn C
Learn C++
Learn C#
Learn R
Learn Kotlin
Learn Go
Learn Django
Learn TypeScript
Server Side
Learn SQL
Learn MySQL
Learn PHP
Learn ASP
Learn Node.js
Learn Raspberry Pi
Learn Git
Learn MongoDB
Learn AWS Cloud
Web Building
Create a Website
NEW
Where To Start
Web Templates
Web Statistics
Web Certificates
Web Development
Code Editor
Test Your Typing Speed
Play a Code Game
Cyber Security
Accessibility
Join our Newsletter
Data Analytics
Learn AI
Learn Machine Learning
Learn Data Science
Learn NumPy
Learn Pandas
Learn SciPy
Learn Matplotlib
Learn Statistics
Learn Excel
Learn Google Sheets
XML Tutorials
Learn XML
Learn XML AJAX
Learn XML DOM
Learn XML DTD
Learn XML Schema
Learn XSLT
Learn XPath
Learn XQuery
×
References
HTML
HTML Tag Reference
HTML Browser Support
HTML Event Reference
HTML Color Reference
HTML Attribute Reference
HTML Canvas Reference
HTML SVG Reference
Google Maps Reference
CSS
CSS Reference
CSS Browser Support
CSS Selector Reference
Bootstrap 3 Reference
Bootstrap 4 Reference
W3.CSS Reference
Icon Reference
Sass Reference
JavaScript
JavaScript Reference
HTML DOM Reference
jQuery Reference
AngularJS Reference
AppML Reference
W3.JS Reference
Programming
Python Reference
Java Reference
Server Side
SQL Reference
MySQL Reference
PHP Reference
ASP Reference
XML
XML DOM Reference
XML Http Reference
XSLT Reference
XML Schema Reference
Character Sets
HTML Character Sets
HTML ASCII
HTML ANSI
HTML Windows-1252
HTML ISO-8859-1
HTML Symbols
HTML UTF-8
×
Exercises and Quizzes
Exercises
HTML Exercises
CSS Exercises
JavaScript Exercises
Python Exercises
SQL Exercises
PHP Exercises
Java Exercises
C Exercises
C++ Exercises
C# Exercises
jQuery Exercises
React.js Exercises
MySQL Exercises
Bootstrap 5 Exercises
Bootstrap 4 Exercises
Bootstrap 3 Exercises
NumPy Exercises
Pandas Exercises
SciPy Exercises
TypeScript Exercises
Excel Exercises
R Exercises
Git Exercises
Kotlin Exercises
Go Exercises
MongoDB Exercises
Quizzes
HTML Quiz
CSS Quiz
JavaScript Quiz
Python Quiz
SQL Quiz
PHP Quiz
Java Quiz
C Quiz
C++ Quiz
C# Quiz
jQuery Quiz
React.js Quiz
MySQL Quiz
Bootstrap 5 Quiz
Bootstrap 4 Quiz
Bootstrap 3 Quiz
NumPy Quiz
Pandas Quiz
SciPy Quiz
TypeScript Quiz
XML Quiz
R Quiz
Git Quiz
Kotlin Quiz
Cyber Security Quiz
Accessibility Quiz
Courses
HTML Course
CSS Course
JavaScript Course
Front End Course
Python Course
SQL Course
PHP Course
Java Course
C++ Course
C# Course
jQuery Course
React.js Course
Bootstrap 4 Course
Bootstrap 3 Course
NumPy Course
Pandas Course
TypeScript Course
XML Course
R Course
Data Analytics Course
Cyber Security Course
Accessibility Course
Certificates
HTML Certificate
CSS Certificate
JavaScript Certificate
Front End Certificate
Python Certificate
SQL Certificate
PHP Certificate
Java Certificate
C++ Certificate
C# Certificate
jQuery Certificate
React.js Certificate
MySQL Certificate
Bootstrap 5 Certificate
Bootstrap 4 Certificate
Bootstrap 3 Certificate
TypeScript Certificate
XML Certificate
Excel Certificate
Data Science Certificate
Cyber Security Certificate
Accessibility Certificate
×
Tutorials
References
Exercises
Get Certified
Upgrade
Spaces
Videos
Shop
Java
Tutorial
Java HOME
Java Intro
Java Get Started
Java Syntax
Java Output
Print Text
Print Numbers
Java Comments
Java Variables
Variables
Print Variables
Declare Multiple Variables
Identifiers
Java Data Types
Data Types
Numbers
Booleans
Characters
Non-primitive Types
Java Type Casting
Java Operators
Java Strings
Strings
Concatenation
Numbers and Strings
Special Characters
Java Math
Java Booleans
Java If...Else
If...Else
Short Hand If...Else
Java Switch
Java While Loop
Java For Loop
For Loop
For-Each Loop
Java Break/Continue
Java Arrays
Arrays
Loop Through an Array
Multidimensional Arrays
Java Methods
Java Methods
Java Method Parameters
Java Method Overloading
Java Scope
Java Recursion
Java Classes
Java OOP
Java Classes/Objects
Java Class Attributes
Java Class Methods
Java Constructors
Java Modifiers
Java Encapsulation
Java Packages / API
Java Inheritance
Java Polymorphism
Java Inner Classes
Java Abstraction
Java Interface
Java Enums
Java User Input
Java Date
Java ArrayList
Java LinkedList
Java HashMap
Java HashSet
Java Iterator
Java Wrapper Classes
Java Exceptions
Java RegEx
Java Threads
Java Lambda
Java File Handling
Java Files
Java Create/Write Files
Java Read Files
Java Delete Files
Java How To
Add Two Numbers
Count Words
Reverse a String
Java Reference
Java Keywords
abstract
boolean
break
byte
case
catch
char
class
continue
default
do
double
else
enum
extends
final
finally
float
for
if
implements
import
instanceof
int
interface
long
new
package
private
protected
public
return
short
static
super
switch
this
throw
throws
try
void
while
Java String Methods
Java Math Methods
Java Examples
Java Examples
Java Compiler
Java Exercises
Java Quiz
Java Certificate
Java
Examples
❮ Previous
Next ❯
Java Syntax
Create a simple "Hello World" program
Syntax Explained
Java Comments
Single-line comment before a line of code
Single-line comment at the end of a line of code
Multi-line comment
Comments Explained
Java Variables
Create a string variable
Create an integer variable
Create a variable without assigning the value, and assign the value later
Overwrite an existing variable value
Create a final variable (unchangeable and read-only)
Combine text and a variable on display
Add a variable to another variable
Declare many variables of the same type with a comma-separated list
Variables Explained
Java Data Types
A demonstration of different data types in Java
Create a byte type
Create a short type
Create an int type
Create a long type
Create a float type
Create a double type
Create a boolean type
Create a char type
Create a String type
Data Types Explained
Java Type Casting
Widening Casting
Narrowing Casting
Type Casting Explained
Java Operators
Addition operator
Subtraction operator
Multiplication operator
Division operator
Modulus operator
Increment operator
Decrement operator
Assignment operator
Comparison operator
Logical operator
Operators Explained
Java Strings
Create a string
Quotes inside a string
Find the length of a string
Using methods to convert strings to uppercase and lowercase
Finding a string in a string
String concatenation
If you add a number and a string, the result will be a string concatenation
Strings Explained
Java Math
Math.max(x,y) - return the highest value of x and y
Math.min(x,y) - return the lowest value of x and y
Math.sqrt(x) - return the square root of x
Math.abs(x) - return the absolute (positive) value of x
Math.random() - return a random number between 0 and 1
Math Explained
Java Booleans
Create a boolean type
Find out if an expression is true or false
Use the "equal to" operator to evaluate a boolean expression
Booleans Explained
Java If...Else (Conditions)
The if statement
The else statement
The else if statement
If...Else Explained
Java Switch
The switch statement
The switch statement with a default keyword
Switch Explained
Java Loops
While loop
Do while loop
For loop
For-each loop
Break a loop
Continue a loop
Loops Explained
Java Arrays
Create and access an array
Change an array element
Find the length of an array
Access an array
Loop through an array
Loop through an array with for-each
Multidimensional array
Loop through a multidimensional array
Arrays Explained
Java Methods
Create and call a method
Call a method multiple times
Method with parameters
Method with multiple parameters
Return value
A method with if...else
Method overloading
Recursion
Recursive function with a halting condition
Methods Explained
Java Classes and Objects
Create a class and an object of a class
Create multiple objects of a class
Accessing class attributes (variables)
Modify attributes
Override existing attribute values
Multiple attributes
Create a class method
Method with parameters
Access class methods with an object
Create a class constructor
Constructor with parameters
Classes and Objects Explained
Java Modifiers
Public class
Default class
Public attributes
Private attributes
Default attributes
Protected attributes
Final class
Abstract class with abstract methods
Modifiers Explained
Java Encapsulation
Java encapsulation (getters and setters)
Encapsulation Explained
Java Packages
Import a class from the Java API
Import a package from the Java API
Create a package
Packages Explained
Java Inheritance
Java inheritance (extends)
Java polymorphism
Inheritance Explained
Java Inner Classes
Inner class
Private inner class (error when trying to access it from an outside class)
Static inner class
Access outer class from inner class
Inner Classes Explained
Java Abstraction & Interfaces
Java abstract classes and methods
Java interface (implements)
Multiple interfaces
Interfaces Explained
Java Enums
Create an enum with a group of constants
An enum inside a class
An enum in a switch statement
Loop through an enum
Enums Explained
Java User Input
Read user input
Read user input of various types
User Input Explained
Java Dates
Display current date
Display current time
Display current date and time
Formatting date and time
Dates Explained
Java ArrayList
Create an ArrayList
Access an item in an ArrayList
Remove an item from an ArrayList
Remove all items from an ArrayList
Get the size of an ArrayList
Loop through an ArrayList
Loop through an ArrayList with for-each
Create an ArrayList that should store numbers (integers)
ArrayList Explained
Java HashMap
Create a HashMap
Access an item in a HashMap
Remove an item from a HashMap
Remove all items from a HashMap
Get the size of a HashMap
Loop through a HashMap
Create a HashMap that should store String keys and Integer values
HashMap Explained
Java HashSet
Create a HashSet and add items to it
Check if an item exists in a HashSet
Remove an item from a HashSet
Remove all items from a HashSet
Get the size of a HashSet
Loop through a HashSet
Create a HashSet that should store Integer values
HashSet Explained
Java Iterator
Getting an iterator
Looping throug a collection
Removing items from a collection
Iterator Explained
Java Wrapper Classes
Create an ArrayList that should store numbers (integers)
Create wrapper objects
Using wrapper methods
Convert wrapper objects to strings
Wrapper Classes Explained
Java Exceptions (Try...Catch)
The try...catch statement
The finally statement
The throw statement
Exceptions Explained
Java Regular Expressions
Search for the word "w3schools" in a sentence
Regular Expressions Explained
Java Threads
Running a thread by extending the thread class
Running a thread by implementing the Runnable interface
Concurrency problems
Avoid concurrency problems
Threads Explained
Java Files
Create a file
Write to a file
Read a file
Get file information
Delete a file
Files Explained
❮ Previous
Next ❯
COLOR PICKER
Get certified
by completing
a
course today!
w
3
s
c
h
o
o
l
s
C
E
R
T
I
F
I
E
D
.
2
0
2
2
Get started