JAVA Corebasics
JAVA Corebasics
Basics
• JAVA is a high level programming language
• It was developed by James Gosling. It was initially termed Oak.
• It is platform independent language
• It can be used for developing Object Oriented Programs/Applications.
• Java can be used for Procedure-Oriented Programming as well as
Object Oriented Programming.
• Java syntax is a mix-up of C, C++ Languages.
• Java has several new features which help any new programmers to
develop Real World Applications with ease.
Features
• Simple
• Object-Oriented
• Portable
• Platform-Independent
• Secured
• Multi-Threaded
• Memory Management
• Robust
• Architecture Neutral
• High-level
• Multi-Threading
Variables
• Variables are Named storage spaces to store data and access data
during the program/Application development
• Variables: Syntax:
• Syntax:
• Datatype identifier = value 1
Class_name identifier = new Class_name() 2
• Numeric
• Byte
• Short
• Int
• Long
• Float
• Double
Operators
• Arithmetic
• Relational
• Logical
• Ternary
• Bitwise
• Assignment
Operators……
• +, ++
• -, --
• /,*,%
• +=, /=
• -=, %=
• *=
• &,|,&&, ||
•!
• <<, >>
• <=, >=
• ==, !=
• <,>
•=
• ?, :
Statements
• Conditional Statements
• Iteration Statements
• Assignment Statements
Int a = 100;
String name = “COUNTRY”
Boolean flag = true
Statements…
• CONDITIONAL STATEMENTS:
• If..else
• Do… while
• While
• This is the first of the Conditional Statements in JAVA. There are three
variations of the If.. Else
• If.. Else
• Nested if
Statements…
• Do.. While
• This is the second of the Conditional Statements in JAVA. The syntax is:
• Do {
• Statement1
• Statement2
• ..
• ..
•}
• While (conditions)
Statements….
• While….
• While (condition)
•{
• Statement1
• Statement2
•…
•…
•}
Statements…
• ITERATION STATEMENTS:
• For Statement
• Switch Statement
Statements
• FOR Statement
• Syntax:
• for (I = 0; i<15;i++)
•{
• Statement1
• Statement2
• ….
•…
•}
Statements….
• SWITCH Statement
• Syntax:
• Switch (condition) {
• Case value:
• Statement1
• Case value:
• Statement1
• Statement2
• Default:
• Statement1
}
Arrays
• Arrays are user defined data types.
• Arrays are used to store more than 1 value in a single variable
• Array values are accessed using an Array Index.
• Array Index starts from 0.
• Arrays are treated as Objects in JAVA.
• Arrays are of two types
• Single dimensional
• Multi-dimensional
Arrays…
• Syntax:
• Variables
• Constructors
• Methods
• Inner Class/Classes
• Constants/Static variables
Class….
• Syntax:
Class student {
String Name
String Id
int class
Attendance() {
…
…
}
Examresults() {
…
…
}
}
Objects
• Objects are the physical representation of the Classes.
• All the real-world entities are treated as Objects, since it has been
found that any entity exhibits all/most of the other characteristics
found in most commonly found or existing Objects in the world.
• Objects are created in JAVA using the NEW keyword in the memory.
• For example, for the class Student, which we created previously, we
can create an object as below
• Class_name Reference_type = New Class_name(); --- (1)
• In this type the function doesn’t use a copy of the value of the variable.
• It refers the variable directly and uses the value within the function
statements.
• Any change in the value or updation of values within the function is
reflected in the variable directly and visible outside the function and
the statements following the function-call where the variable is
displayed or referred.
RESPONSIBILITY --EMPTY -- SLIDE
Object Oriented Programming
• Java used all the same OOP principles that were used in its previous
programming language.
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
OOPs…
• Abstraction
Principles of OOPs
• Abstraction
Principles of OOPs…..
• Encapsulation
Principles of OOPs….
• Inheritance
Principles of OOPs…..
• Polymorphism
Principles of OOPs…
• Polymorphism
Method Overloading
• This is static binding.
Method Overriding
• This is dynamic binding.
Abstract Class
Abstract Class….
• Using abstraction java programs implement only 80% of Abstraction.
Interface
• This concept is used by JAVA to implement 100% abstraction in
programs and applications developed using JAVA.
Interface….
• Syntax:
Interface….
• Syntax:
Interface….
• Example of the syntax:
Multi-threading
What is multi-tasking?
It is performing more than one process simultaneously.
It is used when there is a need to perform two or more processes
and if one process shouldn’t affect the other or all remaining processes
in the program or application.
What is multi-threading?
It is a subset of Multi-threading. It is used not in process. But in
small tasks in a program or application.
Multi-threading…
• Definition:
Multi-Threading…
• Syntax:
Multi-Threading…
• Example:
Multi-Threading…
• Interfaces or classes used for Multi-threading in JAVA.
Multi-Threading….
• Thread class and its methods used in implementing Multi-threading.
Multi-Threading…..
• Interface Runnable and its methods used in Multi-threading.
Multi-Threading….
• Synchronization:
Multi-threading
• Synchronization implementation in JAVA using as a block, method.
Packages….
Packages….
Packages….
Packages….