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

Introduction To Java Programming

To write a Java program: 1. Open Eclipse, create a new Java project and class; 2. Write the program code within the class, including using variables to store values, operators for computations, and methods like println() to output results; 3. Run the program to test it works as expected.

Uploaded by

Hamdy Amin
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)
27 views

Introduction To Java Programming

To write a Java program: 1. Open Eclipse, create a new Java project and class; 2. Write the program code within the class, including using variables to store values, operators for computations, and methods like println() to output results; 3. Run the program to test it works as expected.

Uploaded by

Hamdy Amin
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
You are on page 1/ 11

Java Programming Language

How to write a Java program

Open Eclipse
File> New> Java Project>
Write Project Name
Right Click on src>New>class
Write a name for the class
Write the program
Run
Variables

Named location that stores a value of one particular type.

Form:
TYPE NAME;
Example:
String foo;
Types

Kinds of values that can be stored and manipulated.

boolean: Truth value (true or false).


int: Integer (0, 1, -47).
double: Real number (3.14, 1.0, -2.1).
String: Text (hello, example).
String a = a;
String b = letter b; a = letter a;
String c = a + and + b;

\n new line, \t tab


Operators

Symbols that perform simple computations

Assignment: =
Addition: +
Subtraction: -
Multiplication: *
Division: /
Order of Operations

Follows standard math rules:

1. Parentheses
2. Multiplication and division
3. Addition and subtraction

double x = 3 / 2 + 1; // x = 2.0
double y = 3 / (2 + 1); // y = 1.0
First Program
public class HelloWorld
{

public static void main(String[] args)


{
System.out.println("Hello world.");
System.out.println("Line Number2");

}
}
Second Program

public class Hello2


{
public static void main(String[] arguments)
{
System.out.println("Hello world.");
System.out.println("Line number 2");
}
}
class Hello3
{
public static void main(String[] arguments)
{
String foo = "Al Qassim University";
System.out.println(foo);
foo = "Something else";
System.out.println(foo);
}
}
public class DoMath
{

public static void main(String[] arguments)


{
double score = 1.0 + 2.0 * 3.0;
System.out.println(score);
score = score / 2.0;
System.out.println(score);
}
}
public class DoMath2
{

public static void main(String[] args)


{

double score = 1+2*3;


System.out.println(score);

double copy=score;
System.out.println(copy);
System.out.println(score);

}
}
public class divide1
{

public static void main(String[] args)


{

double a = 5.0/2.0; // a = 2.5


System.out.println(a);
int b = 4/2; // b = 2
System.out.println(b);
int c = 5/2; // c = 2
System.out.println(c);
Double d=5/2; // d=2.0
System.out.println(d);
}

You might also like