Java

Java Basics

24 lessons in this section of the Java tutorial. Work through them in order, or jump to the one you need.

  1. 1.Variables in Java

    A variable is just a named box in memory that holds a value.

  2. 2.Data Types in Java

    Java needs to know exactly what kind of data it's dealing with before it can store or process it.

  3. 3.Primitive Data Types

    Java has eight primitive data types — the most basic building blocks for storing data.

  4. 4.Non-Primitive Data Types

    Non-primitive data types — also called reference types — are everything beyond Java's eight primitives.

  5. 5.Literals

    A literal is a fixed value written directly in your source code — 42, 3.14, 'A', true, "Hello".

  6. 6.Type Casting

    Type casting is converting a value from one type to another.

  7. 7.Widening Casting

    Widening casting is the automatic conversion of a smaller data type to a larger one.

  8. 8.Narrowing Casting

    Narrowing casting converts a larger data type into a smaller one.

  9. 9.Operators

    Operators are the symbols that tell Java what to do with values — add them, compare them, combine them, assign them.

  10. 10.Arithmetic Operators

    Arithmetic operators perform mathematical operations on numeric values.

  11. 11.Relational Operators

    Relational operators compare two values and always produce a boolean result — true or false.

  12. 12.Logical Operators

    Logical operators combine boolean expressions into more complex conditions.

  13. 13.Bitwise Operators

    Bitwise operators work directly on the binary representation of integers — manipulating individual bits.

  14. 14.Assignment Operators

    Assignment operators store values into variables.

  15. 15.Unary Operators

    Unary operators take a single operand. Java has five: unary plus, unary minus, increment, decrement, and logical NOT. The increment and decrement operators have prefix…

  16. 16.Ternary Operator

    The ternary operator is Java's only three-operand operator.

  17. 17.instanceof Operator

    instanceof checks whether an object is an instance of a specific class or interface.

  18. 18.Input and Output

    Input and output (I/O) in Java is how a program communicates with the outside world — reading data from the keyboard, files, or network, and writing data to the screen…

  19. 19.Scanner Class

    The Scanner class (java.util.Scanner) is the standard way to read user input from the keyboard in Java.

  20. 20.BufferedReader

    BufferedReader wraps a Reader (typically InputStreamReader wrapping System.in or a FileReader) and adds an internal buffer that dramatically reduces the number of…

  21. 21.Console Input

    The System.console() method returns a Console object that provides direct access to the character-based console (terminal) attached to the JVM.

  22. 22.printf()

    printf() formats output using a format string containing literal text and format specifiers that are replaced with the values of subsequent arguments.

  23. 23.Escape Sequences

    Escape sequences are special character combinations beginning with a backslash that represent characters which cannot be typed directly in a string or character literal…

  24. 24.Command Line Arguments

    Command line arguments are values passed to a Java program when it is launched from the terminal.