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

Java

Uploaded by

sithum Marasighe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java

Uploaded by

sithum Marasighe
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Getting Started with Java: A

Simple Guide
1. Install Java Development Kit (JDK):

Download the latest JDK from Oracle's official website:


https://www.oracle.com/java/technologies/downloads/
Follow the installation instructions for your operating system (Windows, macOS, or
Linux).

2. Set Up a Development Environment:

Text Editor: Choose a text editor like Notepad++, Sublime Text, or Visual Studio Code.
Integrated Development Environment (IDE): Consider using an IDE like Eclipse, IntelliJ
IDEA, or NetBeans for a more structured development experience.

3. Write Your First Java Program:

Create a new text file and name it HelloWorld.java.

Write the following code:

<!-- end list -->

Java

public class HelloWorld {

public static void

main(String[] args) {

System.out.println("Hello, World!");

Use code with caution.

4. Compile the Code:

Open a terminal or command prompt.


Navigate to the directory where you saved HelloWorld.java.
Use the javac command to compile the code:

<!-- end list -->


Bash

javac HelloWorld.java

Use code with caution.

This will create a bytecode file named HelloWorld.class.

5. Run the Program:

Use the java command to run the compiled class:

<!-- end list -->

Bash

java HelloWorld

Use code with caution.

This will output "Hello, World!" to the console.

Basic Java Concepts:

Variables: Used to store data.


Java
int age = 25;
String name = "Alice";
double pi = 3.14159;
Use code with caution.
Data Types: Different types of data, such as int, double, String, boolean, etc.
Operators: Used to perform operations on variables.
Java
int sum = 5 + 3;
int difference = 10 - 4;
int product = 2 * 6;
int quotient = 12 / 3;
Use code with caution.

Control Flow: Used to control the execution flow of a program.


Java

if (condition) {

// code to execute if the condition is


true

} else {

// code to execute if the condition is false

for (int i = 0; i < 10; i++) {

// code to execute 10 times

while (condition) {

// code to execute while the condition is true

Use code with caution.

Methods: Reusable blocks of code.

Java

public static void greet(String name) {

System.out.println("Hello, " + name + "!");

Use code with caution.

Classes and Objects: The building blocks of object-oriented programming.

Java

public class Car {

String color;

int year;
public void start() {

System.out.println("Car started.");

Use code with caution.

Additional Tips:

Practice regularly to improve your skills.

Break down complex problems into smaller, manageable steps.

Use comments to explain your code.

Test your code thoroughly.

Learn from others and online resources.

Don't be afraid to experiment and make mistakes.

You might also like