SlideShare uma empresa Scribd logo
1 de 18
JAVA
Java programming language was originally developed by Sun Microsystems.
Java is guaranteed to be Write Once, Run Anywhere.
Java is not a programming language but also a platform.
Java files are written with “.java” extension.
STRUCTURE:
class filename {
public static void main(String[]args)//main function
{
____________________________
}
}
Main function:
public-it declares that the main method is publicaly accessible to other classes.
static: it declares that the main method can be invoked without creating an
instance of the class.
void: it declares that the main method does not return any value.
main- it defines the name of the method.
String [] args- it defines a parameter to main method which will contain any
command line options passed by the user when invoking the program.
SCANNER CLASS : import java.util.Scanner;
Scanner input = new Scanner(System.in);
Datatype object = input.nextDatatype();
PRINTING VALUE: System.out.println("______");
MATH FUNCTIONS: import.java.lang.Math;
“A” is a string & ‘A’ is a character.
Any positive integer b/w 0 to FFFF in hexadecimal can be cast in character
implicity.
To convert a string to a number we use-
int intValue = Integer.parseInt(intString);
To convert a string into a double value, use the Double.parseDouble method, as
follows:
double doubleValue = Double.parseDouble(doubleString);
A named constant is declared by using the keyword final.
DIFFERENCE B/W C/C++ & JAVA:
1. Java does not support preprocessing.
2. Total code of java is written in class.
3. Java does not support global variable. Every variable should declare in
class.
4. Java supports wrapper class.
5. Memory allocation is done by java compiler (using garbage collector).
6. Java programs are platform independent.
7. Java does not support structure, union & pointer.
8. It runs in a protected virtual machine
HOW TO RUN A PROGRAM:
1. Write a code in notepad & save it as name.java
2. For compiling:
C:  javac name.java
C: java classname
For applets: we write 2 codes: name.java & name.html {both should lie in
the same directory.}
C:  javac name.java
C:  appletviewer name.html
IMPORTANT TERMS:
Object oriented programming simplifies the software development and
maintenance by providing some concepts:
Object [Any entity that has state and behavior]
Class [Collection of objects]{ A class is a set of objects with similar
properties (attributes), common behaviour (operations), and common link to
other objects.}
Inheritance [When one object acquires all the properties and behaviours of
parent object i.e. known as inheritance. It provides code reusability. It is used
to achieve runtime polymorphism.]
Polymorphism [When one task is performed by different ways i.e. known as
polymorphism. In java, we use method overloading and method overriding to
achieve polymorphism.
Polymorphism means that a variable of a supertype can refer to a subtype
object. ]
Abstraction [Hiding internal details and showing functionality is known as
abstraction. In java, we use abstract class and interface to achieve
abstraction]
Encapsulation [Binding (or wrapping) code and data together into a single unit
is known as encapsulation]
Interface: it is like a class except that an interface contains methods with no
body & static final fields. Interface alone is of no use, it should be implemented
by some class.
Package: it is a container of related classes & interfaces. A package is like a
folder in a file system.
Wrapper class: primitive data type is written in classes for security.
Message parsing: it is a mechanism by which objects interchange among other
object.
Bytecodes: these are a set of instructions that looks a lot like some machine
codes, but that is not specific to any one processor
Swing: it has the properties similar to AWT. It is used to enhance the look of
the applet.
Thread: a thread is a light weight sub process, a smallest unit of processing. It
is separate path of execution.
Abstract class: it is used for inheritance purpose only. An abstract class may
have abstract method. The method that have no body are abstract class.
Dynamic binding: A method can be implemented in several classes along the
inheritance chain.
Final keyword: it is used with context to class, method & reference or primitive
type variable declaration.
Finalize keyword; a finalize method is a protected method of java.lang.Object.
this method is called by the garbage collector on object which is least recently
used and there are no references made to the object for a long time.
Implicit casting: the process of assigning one entity to another without any
transporation guidance to the compiler. This type of is not permitted
transportations & may not workout for all applicaton types. Ex;
Int i=4000;
Long h=i;
Explicit casting: the process in which the complier are specifically informed to
about transforming the object. Ex;
Long ln=700.20;
t=(int)ln;
string tokenizer class: it takes an input stream & parses it into “tokens” ,
allowing the tokens to be read one at a time.
StringTokenizer sTokenize = new StringTokenizer(s,” “);
while(sTokenizer.hasMoreTokens) {
Java is:
 Object Oriented: In Java, everything is an Object. Java can be easily
extended since it is based on the Object model.
 Platform independent: Unlike many other programming languages including
C and C++, when Java is compiled, it is not compiled into platform specific
machine, rather into platform independent byte code. This byte code is
distributed over the web and interpreted by virtual Machine (JVM) on
whichever platform it is being run.
 Simple: Java is designed to be easy to learn. If you understand the basic
concept of OOP, Java would be easy to master.
 Secure: With Java's secure feature, it enables to develop virus-free,
tamper-free systems. Authentication techniques are based on public-key
encryption.
 Architectural-neutral: Java compiler generates an architecture-neutral
object file format, which makes the compiled code to be executable on
many processors, with the presence of Java runtime system.
 Robust: Java makes an effort to eliminate error prone situations by
emphasizing mainly on compile time error checking and runtime checking.
 Multithreaded: With Java's multithreaded feature, it is possible to write
programs that can do many tasks simultaneously. This design feature
allows developers to construct smoothly running interactive applications.
 Interpreted: Java byte code is translated on the fly to native machine
instructions and is not stored anywhere. The development process is more
rapid and analytical since the linking is an incremental and lightweight
process.
 High Performance: With the use of Just-In-Time compilers, Java enables
high performance.
 Distributed: Java is designed for the distributed environment of the
internet.
 Dynamic: Java programs can carry extensive amount of run-time
information that can be used to verify and resolve accesses to objects on
run-time. It can be defined as a collection of objects that communicate
via invoking each other's methods.
 Object - Objects have states and behaviours. Example: A dog has states-
color, name, breed as well as behaviours -wagging, barking, eating. An
object is an instance of a class. An object is a collection of data members
& methods. Data members are called as variables, methods are called as
functions.
 Class - A class can be defined as a template/blue print that describes the
behaviours/states that object of its type support.
 Methods - A method is basically a behaviour. A class can contain many
methods. It is in methods where the logics are written, data is
manipulated and all the actions are executed.
 Instance Variables - Each object has its unique set of instance variables.
An object's state is created by the values assigned to these instance
variables.
 Instance variables are declared Inside a class but not Inside a method
 Methods must have a return type, but constructors cannot have a return
type.
 Constructors are not inherited.
 Three ways to get rid of an object's reference:
1. The reference is assigned another object
2. The reference is explicitly set to null
3. the reference goes out of scope permanently
SOME IMPORTANT POINTS TO REMEMBER-
 Case Sensitivity - Java is case sensitive, which means identifier Hello and
hello would have different meaning in Java.
 Class Names - For all class names, the first letter should be in Upper
Case. If several words are used to form a name of the class, each inner
word's first letter should be in Upper Case. Example class
MyFirstJavaClass
 Method Names - All method names should start with a Lower Case letter.
If several words are used to form the name of the method, then each
inner word's first letter should be in Upper Case. Example public void
myMethodName()
 Program File Name - Name of the program file should exactly match the
class name. When saving the file, you should save it using the class name &
append '.java' to the end of the name (if the file name and the class name
do not match your program will not compile). Example : Assume
'MyFirstJavaProgram' is the class name, then the file should be saved
as'MyFirstJavaProgram.java'
 public static void main(String args[]) - Java program processing starts
from the main() method, which is a mandatory part of every Java program.
 The Java compiler does not require import declarations in a Java source-
code file if the fully qualified class name is specified every time a class
name is used in the source code.Most Java programmers prefer to use
import declarations.
IMPORTANT JAVA CONCEPTS:
JAVA ARRAYS:
Arrays are objects that store multiple variables of the same type. However, an
array itself is an object on the heap.
It is a collection of similar or homogeneous values.
Int a[]= new int[5]
JAVA ENUMS:
Enums restrict a variable to have one of only a few predefined values. The
values in this enumerated list are called enums. With the use of enums, it is
possible to reduce the number of bugs in your code. Enums can be declared as
their own or inside a class. Methods, variables, constructors can be defined
inside enums as well.
Java supports the following fundamental concepts:
 Polymorphism
 Inheritance
 Encapsulation
 Abstraction
 Classes
 Objects
 Instance
 Method
 Message Parsing
Java does NOT support-
 Header files
 #defines
 Typedefs or structs
 Pointer arithmetic
 Multiple inheritance of classes {but can be indirectly applied by using ‘n’
interfaces.}
 General functions(only methods are supported)
 Pointer, structure & union
Java Development kit (JDK) – The JDK comes with a set of tools that are
used for developing and running Java program. It includes:
1. Appletviewer( It is used for viewing the applet)
2. Javac(It is a Java Compiler)
3. Java(It is a java interpreter)
4. Javap(Java diassembler,which convert byte code into program description)
5. Javah(It is for java C header files)
6. Javadoc(It is for creating HTML document)
7. Jdb(It is Java debugger)
JAVA IDENTIFIERS:
All Java components require names. Names used for classes, variables and
methods are called identifiers. In Java, there are several points to remember
about identifiers. They are as follows:
All identifiers should begin with a letter (A to Z or a to z), currency character
($) or an underscore (_).
After the first character identifiers can have any combination of characters.
A key word cannot be used as an identifier.
Most importantly identifiers are case sensitive.
Examples of legal identifiers: age, $salary, _value, __1_value
Examples of illegal identifiers: 123abc, -salary
JAVA MODIFIERS:
It is possible to modify classes, methods, etc., by using modifiers. There are
two categories of modifiers:
Access Modifiers: default, public , protected, private
Non-access Modifiers: final, abstract, strictfp
ABSTRACT CLASS: if a class contains any function with no body the & such a
function is known as abstract function & that function must be proceeded by
abstract method
JAVA VARIABLES:
 Local Variables
 Class Variables (Static Variables)
 Instance Variables (Non-static variables)
INHERITANCE:
It is a process of reusability. The existing members of a class can be
accessed in a subclass.
I.e. classes can be derived from classes.
There are 3 types:
 Simple level
 Multi level
 Hirerarical
In java multiple inheritance cannot be supported for class structure or
hierarchy. But we are having an optional technique to implement multiple
inheritance. By implementing ‘n’ no .of interface, we can actually implement
multiple inheritance property indirectly. We have to define abstract methods
corresponding to each & every interfaces in the class.
HOW TO USE CONSTRUCTORS IN INHERITANCE?
In inheritance we are always creating objects for subclasses.
Therefore, whatever values required for sub & superclasses should be passed
to subclass constructor, from there we can pass to superclass by using a
keyword called “super”. It should be the first statement in subclass
constructor.
POLYMORPHISM:
Creating a function with same in more than one class is a concept of
polymorphism.
Dynamic Method Dispatch (Runtime polymorphism) is a process in which a call
to an overridden method is resolved at runtime rather than compile-time.
In other words, an overridden method is called through the reference
variable of a superclass The determination of the method to be called is
based on the object being referred to by the reference variable.
Void area(int I, int j) {
Int area;
Area=i*j;
}
Void area(int i)
{
Int area;
Area=i*I;
}
Same name action different
INTERFACES:
An interface can be defined as a contract between objects on how to
communicate with each other. An interface defines the methods, a deriving
class (subclass) should use. But the implementation of the methods is totally
up to the subclass.
Why use Java interface?
It is used to achieve fully abstraction.
By interface, we can support the functionality of multiple inheritance.
It can be used to achieve loose coupling.
JAVA PACKAGE:
A java package is a group of similar types of classes, interfaces and sub-
packages.
Package in java can be categorized in two form, built-in package and user-
defined package.
There are many built-in packages such as java, lang, awt, javax, swing, net, io,
util, sql etc.
It is used in Java in order to prevent naming conflicts, to control access, to
make searching/locating and usage of classes, interfaces, enumerations and
annotations easier, etc.
The default package in java is java.lang.
THREADS:
By using threads we can execute more programs simultaneously.
Imp. Methods: start(), stop(), sleep(), suspend(), resume()
 New born state: when we create a thread
 Runnable state: start
 Running state : run() exection
 Blocked state: wait(), sleep()
 Dead/finished state: work is over
Java is the only programing language that supports multi-threading.
SETTING PIRORITES FOR THEREADS: Generally all threads have equal
priority i.e normal priority(5).
{highest priority= 10 & least priority= 1}
The thread which is having highest priority will be completing first even if it
starts late & the thread with least priority will complete at the last even if
it starts early.
Deadlock: two or more threads are blocked forever, this situation arises
with atleast 2 threads or more resources.
MULTITHREADING:
execution of multiple threads can be done simultaneously as we create
multiple child thread corresponding to single parent thread.
If the priority of the thread is same, but if the priority gets changed then
the execution sequence might differ, it depends upon the O.S.
It does not block the user.
Many operations can be performed together, so it saves time.
Cost of communication between the threads is low.
IsAlive() method: reuturns the status of the thread(true or false) i.e
whether a thread is alive or dead.
Join() method: it will wait till the program execution will get over. i.e it waits
upto the exection of all threads corresponding to a thread group.
ADAVNTAGES OF MULTITHREADING:
1. Reduces the computation time.
2. Improves performance of an application.
3. Threads distribute the same address space so it saves the memory.
4. Context switching between threads is usually less costly than between
processes.
5. Cost of communication between threads is comparatively low
THREAD SYNCRONIZATION: When we start two or more threads within a
program, there may be a situation when multiple threads try to access the same
resource and finally they can produce unforeseen result due to concurrency
issue.
The general form of the synchronized statement:
synchronized(objectidentifier) {
}
objectidentifier is a reference to an object whose lock associates with the
monitor that the synchronized statement represents
DEADLOCK: It is a programming situation where 2 or more threads are blocked
forever, this situation arises with atleast 2 or more resources.
This arises when a thread wants some information from another thread, which
is already in waiting state, then the thread goes in waiting state. So deadlock
occours.
INTERFACES: As java does not support multiple inheritance, interfaces can
be used as an alternative. In interface, whatever variables are declared are
treated as final members i.e constants.
In interface, we can only make function declaration. Body can be included as
per the necessity of the class. The class is called in another using extends
keyword. A interfaced is called using implements.
an interface is different from a class in several ways, including:
t.
in an interface must be declared both static and final.
ces.
An interface is similar to a class in the following ways:
the interface matching the name of the file.
an interface appears in a .class file.
be in a directory structure that matches the package name.
JAVA OVERRIDING: The benefit of overriding is: ability to define a
behavior that's specific to the subclass type which means a subclass can
implement a parent class method based on its requirement. In object-
oriented terms, overriding means to override the functionality of an existing
method.
FILE CLASS: Using this we can display total files & directories.
A.W.T
{ABSTRACT WINDOW TOOLKIT}
Using this we can create windows in java.
APPLET:
Applets do not need a main( ) method.
 Applets must be run under an applet viewer or a Java-compatible browser.
 User I/O is not accomplished with Java’s stream I/O classes. Instead,
applets use the interface provided by the AWT or Swing.
 Applets are small programs.
 The java.applet package is the smallest package in Java API(Application
Programming Interface).
Lifecycle of applet:
 Init : born/ initialization
 Start : running
 Stop: idle
 Destroy: dead
init() : This method is used for whatever initializations are needed for your
applet. Applets can have a default constructor, but it is better to perform all
initializations in the init method instead of the default constructor.
start() : This method is automatically called after Java calls the init method. If
this method is overwritten, code that needs to be executed every time that
the user visits the browser page that contains this applet.
stop() : This method is automatically called when the user moves off the page
where the applet sits. If your applet doesn't perform animation, play audio
files, or perform calculations in a thread, you don't usually need to use this
method.
destroy(): Java calls this method when the browser shuts down
public void paint(Graphics g): is used to paint the Applet. It provides Graphics
class object that can be used for drawing oval, rectangle, arc etc.
JVM:
Java Virtual Machine: it is an abstract machine.
It performs following main tasks:
Loads code
Verifies code
Executes code
Provides runtime environment
It is platform dependent.
JRE:
Java Runtime Environment: It contains set of libraries + other files that
JVM uses at runtime.
JDK:
Java Development Kit: It physically exists. It contains JRE + development
tools.
METHOD OVERLOADING: If a class have multiple methods by same name but
different parameters, it is known as Method Overloading.
If we have to perform only one operation, having same name of the methods
increases the readability of the program.
Advantage: Method overloading increases the readability of the program.
METHOD OVERRIDING:
If subclass has the same method as declared in the parent class, it is known as
method overriding.
Rules:
 Method must have same name as in the parent class.
 Method must have same parameter as in the parent class.
 Must have inheritance.
It is used for runtime polymorphism.
It is used to provide specific implementation of a method that is already
provided by super class.
OVERLOADING VS OVERRIDING:
Overloading means to define multiple methods with the same name but
different signatures. Overriding means to provide a new implementation
for a method in the subclass.
EXCEPTION HANDLING:
An exception is nothing but a runtime error. When a runtime error occurs,
program gets terminated abnormally.
Exception handing means handling runtime errors. When an exception occurs,
the JRE creates a corresponding exception class object & throws it to the
program. If we want to handle it then we have to catch it.
Keywords used: try, catch, throw, throws, finally
Examples: dividing an integer with zero, giving an invalid input, reading from a
file which is not available.
Types:
Checked [Built in exceptions example: ArithmeticException,
ArrayIndexOutOfBoundsException]
Unchecked [created as per necessity of the user. Example: when bank balance
falls below minimum balance, an error can be raised. ]
Exception handling blocks:
1. Try { checks errors}
2. Catch { to catch the errors}
3. Finally { concluding remark}
 It's possible to have a try block followed by a finally block, with no catch
block :this is used to prevent an unchecked exception from exiting the
method before cleanup code can be executed
Throw & throws statement:
Throw: The throws clause is used to list the types of exception that can
be thrown in the execution of a method in a program
The throws statement is used by a method to specify the types of exceptions
the method throws. If a method is capable of raising an exception that it does
not handle, the method must specify that the exception have to be handled by
the calling method.
GARBAGE COLLECTOR:
Whenever the reference of an object becomes null, then the memory space of
that object is allocated. i.e it would go to the endofgarbage program to execute
its program immediately. It is a very low priority process.
Garbage collection occurs whenever an object becomes garbage, but it might
have some important data, so this important data gets trapped in the garbage,
So we use Finalize method to invoke the info. After that garbage collection
occurs.
Byte 8 bit
Short 16 bit
Int 32 bit
Long 64 bit
Char 16 bit

Mais conteúdo relacionado

Mais procurados

Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For SyntaxPravinYalameli
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Uzair Salman
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_javaHoang Nguyen
 
Java Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJava Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJavabynataraJ
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructorShivam Singhal
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1Sherihan Anver
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java ProgrammingRavi Kant Sahu
 
Core Java interview questions-ppt
Core Java interview questions-pptCore Java interview questions-ppt
Core Java interview questions-pptMayank Kumar
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
Introduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging APIIntroduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging APIwhite paper
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101kankemwa Ishaku
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobGaruda Trainings
 

Mais procurados (20)

Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes
 
Object oriented programming-with_java
Object oriented programming-with_javaObject oriented programming-with_java
Object oriented programming-with_java
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
Java Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJava Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRao
 
Java for C++ programers
Java for C++ programersJava for C++ programers
Java for C++ programers
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructor
 
Core java
Core java Core java
Core java
 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
 
Java interview questions 1
Java interview questions 1Java interview questions 1
Java interview questions 1
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Core Java
Core JavaCore Java
Core Java
 
Java Notes
Java Notes Java Notes
Java Notes
 
Core Java interview questions-ppt
Core Java interview questions-pptCore Java interview questions-ppt
Core Java interview questions-ppt
 
JAVA BASICS
JAVA BASICSJAVA BASICS
JAVA BASICS
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
Introduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging APIIntroduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging API
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 
Java training in delhi
Java training in delhiJava training in delhi
Java training in delhi
 

Semelhante a Java notes

SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to JavaSMIJava
 
Java programming basics
Java programming basicsJava programming basics
Java programming basicsHamid Ghorbani
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answersKrishnaov
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for MainframersRich Helton
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...AnkurSingh340457
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitishChaulagai
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objectsvmadan89
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2Raghu nath
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Ayes Chinmay
 
Introduction
IntroductionIntroduction
Introductionrichsoden
 

Semelhante a Java notes (20)

Java notes jkuat it
Java notes jkuat itJava notes jkuat it
Java notes jkuat it
 
Java
JavaJava
Java
 
Java_presesntation.ppt
Java_presesntation.pptJava_presesntation.ppt
Java_presesntation.ppt
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Java interview questions and answers
Java interview questions and answersJava interview questions and answers
Java interview questions and answers
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
FAL(2022-23)_CSE0206_ETH_AP2022232000455_Reference_Material_I_16-Aug-2022_Mod...
 
Nitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptxNitish Chaulagai Java1.pptx
Nitish Chaulagai Java1.pptx
 
Classes and Objects
Classes and ObjectsClasses and Objects
Classes and Objects
 
Viva file
Viva fileViva file
Viva file
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
 
Java basics
Java basicsJava basics
Java basics
 
Java1
Java1Java1
Java1
 
Java
Java Java
Java
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
java basic .pdf
java basic .pdfjava basic .pdf
java basic .pdf
 
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
Internet and Web Technology (CLASS-15) [JAVA Basics] | NIC/NIELIT Web Technol...
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Introduction
IntroductionIntroduction
Introduction
 

Mais de Upasana Talukdar

Mais de Upasana Talukdar (20)

Large group intervention at airbus
Large group intervention at airbusLarge group intervention at airbus
Large group intervention at airbus
 
Shine life insurance
Shine life insuranceShine life insurance
Shine life insurance
 
Ohio department of taxation case study
Ohio department of taxation case studyOhio department of taxation case study
Ohio department of taxation case study
 
Oprah winfrey-charismatic leader
Oprah winfrey-charismatic leaderOprah winfrey-charismatic leader
Oprah winfrey-charismatic leader
 
Reliance vs big bazaar
Reliance vs big bazaarReliance vs big bazaar
Reliance vs big bazaar
 
Case analysis of wal mart
Case analysis of wal martCase analysis of wal mart
Case analysis of wal mart
 
Key Account Management
Key Account ManagementKey Account Management
Key Account Management
 
contract act
contract actcontract act
contract act
 
Emma
Emma Emma
Emma
 
Real estate market
Real estate market Real estate market
Real estate market
 
interviews
interviewsinterviews
interviews
 
computer organization and architecture notes
computer organization and architecture notescomputer organization and architecture notes
computer organization and architecture notes
 
How to use movie maker
How to use movie maker How to use movie maker
How to use movie maker
 
Html tags list
Html tags listHtml tags list
Html tags list
 
Crytocurrency and bitcoins
Crytocurrency and bitcoinsCrytocurrency and bitcoins
Crytocurrency and bitcoins
 
FISCAL POLICY
FISCAL POLICYFISCAL POLICY
FISCAL POLICY
 
Ben and jerry's CASE STUDY ORGANIZATIONAL DESIGN
Ben and jerry's CASE STUDY ORGANIZATIONAL DESIGNBen and jerry's CASE STUDY ORGANIZATIONAL DESIGN
Ben and jerry's CASE STUDY ORGANIZATIONAL DESIGN
 
Dbms notes
Dbms notesDbms notes
Dbms notes
 
Data structures notes
Data structures notesData structures notes
Data structures notes
 
Mba in India 101
Mba in India 101Mba in India 101
Mba in India 101
 

Último

Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 

Último (20)

Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 

Java notes

  • 1. JAVA Java programming language was originally developed by Sun Microsystems. Java is guaranteed to be Write Once, Run Anywhere. Java is not a programming language but also a platform. Java files are written with “.java” extension. STRUCTURE: class filename { public static void main(String[]args)//main function { ____________________________ } } Main function: public-it declares that the main method is publicaly accessible to other classes. static: it declares that the main method can be invoked without creating an instance of the class. void: it declares that the main method does not return any value. main- it defines the name of the method. String [] args- it defines a parameter to main method which will contain any command line options passed by the user when invoking the program. SCANNER CLASS : import java.util.Scanner; Scanner input = new Scanner(System.in);
  • 2. Datatype object = input.nextDatatype(); PRINTING VALUE: System.out.println("______"); MATH FUNCTIONS: import.java.lang.Math; “A” is a string & ‘A’ is a character. Any positive integer b/w 0 to FFFF in hexadecimal can be cast in character implicity. To convert a string to a number we use- int intValue = Integer.parseInt(intString); To convert a string into a double value, use the Double.parseDouble method, as follows: double doubleValue = Double.parseDouble(doubleString); A named constant is declared by using the keyword final. DIFFERENCE B/W C/C++ & JAVA: 1. Java does not support preprocessing. 2. Total code of java is written in class. 3. Java does not support global variable. Every variable should declare in class. 4. Java supports wrapper class. 5. Memory allocation is done by java compiler (using garbage collector). 6. Java programs are platform independent. 7. Java does not support structure, union & pointer. 8. It runs in a protected virtual machine HOW TO RUN A PROGRAM: 1. Write a code in notepad & save it as name.java 2. For compiling: C: javac name.java C: java classname
  • 3. For applets: we write 2 codes: name.java & name.html {both should lie in the same directory.} C: javac name.java C: appletviewer name.html IMPORTANT TERMS: Object oriented programming simplifies the software development and maintenance by providing some concepts: Object [Any entity that has state and behavior] Class [Collection of objects]{ A class is a set of objects with similar properties (attributes), common behaviour (operations), and common link to other objects.} Inheritance [When one object acquires all the properties and behaviours of parent object i.e. known as inheritance. It provides code reusability. It is used to achieve runtime polymorphism.] Polymorphism [When one task is performed by different ways i.e. known as polymorphism. In java, we use method overloading and method overriding to achieve polymorphism. Polymorphism means that a variable of a supertype can refer to a subtype object. ] Abstraction [Hiding internal details and showing functionality is known as abstraction. In java, we use abstract class and interface to achieve abstraction] Encapsulation [Binding (or wrapping) code and data together into a single unit is known as encapsulation] Interface: it is like a class except that an interface contains methods with no body & static final fields. Interface alone is of no use, it should be implemented by some class.
  • 4. Package: it is a container of related classes & interfaces. A package is like a folder in a file system. Wrapper class: primitive data type is written in classes for security. Message parsing: it is a mechanism by which objects interchange among other object. Bytecodes: these are a set of instructions that looks a lot like some machine codes, but that is not specific to any one processor Swing: it has the properties similar to AWT. It is used to enhance the look of the applet. Thread: a thread is a light weight sub process, a smallest unit of processing. It is separate path of execution. Abstract class: it is used for inheritance purpose only. An abstract class may have abstract method. The method that have no body are abstract class. Dynamic binding: A method can be implemented in several classes along the inheritance chain. Final keyword: it is used with context to class, method & reference or primitive type variable declaration. Finalize keyword; a finalize method is a protected method of java.lang.Object. this method is called by the garbage collector on object which is least recently used and there are no references made to the object for a long time. Implicit casting: the process of assigning one entity to another without any transporation guidance to the compiler. This type of is not permitted transportations & may not workout for all applicaton types. Ex; Int i=4000; Long h=i; Explicit casting: the process in which the complier are specifically informed to about transforming the object. Ex; Long ln=700.20;
  • 5. t=(int)ln; string tokenizer class: it takes an input stream & parses it into “tokens” , allowing the tokens to be read one at a time. StringTokenizer sTokenize = new StringTokenizer(s,” “); while(sTokenizer.hasMoreTokens) { Java is:  Object Oriented: In Java, everything is an Object. Java can be easily extended since it is based on the Object model.  Platform independent: Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual Machine (JVM) on whichever platform it is being run.  Simple: Java is designed to be easy to learn. If you understand the basic concept of OOP, Java would be easy to master.  Secure: With Java's secure feature, it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.  Architectural-neutral: Java compiler generates an architecture-neutral object file format, which makes the compiled code to be executable on many processors, with the presence of Java runtime system.  Robust: Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.  Multithreaded: With Java's multithreaded feature, it is possible to write programs that can do many tasks simultaneously. This design feature allows developers to construct smoothly running interactive applications.  Interpreted: Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and lightweight process.  High Performance: With the use of Just-In-Time compilers, Java enables high performance.
  • 6.  Distributed: Java is designed for the distributed environment of the internet.  Dynamic: Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time. It can be defined as a collection of objects that communicate via invoking each other's methods.  Object - Objects have states and behaviours. Example: A dog has states- color, name, breed as well as behaviours -wagging, barking, eating. An object is an instance of a class. An object is a collection of data members & methods. Data members are called as variables, methods are called as functions.  Class - A class can be defined as a template/blue print that describes the behaviours/states that object of its type support.  Methods - A method is basically a behaviour. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.  Instance Variables - Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.  Instance variables are declared Inside a class but not Inside a method  Methods must have a return type, but constructors cannot have a return type.  Constructors are not inherited.  Three ways to get rid of an object's reference: 1. The reference is assigned another object 2. The reference is explicitly set to null 3. the reference goes out of scope permanently SOME IMPORTANT POINTS TO REMEMBER-  Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java.  Class Names - For all class names, the first letter should be in Upper Case. If several words are used to form a name of the class, each inner
  • 7. word's first letter should be in Upper Case. Example class MyFirstJavaClass  Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example public void myMethodName()  Program File Name - Name of the program file should exactly match the class name. When saving the file, you should save it using the class name & append '.java' to the end of the name (if the file name and the class name do not match your program will not compile). Example : Assume 'MyFirstJavaProgram' is the class name, then the file should be saved as'MyFirstJavaProgram.java'  public static void main(String args[]) - Java program processing starts from the main() method, which is a mandatory part of every Java program.  The Java compiler does not require import declarations in a Java source- code file if the fully qualified class name is specified every time a class name is used in the source code.Most Java programmers prefer to use import declarations. IMPORTANT JAVA CONCEPTS: JAVA ARRAYS: Arrays are objects that store multiple variables of the same type. However, an array itself is an object on the heap. It is a collection of similar or homogeneous values. Int a[]= new int[5] JAVA ENUMS: Enums restrict a variable to have one of only a few predefined values. The values in this enumerated list are called enums. With the use of enums, it is possible to reduce the number of bugs in your code. Enums can be declared as their own or inside a class. Methods, variables, constructors can be defined inside enums as well.
  • 8. Java supports the following fundamental concepts:  Polymorphism  Inheritance  Encapsulation  Abstraction  Classes  Objects  Instance  Method  Message Parsing Java does NOT support-  Header files  #defines  Typedefs or structs  Pointer arithmetic  Multiple inheritance of classes {but can be indirectly applied by using ‘n’ interfaces.}  General functions(only methods are supported)  Pointer, structure & union Java Development kit (JDK) – The JDK comes with a set of tools that are used for developing and running Java program. It includes: 1. Appletviewer( It is used for viewing the applet) 2. Javac(It is a Java Compiler) 3. Java(It is a java interpreter) 4. Javap(Java diassembler,which convert byte code into program description) 5. Javah(It is for java C header files) 6. Javadoc(It is for creating HTML document) 7. Jdb(It is Java debugger) JAVA IDENTIFIERS:
  • 9. All Java components require names. Names used for classes, variables and methods are called identifiers. In Java, there are several points to remember about identifiers. They are as follows: All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). After the first character identifiers can have any combination of characters. A key word cannot be used as an identifier. Most importantly identifiers are case sensitive. Examples of legal identifiers: age, $salary, _value, __1_value Examples of illegal identifiers: 123abc, -salary JAVA MODIFIERS: It is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers: Access Modifiers: default, public , protected, private Non-access Modifiers: final, abstract, strictfp ABSTRACT CLASS: if a class contains any function with no body the & such a function is known as abstract function & that function must be proceeded by abstract method JAVA VARIABLES:  Local Variables  Class Variables (Static Variables)  Instance Variables (Non-static variables) INHERITANCE: It is a process of reusability. The existing members of a class can be accessed in a subclass. I.e. classes can be derived from classes.
  • 10. There are 3 types:  Simple level  Multi level  Hirerarical In java multiple inheritance cannot be supported for class structure or hierarchy. But we are having an optional technique to implement multiple inheritance. By implementing ‘n’ no .of interface, we can actually implement multiple inheritance property indirectly. We have to define abstract methods corresponding to each & every interfaces in the class. HOW TO USE CONSTRUCTORS IN INHERITANCE? In inheritance we are always creating objects for subclasses. Therefore, whatever values required for sub & superclasses should be passed to subclass constructor, from there we can pass to superclass by using a keyword called “super”. It should be the first statement in subclass constructor. POLYMORPHISM: Creating a function with same in more than one class is a concept of polymorphism. Dynamic Method Dispatch (Runtime polymorphism) is a process in which a call to an overridden method is resolved at runtime rather than compile-time. In other words, an overridden method is called through the reference variable of a superclass The determination of the method to be called is based on the object being referred to by the reference variable. Void area(int I, int j) { Int area; Area=i*j; } Void area(int i)
  • 11. { Int area; Area=i*I; } Same name action different INTERFACES: An interface can be defined as a contract between objects on how to communicate with each other. An interface defines the methods, a deriving class (subclass) should use. But the implementation of the methods is totally up to the subclass. Why use Java interface? It is used to achieve fully abstraction. By interface, we can support the functionality of multiple inheritance. It can be used to achieve loose coupling. JAVA PACKAGE: A java package is a group of similar types of classes, interfaces and sub- packages. Package in java can be categorized in two form, built-in package and user- defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc. It is used in Java in order to prevent naming conflicts, to control access, to make searching/locating and usage of classes, interfaces, enumerations and annotations easier, etc. The default package in java is java.lang. THREADS:
  • 12. By using threads we can execute more programs simultaneously. Imp. Methods: start(), stop(), sleep(), suspend(), resume()  New born state: when we create a thread  Runnable state: start  Running state : run() exection  Blocked state: wait(), sleep()  Dead/finished state: work is over Java is the only programing language that supports multi-threading. SETTING PIRORITES FOR THEREADS: Generally all threads have equal priority i.e normal priority(5). {highest priority= 10 & least priority= 1} The thread which is having highest priority will be completing first even if it starts late & the thread with least priority will complete at the last even if it starts early. Deadlock: two or more threads are blocked forever, this situation arises with atleast 2 threads or more resources. MULTITHREADING: execution of multiple threads can be done simultaneously as we create multiple child thread corresponding to single parent thread. If the priority of the thread is same, but if the priority gets changed then the execution sequence might differ, it depends upon the O.S. It does not block the user. Many operations can be performed together, so it saves time. Cost of communication between the threads is low. IsAlive() method: reuturns the status of the thread(true or false) i.e whether a thread is alive or dead.
  • 13. Join() method: it will wait till the program execution will get over. i.e it waits upto the exection of all threads corresponding to a thread group. ADAVNTAGES OF MULTITHREADING: 1. Reduces the computation time. 2. Improves performance of an application. 3. Threads distribute the same address space so it saves the memory. 4. Context switching between threads is usually less costly than between processes. 5. Cost of communication between threads is comparatively low THREAD SYNCRONIZATION: When we start two or more threads within a program, there may be a situation when multiple threads try to access the same resource and finally they can produce unforeseen result due to concurrency issue. The general form of the synchronized statement: synchronized(objectidentifier) { } objectidentifier is a reference to an object whose lock associates with the monitor that the synchronized statement represents DEADLOCK: It is a programming situation where 2 or more threads are blocked forever, this situation arises with atleast 2 or more resources. This arises when a thread wants some information from another thread, which is already in waiting state, then the thread goes in waiting state. So deadlock occours. INTERFACES: As java does not support multiple inheritance, interfaces can be used as an alternative. In interface, whatever variables are declared are treated as final members i.e constants.
  • 14. In interface, we can only make function declaration. Body can be included as per the necessity of the class. The class is called in another using extends keyword. A interfaced is called using implements. an interface is different from a class in several ways, including: t. in an interface must be declared both static and final. ces. An interface is similar to a class in the following ways: the interface matching the name of the file. an interface appears in a .class file. be in a directory structure that matches the package name. JAVA OVERRIDING: The benefit of overriding is: ability to define a behavior that's specific to the subclass type which means a subclass can implement a parent class method based on its requirement. In object- oriented terms, overriding means to override the functionality of an existing method. FILE CLASS: Using this we can display total files & directories. A.W.T {ABSTRACT WINDOW TOOLKIT}
  • 15. Using this we can create windows in java. APPLET: Applets do not need a main( ) method.  Applets must be run under an applet viewer or a Java-compatible browser.  User I/O is not accomplished with Java’s stream I/O classes. Instead, applets use the interface provided by the AWT or Swing.  Applets are small programs.  The java.applet package is the smallest package in Java API(Application Programming Interface). Lifecycle of applet:  Init : born/ initialization  Start : running  Stop: idle  Destroy: dead init() : This method is used for whatever initializations are needed for your applet. Applets can have a default constructor, but it is better to perform all initializations in the init method instead of the default constructor. start() : This method is automatically called after Java calls the init method. If this method is overwritten, code that needs to be executed every time that the user visits the browser page that contains this applet. stop() : This method is automatically called when the user moves off the page where the applet sits. If your applet doesn't perform animation, play audio files, or perform calculations in a thread, you don't usually need to use this method. destroy(): Java calls this method when the browser shuts down public void paint(Graphics g): is used to paint the Applet. It provides Graphics class object that can be used for drawing oval, rectangle, arc etc. JVM:
  • 16. Java Virtual Machine: it is an abstract machine. It performs following main tasks: Loads code Verifies code Executes code Provides runtime environment It is platform dependent. JRE: Java Runtime Environment: It contains set of libraries + other files that JVM uses at runtime. JDK: Java Development Kit: It physically exists. It contains JRE + development tools. METHOD OVERLOADING: If a class have multiple methods by same name but different parameters, it is known as Method Overloading. If we have to perform only one operation, having same name of the methods increases the readability of the program. Advantage: Method overloading increases the readability of the program. METHOD OVERRIDING: If subclass has the same method as declared in the parent class, it is known as method overriding. Rules:  Method must have same name as in the parent class.  Method must have same parameter as in the parent class.  Must have inheritance. It is used for runtime polymorphism.
  • 17. It is used to provide specific implementation of a method that is already provided by super class. OVERLOADING VS OVERRIDING: Overloading means to define multiple methods with the same name but different signatures. Overriding means to provide a new implementation for a method in the subclass. EXCEPTION HANDLING: An exception is nothing but a runtime error. When a runtime error occurs, program gets terminated abnormally. Exception handing means handling runtime errors. When an exception occurs, the JRE creates a corresponding exception class object & throws it to the program. If we want to handle it then we have to catch it. Keywords used: try, catch, throw, throws, finally Examples: dividing an integer with zero, giving an invalid input, reading from a file which is not available. Types: Checked [Built in exceptions example: ArithmeticException, ArrayIndexOutOfBoundsException] Unchecked [created as per necessity of the user. Example: when bank balance falls below minimum balance, an error can be raised. ] Exception handling blocks: 1. Try { checks errors} 2. Catch { to catch the errors} 3. Finally { concluding remark}  It's possible to have a try block followed by a finally block, with no catch block :this is used to prevent an unchecked exception from exiting the method before cleanup code can be executed Throw & throws statement:
  • 18. Throw: The throws clause is used to list the types of exception that can be thrown in the execution of a method in a program The throws statement is used by a method to specify the types of exceptions the method throws. If a method is capable of raising an exception that it does not handle, the method must specify that the exception have to be handled by the calling method. GARBAGE COLLECTOR: Whenever the reference of an object becomes null, then the memory space of that object is allocated. i.e it would go to the endofgarbage program to execute its program immediately. It is a very low priority process. Garbage collection occurs whenever an object becomes garbage, but it might have some important data, so this important data gets trapped in the garbage, So we use Finalize method to invoke the info. After that garbage collection occurs. Byte 8 bit Short 16 bit Int 32 bit Long 64 bit Char 16 bit