Introduction To Java Programming
Introduction To Java Programming
export JAVA_HOME=/Library/Java/Home
How to compile and run the above program
1. Open a text editor, like Notepad on windows and TextEdit on
Mac. Copy the above program and paste it in the text editor.
2. Save the file as FirstJavaProgram.java. In our program, the
public class name is FirstJavaProgram, that’s why our file
name should be FirstJavaProgram.java.
3. In this step, we will compile the program. For this,
open command prompt (cmd) on Windows, if you
are Mac OS then open Terminal.
javac FirstJavaProgram.java
Variables in Java
How to Declare a variable in Java
To declare a variable follow this syntax:
• data_type variable_name = value;
Primitive Data types
Operators in Java
Types of Operator in Java
1. Basic Arithmetic Operators
2. Assignment Operators
3. Auto-increment and Auto-decrement Operators
4. Logical Operators
5. Comparison (relational) operators
6. Bitwise Operators
7. Ternary Operator
Basic Arithmetic Operators
• Basic arithmetic operators are: +, -, *, /, %
• + is for addition.
• – is for subtraction.
• * is for multiplication.
• % is for modulo.
Example
public class ArithmeticOperatorDemo {
public static void main(String args[]) {
int num1 = 100;
int num2 = 20;