Introduction to Java -
History
• Origin
• Father of Java Language
• Another name of Java
• Why JAVA ??
Java Environment Setup -
• Hardware or Software environment ( Platform )
• It supports JVM ( Java virtual machine ) , JRE ( Java Run-time environment) , JDK
(Java Development Kit)
• Platform such as Eclipse IDE , Code Block , Netbeans etc
Java Features
Java Applications
• Mobile applications
• Web development
• Gaming
• Industrial
• Buisness applications
• Desktop GUI applications
Advantages and Disadvantages
Advantages --> Disadvantages -->
. Secure Speed
. Simple
. Powerful Cost
. Portable
Multithreaded
Program Structure and Basic Syntax
Keywords
Variables and Identifiers -
• Variable is a container which contains the value or data.
• Variable restrictions or features
• Basic syntax - keyword variable = value ; e.g . int a = 5; where 'a'
is variable
• Types of variable
• 1. Local 2. Global 3. static variable
• Identifiers - It is the name of variables , class , functions etc.
• e.g. float b = 3.4f ; where 'b' is an identifier.
Comments -
• It is a symbol which is used to add any sentence or code in existing code
without execution.
• Avoiding execution of Program
• Types of Comments
• a. Single – line comment //
• b. Multi-line comment /* sentence or code */
Inputs and Outputs -
• Inputs - To take the value from user I.e. enter values in compiler.
• Syntax for User input -
• Import java.util.Scanner; // above the class
• Scanner input = new Scanner(System.in); // inside the function
• Keyword variable = input.nextKeyword(); // inside the function
• Output - To print the output on computer screen
• Syntax for output -
• System.out.println(" Sentence ");
Type Casting -
• It converts one data type into an another data type . It is also called as Type
Conversion.
• It has 2 types -
• a. Implicit Conversion ( automatic )
• b. Explicit Conversion
Java Operators -
• Operators are symbols to perform specific task on operand or variables .
• Types of operators -
• a. Arithmetic i.e. + - * /
• b. Assignment i.e. =
• c. Relational i.e. < > <= >= == !=
• d. Logical i.e. && || !
• e. Bitwise i.e. & | ^ ~ << >>
• Special operators -
• a. Ternary/Conditional - ?:
• b. instanceof
Flow Control -
Looping -
Methods or Functions -
• It is the block of code to perform specific task.
• Type of Methods -
• a. Standard library functions i.e. sqrt , pow , log , max and min etc.
• b. User – defined functions
• Syntax
• returntype functionname( parameters) = {
•
• // code
• }
• functionname(actual parameters); // function call
Java Array -
• Collection of data of same type.
• Syntax of array -
• keyword arrayname[ size] = { values } ;
• Array with new keyword -
• keyword arrayname [ ] = new keyword [ ];
• e.g. int a[ ] = { 1,1,3,4,5,6,7 } ;
• Types of array -
• a. Single dimensional i.e. one dimension
• b. Multi-dimensional i.e. two , threee etc .
File handling in Java -
File operation -
• Create a file
• Read from file
• Write to file
• Get file information
• Delete the file
Wrapper Class -
• To convert Primitive datatypes into object and object into Primitive datatypes.
• It has 2 features -
• a. autoboxing
• b. Unboxing
• e.g. int c=23; i.e. Integer c=23; // so Integer is a Wrapper class
OOP ( Object – Oriented Programming )
Class, Objects and Constructor -
object - instance of class
Syntax - classname objectname = new classname();
Class - cllections of an objects.
syntax - class classname {
access specifier
datamemeber and memeber variables
}
Constructor - special menmber function whose name same as class name.
Types of Constructors - parameterized, non-parameterized and copy
Syntax - classname(){
// code
Access specifiers and non-access specifiers -
access specifiers - It specifies accessibility to variables , data members ,
constructors etc.
Types -
. public
. private
. protected
. default
Non- access specifiers - when no access level is specified then it is used.
i.e. final , static , abstract etc.
Inheritance and it’s type -
Abstraction and Encapsulation -
Abstarction - Hiding data and showing esential data.
e.g. AC i.e. we know only on or off button but we don’t know internal details.
Encapsulation - wrapping data members and member functions togther.
e.g. Capsule i.e. combination of different contents.
Polymorphism -
Polymorphism - function is displayed in more than one form.
Types -
1. Compile time Polymorphism
2.Run-time Polymorphism
Exceptional Handling -
• The process of handling the errors is known as ' Exceptional handling.'
• Exception - error during runtime of program
• Types of exceptions -
• 1. Checked exceptions I.e. SQL and I/O exceptions
• 2. Un-checked exceptions I.e. Arithmetic and Null-pointer exceptions
• How it is handled ???
• It is handled by 5 keywords
• Try
• Catch
• Throw
• Throws
•
Collections -