0% found this document useful (0 votes)
7 views

Introduction To Java

The document is an introduction to Java, covering its history, uses, and advantages. It explains Java variables, including their types, declaration, and the concept of final variables. The document serves as a foundational guide for understanding Java programming concepts and syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Introduction To Java

The document is an introduction to Java, covering its history, uses, and advantages. It explains Java variables, including their types, declaration, and the concept of final variables. The document serves as a foundational guide for understanding Java programming concepts and syntax.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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 owned by Oracle, and more than 3 billion devices run Java.

It is used for:

 Mobile applications (specially Android apps)


 Desktop applications
 Web applications
 Web servers and application servers
 Games
 Database connection
 And much, much more!

Why Use Java?


 Java works on different platforms (Windows, Mac, Linux, Raspberry Pi,
etc.)
 It is one of the most popular programming language in the world
 It has a large demand in the current job market
 It is easy to learn and simple to use
 It is open-source and free
 It is secure, fast and powerful
 It has a huge community support (tens of millions of developers)
 Java is an object oriented language which gives a clear structure to
programs and allows code to be reused, lowering development costs
 As Java is close to C++ and C#, it makes it easy for programmers to
switch to Java or vice versa
2. Java Variable
3. Java Data Types
4. s
Java Variables
Variables are containers for storing data values.

In Java, there are different types of variables, for example:

 String - stores text, such as "Hello". String values are surrounded by


double quotes
 int - stores integers (whole numbers), without decimals, such as 123
or -123
 float - stores floating point numbers, with decimals, such as 19.99 or -
19.99
 char - stores single characters, such as 'a' or 'B'. Char values are
surrounded by single quotes
 boolean - stores values with two states: true or false

Declaring (Creating) Variables


To create a variable, you must specify the type and assign it a value:

SyntaxGet your own Java Server


type variableName = value;

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":

String name = "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:

int myNum = 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:

int myNum = 15;

myNum = 20; // myNum is now 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;

myNum = 20; // will generate an error: cannot assign a value to


a final variable

Try it Yourself »

Other Types
A demonstration of how to declare variables of other types:

Example
int myNum = 5;

float myFloatNum = 5.99f;

char myLetter = 'D';

boolean myBool = true;

String myText = "Hello";

You might also like