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

Java Fundaments

Uploaded by

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

Java Fundaments

Uploaded by

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

Java Development Kit(JDK):

*JDK is a tool used to develop a Java application and has a compiler(javac).

Java Runtime Environment(JRE):


*JRE is a software that provides the class libraries and other resources that a
Java program needs to run.

Java Virtual Machine(JVM):


*JVM is a virtual machine that allows a computer to run a Java program.
Note: A virtual machine (VM) is a digital version of a physical computer.

--JDK,JRE & JVM image--

Java compiler:
The compiler converts the Java code into a byte code.

compile - javac ProgramName.java

Java is Platform-independent ~
The Byte code(Intermediate level language) is platform independent. This byte
code is then fed into JVM of the respective OS and gets converted into binary
code(Machine level language). Hence, Java is WORA(Write Once Run Anywhere).

run - java ProgramName

VARIABLES:
containers for storing data.
<<DataType variableName = value;>>

Java is a statically-typed/strongly-typed language ~


The data type of each variable is known at compile-time.

Primitive Data Types:


These are the basic built-in data types.
1.Integer - stores whole numbers.
byte, short, int, long(l)
2.Float - stores decimal numbers.
float(f),double
3.Boolean - stores true or false.
Boolean
4.Character - stores a character.
char('')

Reference Data Types:


Reference type variables store the address(refer) of another variable(object).

OPERATORS:
Operators are used to perform operations on operands.

1.Arithmetic Operators
+ : Addition
- : Subtraction
* : Multiplication
/ : Division
% : Modulo Division(returns remainder)

2.Assignment Operators
= , += , -=, *= , /= , %=
3.Comparison Operators
== : equal to
!= : not equal to
> : greater than
>= : greater than or equal to
< : lesser than
<= : lesser than or equal to

4.Logical Operators
&& : logical AND
|| : logical OR
! : logical NOT

5.Ternary Operator
variableName = condition ? true-statement : false-statement ;

6.Increment and Decrement Operators


pre-increment/pre-decrement : ++variableName / --variableName
~ process after increment/decrement

post-increment/post-decrement : variableName++ / variableName--


~ process before increment/decrement

CONDITIONAL STATEMENTS:

1.if statement
if(condition) {
//code to be executed if condition is true;
}

2.if else statement


if(condition) {
//code to be executed if condition is true;
}
else {
//code to be executed if condition is false;
}

3.if else if statement


if(condition-1) {
//code to be executed if condition-1 is true;
}
else if(condition-2) {
//code to be executed if condition-2 is true;
}
/*optional
else {
//code to be executed if none of the conditions is true;
}
*/

4.switch statement
switch(expression) {
case x:
{
//code
break;
}
case y:
{
//code
break;
}
case z:
{
//code
break;
}
default:
{
//code
}
}

LOOPS:

1.for loop
for(initialisation;condition;alteration) {
//code
}

2.while loop
initialisation;
while(condition) {
//code
alteration;
}

3.do while loop


initialisation;
do {
//code
alteration;
}
while(condition);

4.for-each loop
used to traverse through a collection of elements.
for(dataType variableName : refVariableName) {
//code
}

*break : breaks out of a loop.


*continue : it ends the current iteration in a loop and continues to the next
iteration.

USER INPUT:
Scanner:
It is used to get user input.

<<import java.util.Scanner;
/////////////////////////
Scanner refVariableName = new Scanner(System.in);
dataType variableName = refVariableName.methodName();>>

*close it after usage to prevent resource leakage.


<<refVariableName.close();>>
SYSTEM OUTPUT:
It is used to print output on the console.

<<System.out.println(args);>>

METHODS:
A method is a block of code used to perform certain actions.

<< returnType methodName(parameters) {


//method body
}

method call:
methodName(arguments);

parameters: values inside a method.


arguments : values passed to a method.

*Java is strictly pass-by-value.i.e.only a copy of the argument is passed and not


the actual argument.

Local variables:
variables inside a method.

You might also like