Introduction To Java
Introduction To Java
Content
1. Java Intro
2. Java Variables
3. Java Data Types
4. Java Type Casting
5. Java Operators
6. Java Strings
7. Java Math
8. Java Booleans
9. Java If...Else
10. Java Switch
11. Java While Loop
12. Java For Loop
13. Java Break/Continue
14. Java Array
15. Java Classes
16. Java OOP
17. Java Classes/Objects
18. Java Class Attributes
19. Java Class Methods
20. Java Constructors
21. Java Modifiers
22. Java Encapsulation
23. Java Packages / API
24. Java Inheritance
25. Java Polymorphism
26. Java Inner Classes
27. Java Abstraction
28. Java Interface
29. Java Enums
30. Java User Input
31. Java Date
32. Java ArrayList
33. Java LinkedList
34. Java HashMap
35. Java HashSet
36. Java Iterator
37. Java Wrapper Classes
38. Java Exceptions
39. Java Thread
1. Java Intro
What is Java?
Java is a popular programming language, created in 1995.
It is used for:
Where type is one of Java's types (such as int or String), and variableName is
the name of the variable (such as x or name). The equal sign is used to
assign values to the variable.
To create a variable that should store text, look at the following example:
Example
Create a variable called name of type String and assign it the value "John":
System.out.println(name);
Try it Yourself »
To create a variable that should store a number, look at the following
example:
Example
Create a variable called myNum of type int and assign it the value 15:
System.out.println(myNum);
Try it Yourself »
You can also declare a variable without assigning the value, and assign the
value later:
Example
int myNum;
myNum = 15;
System.out.println(myNum);
Try it Yourself »
Note that if you assign a new value to an existing variable, it will overwrite
the previous value:
Example
Change the value of myNum from 15 to 20:
System.out.println(myNum);
Try it Yourself »
Final Variables
If you don't want others (or yourself) to overwrite existing values, use
the final keyword (this will declare the variable as "final" or "constant",
which means unchangeable and read-only):
Example
final int myNum = 15;
Try it Yourself »
Other Types
A demonstration of how to declare variables of other types:
Example
int myNum = 5;