0% found this document useful (0 votes)
19 views12 pages

Introduction To Java

Uploaded by

KRISHNA KUMAR .G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views12 pages

Introduction To Java

Uploaded by

KRISHNA KUMAR .G
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INTRODUCTION TO JAVA

What is java
Java is a high-level, object-oriented programming language used to build software applications,
websites, mobile apps, and enterprise systems.
It was developed by Sun Microsystems in 1995 (now owned by Oracle Corporation).

Where is java used


Web applications (Spring, JSP)
Android app development
Banking & financial systems
Desktop applications
Enterprise software
Java code

public class Main {


public static void main(String[] args) {
[Link]("Hello World");
}
}

How Java Works


you write code in a .java file. - Format
Java compiler converts it into bytecode.
JVM runs that bytecode on any system
How to install java on your pc
Step 1: Download Java (JDK)
Step 2: Run the Installer
Step 3: Verify Installation
java –version
javac -version

Install VS Code for Java


Install Java Extension Pack
How does code works
we created a Java file called [Link], and we used the following code to print "Hello World" to the screen

public class Main {


public static void main(String[] args) {
[Link]("Hello World");
}
}

Every line of code that runs in Java must be inside a class. The class name should always start with an uppercase first
letter. In our example, we named the class Main

Java is case-sensitive. MyClass and myclass would be treated as two completely different names.

The main() method is required in every Java program. It is where the program starts running
public static void main(String[] args)
Any code placed inside the main() method will be executed
[Link]()
Inside the main() method, we can use the println() method to print a line of text to the screen

public static void main(String[] args) {


[Link]("Hello World");
}

It is important that you end the statement with a semicolon ;.


If you forget the semicolon (;), an error will occur and the program will not run

[Link]("Java is fun!")
error: ';' expected
Variables

What is variables
A variable is a container that stores data

Different types of variables

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

To create a variable
Choose a type (like int or String)
Give the variable a name (like x, age, or name)
Optionally assign it a value using =
Syntax
type variableName = value;
Example
Create a variable called name of type String and assign it the value "John".
Then we use println() to print the name variable

String name = "John";


[Link](name);

Create a variable called myNum of type int and assign it the value 15
int myNum = 15;
[Link](myNum);
Data types
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99f; // Floating point number
char myLetter = 'D'; // Character
boolean myBool = true; // Boolean
String myText = "Hello"; // String

Data Type Description


byte Stores whole numbers from -128 to 127
short Stores whole numbers from -32,768 to 32,767
int Stores whole numbers from -2,147,483,648 to 2,147,483,647
long Stores whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

float Stores fractional numbers. Sufficient for storing 6 to 7 decimal digits


double Stores fractional numbers. Sufficient for storing 15 to 16 decimal digits
boolean Stores true or false values
char Stores a single character/letter or ASCII values
Data Type Variable
Defines type of data Stores the data
Example: int, String Example: age, name
Decides memory size Holds actual value
Cannot store value alone Must have a data type

Eg
double price = 99.99;

double → Data type (decimal number)

price → Variable

99.99 → Value

You might also like