0% found this document useful (0 votes)
9 views27 pages

Introduction To J

The document serves as an introduction to Java programming, covering essential topics such as identifiers, data types, operators, control statements, and object-oriented concepts like inheritance and interfaces. It outlines the rules for creating valid identifiers and lists Java's reserved keywords. Additionally, it provides examples of various data types, operators, and control structures used in Java programming.

Uploaded by

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

Introduction To J

The document serves as an introduction to Java programming, covering essential topics such as identifiers, data types, operators, control statements, and object-oriented concepts like inheritance and interfaces. It outlines the rules for creating valid identifiers and lists Java's reserved keywords. Additionally, it provides examples of various data types, operators, and control structures used in Java programming.

Uploaded by

asmalubnashaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Introduction

to JAVA
DR. RAJASHRI JOSHI
PROGRAMMING BASICS
 Identifiers
 Datatypes
 Operators
 Control statements
 Loop
 Arrays
 Inheritance in JAVA
 Multilevel Hierarchy
 Method overriding
 Abstract classes
 Final classes
Identifiers
Identifiers in Java are symbolic names used for identification.

They can be a class name, variable name, method name, package name, constant name, and more.

Rules
 A valid identifier must have characters [A-Z] or [a-z] or numbers [0-9], and underscore (_) or a dollar sign
($).
 Must start with character.

 An identifier should be of length 4-15 letters only. However, there is no limit on its length. But, it is good
to follow the standard conventions.
 Do not use the Java reserved keywords as an identifier

 An identifier should not be any query language keywords such as SELECT, FROM, COUNT etc
Reserved words
Reserved keywords are predefined words, which are reserved for any functionality or meaning.
There are 53 reserved words in Java.

abstract continue for protected transient


Assert Default transient public Try
Boolean Do If Static throws
break double implements strictfp Package
byte else import super Private
case enum Interface Short switch
Catch Extends instanceof return void
Char Final Int synchronized volatile
class finally long throw Date
float Native This while
Datatypes
bOOLEAN
class BooleanDataTypes else
{ {
public static void main(String args[]) { System.out.println("Boolean value is
False");
boolean var1 = true;
}
if (var1 == true) //checks if the value is
true or false }
{ }
System.out.println("Boolean value is
True");
}
cHAR
class CharDataType {
public static void main(String[] args) {
char var1 = 'A';
char var2 = 'd';
System.out.println(var1);
System.out.println(var2);
}
}
BYTE/INT/SHORT/LONG
class IntegerDataTypes System.out.println("The long variable is " + l);

{ }

public static void main(String[] args) { }

int a = 10;

short s = 2;

byte b = 6;

long l = 125362133223l;

System.out.println("The integer variable is " + a + '\n');

System.out.println("The short variable is " + s + '\n');

System.out.println("The byte variable is " + b + '\n');


FLOAT/DOUBLE
class FloatDataTypes
{
public static void main(String args[]) {
float f = 65.20298f;
double d = 876.765d;
System.out.println("The float variable is " + f);
System.out.println("The double variable is " + d);
}
}
Data Type Default Value Default size Range (from minimum to maximium)

byte 0 1 byte or 8 bits -128 to 127

short 0 2 bytes or 16 bits -32,768 to 32,767

int 0 4 bytes or 32 bits -2,147,483,648 to 2,147,483,647

long 0 8 bytes or 64 bits -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

float 0.0f 4 bytes or 32 bits 1.4e-045 to 3.4e+038

double 0.0d 8 bytes or 64 bits 4.9e-324 to 1.8e+308

char ‘\u0000’ 2 bytes or 16 bits 0 to 65536

boolean FALSE 1 byte or 2 bytes 0 or 1


ARRAY
int Array_Name = new int[7];
STRING
class Main {
public static void main(String[] args) {
// create strings
String S1 = "Java String Data type";
// print strings
System.out.println(S1);
}
}
CLASS

Public class classname()

MEMBER VARIBLES;

MEMBER FUNCTIONS()

object creation

CLASSNAME OBJNAME=NEW CLASSNAME();


Interface An interface is declared like a class. The key difference is that the interface
contains abstract methods by default; they have nobody.

interface printable { A1 obj = new A1();

void print(); obj.print();

} }

class A1 implements printable { }

public void print()

System.out.println("Hello");

public static void main(String args[]) {


enum
enum Level {
LOW,
MEDIUM,
HIGH
}
Operators
1. Arithmetic operators
2. Relational operators
3. Logical operators
4. Assignment operators
5. Increment and decrement operators
6. Conditional operators
7. Bitwise operators
8. Special operators
Arithmetic operators
Operator Description Example

+ Addition - Adds values on either side of the operator A + B will give 30

Subtraction - Subtracts right hand operand from left hand


- A - B will give -10
operand

* Multiplication - Multiplies values on either side of the operator A * B will give 200

/ Division - Divides left hand operand by right hand operand B / A will give 2

Modulus - Divides left hand operand by right hand B % A will give 0


%
operand and returns remainder
Relational operators

Operator Meaning
< Is less than
<= Is less than or equal to
> Is greater than
>= Is greater than or equal to
== Is equal to
!= Is not equal to
Logical operators

Operator Meaning
&& logical AND

|| logical OR
! logical NOT
Assignment operator
v op= exp;

Statement with simple Statement with


assignment operator shorthand operator

a=a+1 a +=1
a=a–1 a-=1
a = a*(n+1) a *= n+1
a = a/(n+1) a /= n+1
a = a%b a %= b
INCREMENT AND
DECREMENT OPERATORS conditional OPERATORS

++ or --
expl? exp2: exp3
if (a > b)
m=5 x = a;

else
x = b;
y=m++

or X=(a>b)?a:b
y=++m
BITWISE OPERATORS
Operator Meaning
& bitwise AND

! bitwise OR

^ bitwise exclusive OR
~ one's complement
<< shift left

>> shift right

>>> shift right with zero fill


SPECIAL OPERATORS
Instanceof
class Simple1

public static void main(String args[])

Simple1 s=new Simple1();

System.out.println(s instanceof Simple1); //true

Dot Operator
personl.age // Reference to the variable age

person1.salary ()
Control statements
Conditional Statement
If

If-else

If-elseif-else(Elseif Ladder)

Switch case

Looping Statement
While

Do-while

For

Foreach
THANK YOU!!

You might also like