SlideShare ist ein Scribd-Unternehmen logo
1 von 16
FEW IMPORTANT TOPIC’S TO BE
REFFERED BY SIR……
THREADING
INTERFACE
POLYMORPHISM
INHERITANCE
APPLET’S
PSVM
Made by:
Farzad
Tapan
1
WHAT IS THREADING ?
2
 Any single path of execution within a program that can be executed
independently, is called a thread.
 Java provides built-in support for multithreaded programming.
 A multithreaded program contains two or more parts that can run
concurrently. Each part of such a program is called a thread,
and each thread defines a separate path of execution.
 A multithreading is a specialized form of multitasking.
Multithreading requires less overhead than multitasking processing.
A thread cannot exist on its own; it must be a part of a process.
When a standalone application is run, a thread is automatically created to
execute the main() method. This thread is called the main thread.
The program terminates when the main thread finishes executing. All
other thread is called child thread.
 Threads subdivide the runtime behavior of a program into separate,
independently running subtasks. Even in a single processor system,
thread provides an illusion of carrying out several tasks
simultaneously.
 This is possible because switching between threads happen very fast.
THREAD PRIORITIES:
3
 Every Java thread has a priority that helps the operating system determine the
order in which threads are scheduled.
 Java priorities are in the range between MIN_PRIORITY (a constant of 1) and
MAX_PRIORITY (a constant of 10). By default, every thread is given
priority NORM_PRIORITY (a constant of 5).
 Threads with higher priority are more important to a program and should be
allocated processor time before lower-priority threads. However, thread
priorities cannot guarantee the order in which threads execute and very
much platform dependentant.
ABOVE MENTIONED STAGES ARE EXPLAINED HERE:
 New: A new thread begins
its life cycle in the new state. It
remains in this state until the
program starts the thread. It is
also referred to as a born
thread.
 Runnable: After a newly
born thread is started, the
thread becomes runnable. A
thread in this state is
considered to be executing its
task.
 Waiting: Sometimes a
thread transitions to the
waiting state while the thread
waits for another thread to
perform a task.
A thread transitions back to
the runnable state only when
another thread signals the
waiting thread to continue
executing.
 Timed waiting: A runnable
thread can enter the timed
waiting state for a specified
interval of time. A thread in
this state transitions back to
the runnable state when that
time interval expires or when
the event it is waiting for
occurs.
 Terminated: A runnable
thread enters the terminated
state when it completes its task
or otherwise terminates.
4
EXAMPLE OF THREADING
5
// Create a new thread.
class NewThread implements Runnable {
Thread t; NewThread() {
// Create a new, second thread
t = new Thread(this, "Demo Thread");
System.out.println("Child thread: " + t);
t.start(); // Start the thread
} // This is the entry point for the second thread.
public void run() {
try { for(int i = 5; i > 0; i--) {
System.out.println("Child Thread: " + i); // Let the thread sleep for a while.
Thread.sleep(500);
}
}
catch (InterruptedException e) {
System.out.println("Child interrupted.");
}
System.out.println("Exiting child thread.");
}
}
public class ThreadDemo {
public static void main(String args[]) {
new NewThread(); // create a new thread
try { for(int i = 5; i > 0; i--) {
System.out.println("Main Thread: " + i);
Thread.sleep(1000);
}
} catch (InterruptedException e) {
System.out.println("Main thread interrupted.");
}
System.out.println("Main thread exiting.");
}
}
Here is an example that creates a new thread and starts it running:
Output:
Child thread: Thread[Demo
Thread,5,main]
Main Thread: 5
Child Thread: 5
Child Thread: 4
Main Thread: 4
Child Thread: 3
Child Thread: 2
Main Thread: 3
Child Thread: 1
Exiting child thread.
Main Thread: 2
Main Thread: 1
Main thread exiting.
WHAT IS INTERFACES ?
6
An interface is a collection of abstract methods. A class implements an
interface, thereby inheriting the abstract methods of the interface.
An interface is not a class. Writing an interface is similar to writing a class,
but they are two different concepts. A class describes the attributes
and behaviors of an object. An interface contains behaviors that a
class implements.
Unless the class that implements the interface is abstract, all the methods of
the interface need to be defined in the class.
An interface is similar to a class in the following ways:
a. An interface can contain any number of methods.
b. An interface is written in a file with a .java extension, with the name of the
interface matching the name of the file.
c. The bytecode of an interface appears in a .class file.
d. Interfaces appear in packages, and their corresponding bytecode file must
be in a directory structure that matches the package name.
DECLARING INTERFACES:
7
The interface keyword is used to declare an interface. Here is a simple example to declare an
interface:
/* File name : NameOfInterface.java */
import java.lang.*;
//Any number of import statements
public interface NameOfInterface {
//Any number of final, static fields
//Any number of abstract method declarations
}
Let us look at an example that depicts encapsulation:
Interfaces have the following properties:
An interface is implicitly abstract. You do not need to use the abstract keyword when
declaring an interface.
Each method in an interface is also implicitly abstract, so the abstract keyword is not
needed.
Methods in an interface are implicitly public.
WHAT IS POLYMORPHISM ?
8
Polymorphism is the ability of an object to take on many forms. The most common
use of polymorphism in OOPS occurs when a parent class reference is used
to refer to a child class object.
Any java object that can pass more than one IS-A test is considered to be
polymorphic. In Java, all java objects are polymorphic since any object will
pass the IS-A test for their own type and for the class Object.
It is important to know that the only possible way to access an object is through a
reference variable. A reference variable can be of only one type. Once
declared the type of a reference variable cannot be changed.
The reference variable can be reassigned to other objects provided that it is not
declared final. The type of the reference variable would determine the
methods that it can invoke on the object.
A reference variable can refer to any object of its declared type or any subtype of its
declared type. A reference variable can be declared as a class or interface
type.
WHAT IS INHERITANCE ?
9
A class can be built on another class that is already defined and is
existing. The already existing class is called base class
or parent class. The newly built class is called derived class
or child class.
The child class inherits all the properties of the parent class,
i.e. it inherits all the member variables and methods of the
parent class.
In addition the child class can have its own member variables
and methods. Inheritance may take different forms.
BASIC OF INHERITANCE
10
Reusability is one of the most important aspects of OOPS paradigm.
Java supports the concept of reusing the code that already
exists. Inheritance allows the creation of hierarchical
classification.
Using inheritance, you can create a general class that defines traits
common to a set of related items. The characteristics of this
class can then be inherited by other, more specific classes,
each adding those aspects that are unique to it.
A class that is inherited is called superclass or parent class.
The class that does the inheriting is called a subclass or
child class.
FORMS OF INHERITANCE
 A class in java can
only extend one other
class, i.e. a class can
only have one
immediate superclass.
This is sometimes
called linear
inheritance. The
inheritance
relationship can be
depicted as an
inheritance hierarchy.
Inheritance defines is-a
relationship between a
superclass and its
subclass.
 This means that an
object of a subclass can
be used whenever an
object of the superclass
can be used. This is-a
relationship does not
hold between peer
classes. Multiple
inheritance, i.e. a
subclass inheriting
from more than one
superclass is not
supported in java. 11
WHAT ARE APPLET’S ?
12
 An applet is a Java program that runs in a Web browser. An applet can be a fully
functional Java application because it has the entire Java API at its disposal.
There are some important differences between an applet and a standalone Java
application, including the following:
1. An applet is a Java class that extends the java.applet.Applet class.
2. A main() method is not invoked on an applet, and an applet class will not
define main().
3. Applets are designed to be embedded within an HTML page.
4. When a user views an HTML page that contains an applet, the code for the
applet is downloaded to the user's machine.
5. A JVM is required to view an applet. The JVM can be either a plug-in of the
Web browser or a separate runtime environment.
6. The JVM on the user's machine creates an instance of the applet class and
invokes various methods during the applet's lifetime.
7. Applets have strict security rules that are enforced by the Web browser. The
security of an applet is often referred to as sandbox security, comparing the
applet to a child playing in a sandbox with various rules that must be
followed.
 Other classes that the applet needs can be downloaded in a single
Java Archive (JAR) file.
LIFE CYCLE OF AN APPLET:
13
 Four methods in the Applet class give you the framework on which you build any
serious applet:
 init: This method is intended for whatever initialization is needed for your applet.
It is called after the param tags inside the applet tag have been processed.
 start: This method is automatically called after the browser calls the init method.
It is also called whenever the user returns to the page containing the applet after
having gone off to other pages.
 stop: This method is automatically called when the user moves off the page on
which the applet sits. It can, therefore, be called repeatedly in the same applet.
 destroy: This method is only called when the browser shuts down normally.
Because applets are meant to live on an HTML page, you should not normally leave
resources behind after a user leaves the page that contains the applet.
 paint: Invoked immediately after the start() method, and also any time the applet
needs to repaint itself in the browser. The paint() method is actually inherited from
the java.awt.
A "HELLO, WORLD" APPLET:
14
 The following is a simple applet named HelloWorldApplet.java:
import java.applet.*;
import java.awt.*;
public class HelloWorldApplet extends Applet {
public void paint (Graphics g) {
g.drawString ("Hello World", 25, 50);
}
}
 These import statements bring the classes into the scope of our applet class:
java.applet.Applet.
java.awt.Graphics.
 Without those import statements, the Java compiler would not recognize the classes
Applet and Graphics, which the applet class refers to.
WHAT IS PUBLIC STATIC VOID MAIN ?
Every word in the above
statement has got a
meaning to the JVM.
1. public: It is a
keyword and
denotes that any
other class (JVM)
can call the main()
method without any
restrictions.
2. static: It is a
keyword and
denotes that any
other class (JVM)
can call the main()
method without the
help of an object.
More about static
is available at
static Keyword –
Philosophy.
3. void: It is a
keyword and
denotes that the
main() method
does not return a
value.
4. main(): It is the
name of the
method. 15
THANK YOU…..
16

Weitere ähnliche Inhalte

Was ist angesagt?

Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview QestionsArun Vasanth
 
Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerTOPS Technologies
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
Interview Questions and Answers for Java
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for JavaGaruda Trainings
 
Top 10 Java Interview Questions and Answers 2014
Top 10 Java Interview Questions and Answers 2014 Top 10 Java Interview Questions and Answers 2014
Top 10 Java Interview Questions and Answers 2014 iimjobs and hirist
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Java Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJava Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJavabynataraJ
 
Java questions for viva
Java questions for vivaJava questions for viva
Java questions for vivaVipul Naik
 
Java object oriented programming - OOPS
Java object oriented programming - OOPSJava object oriented programming - OOPS
Java object oriented programming - OOPSrithustutorials
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.netJanbask ItTraining
 
Top 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersTop 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersWhizlabs
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 
Unit of competency
Unit of competencyUnit of competency
Unit of competencyloidasacueza
 
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007Arun Kumar
 

Was ist angesagt? (18)

Java/J2EE interview Qestions
Java/J2EE interview QestionsJava/J2EE interview Qestions
Java/J2EE interview Qestions
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Most Asked Java Interview Question and Answer
Most Asked Java Interview Question and AnswerMost Asked Java Interview Question and Answer
Most Asked Java Interview Question and Answer
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Interview Questions and Answers for Java
Interview Questions and Answers for JavaInterview Questions and Answers for Java
Interview Questions and Answers for Java
 
Java interview question
Java interview questionJava interview question
Java interview question
 
Top 10 Java Interview Questions and Answers 2014
Top 10 Java Interview Questions and Answers 2014 Top 10 Java Interview Questions and Answers 2014
Top 10 Java Interview Questions and Answers 2014
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Java Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRaoJava Interview Questions by NageswaraRao
Java Interview Questions by NageswaraRao
 
Java questions for viva
Java questions for vivaJava questions for viva
Java questions for viva
 
Java object oriented programming - OOPS
Java object oriented programming - OOPSJava object oriented programming - OOPS
Java object oriented programming - OOPS
 
Java questions and answers jan bask.net
Java questions and answers jan bask.netJava questions and answers jan bask.net
Java questions and answers jan bask.net
 
Core java questions
Core java questionsCore java questions
Core java questions
 
Top 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed AnswersTop 100 Java Interview Questions with Detailed Answers
Top 100 Java Interview Questions with Detailed Answers
 
Concurrency on the JVM
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVM
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
Lulu.com.java.j2 ee.job.interview.companion.2nd.edition.apr.2007
 

Andere mochten auch

Ado.net session14
Ado.net session14Ado.net session14
Ado.net session14Niit Care
 
Account's Assignment
Account's AssignmentAccount's Assignment
Account's AssignmentNgeam Soly
 
Generics n delegates
Generics n delegatesGenerics n delegates
Generics n delegatesIblesoft
 
Microsoft.net architecturte
Microsoft.net architecturteMicrosoft.net architecturte
Microsoft.net architecturteIblesoft
 
MS SQL Server 1
MS SQL Server 1MS SQL Server 1
MS SQL Server 1Iblesoft
 

Andere mochten auch (7)

Ado.net session14
Ado.net session14Ado.net session14
Ado.net session14
 
Perl slid
Perl slidPerl slid
Perl slid
 
Account's Assignment
Account's AssignmentAccount's Assignment
Account's Assignment
 
Generics n delegates
Generics n delegatesGenerics n delegates
Generics n delegates
 
Microsoft.net architecturte
Microsoft.net architecturteMicrosoft.net architecturte
Microsoft.net architecturte
 
Controls
ControlsControls
Controls
 
MS SQL Server 1
MS SQL Server 1MS SQL Server 1
MS SQL Server 1
 

Ähnlich wie Java Basics

Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview QuestionsKuntal Bhowmick
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questionsGradeup
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesHabtamu Wolde
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Fresherszynofustechnology
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdfvenud11
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questionssatish reddy
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questionssatish reddy
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaKavitha713564
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaKavitha713564
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedGaurav Maheshwari
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDevLabs Alliance
 
Top 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETTop 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETDevLabs Alliance
 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetdevlabsalliance
 

Ähnlich wie Java Basics (20)

Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and Interfaces
 
Java Interview Questions For Freshers
Java Interview Questions For FreshersJava Interview Questions For Freshers
Java Interview Questions For Freshers
 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
 
Pocket java
Pocket javaPocket java
Pocket java
 
Threadnotes
ThreadnotesThreadnotes
Threadnotes
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
C#
C#C#
C#
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
 
1
11
1
 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdet
 
Java Threads
Java ThreadsJava Threads
Java Threads
 
Top 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETTop 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDET
 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdet
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Lecture 10
Lecture 10Lecture 10
Lecture 10
 

Kürzlich hochgeladen

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Kürzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Java Basics

  • 1. FEW IMPORTANT TOPIC’S TO BE REFFERED BY SIR…… THREADING INTERFACE POLYMORPHISM INHERITANCE APPLET’S PSVM Made by: Farzad Tapan 1
  • 2. WHAT IS THREADING ? 2  Any single path of execution within a program that can be executed independently, is called a thread.  Java provides built-in support for multithreaded programming.  A multithreaded program contains two or more parts that can run concurrently. Each part of such a program is called a thread, and each thread defines a separate path of execution.  A multithreading is a specialized form of multitasking. Multithreading requires less overhead than multitasking processing. A thread cannot exist on its own; it must be a part of a process. When a standalone application is run, a thread is automatically created to execute the main() method. This thread is called the main thread. The program terminates when the main thread finishes executing. All other thread is called child thread.  Threads subdivide the runtime behavior of a program into separate, independently running subtasks. Even in a single processor system, thread provides an illusion of carrying out several tasks simultaneously.  This is possible because switching between threads happen very fast.
  • 3. THREAD PRIORITIES: 3  Every Java thread has a priority that helps the operating system determine the order in which threads are scheduled.  Java priorities are in the range between MIN_PRIORITY (a constant of 1) and MAX_PRIORITY (a constant of 10). By default, every thread is given priority NORM_PRIORITY (a constant of 5).  Threads with higher priority are more important to a program and should be allocated processor time before lower-priority threads. However, thread priorities cannot guarantee the order in which threads execute and very much platform dependentant.
  • 4. ABOVE MENTIONED STAGES ARE EXPLAINED HERE:  New: A new thread begins its life cycle in the new state. It remains in this state until the program starts the thread. It is also referred to as a born thread.  Runnable: After a newly born thread is started, the thread becomes runnable. A thread in this state is considered to be executing its task.  Waiting: Sometimes a thread transitions to the waiting state while the thread waits for another thread to perform a task. A thread transitions back to the runnable state only when another thread signals the waiting thread to continue executing.  Timed waiting: A runnable thread can enter the timed waiting state for a specified interval of time. A thread in this state transitions back to the runnable state when that time interval expires or when the event it is waiting for occurs.  Terminated: A runnable thread enters the terminated state when it completes its task or otherwise terminates. 4
  • 5. EXAMPLE OF THREADING 5 // Create a new thread. class NewThread implements Runnable { Thread t; NewThread() { // Create a new, second thread t = new Thread(this, "Demo Thread"); System.out.println("Child thread: " + t); t.start(); // Start the thread } // This is the entry point for the second thread. public void run() { try { for(int i = 5; i > 0; i--) { System.out.println("Child Thread: " + i); // Let the thread sleep for a while. Thread.sleep(500); } } catch (InterruptedException e) { System.out.println("Child interrupted."); } System.out.println("Exiting child thread."); } } public class ThreadDemo { public static void main(String args[]) { new NewThread(); // create a new thread try { for(int i = 5; i > 0; i--) { System.out.println("Main Thread: " + i); Thread.sleep(1000); } } catch (InterruptedException e) { System.out.println("Main thread interrupted."); } System.out.println("Main thread exiting."); } } Here is an example that creates a new thread and starts it running: Output: Child thread: Thread[Demo Thread,5,main] Main Thread: 5 Child Thread: 5 Child Thread: 4 Main Thread: 4 Child Thread: 3 Child Thread: 2 Main Thread: 3 Child Thread: 1 Exiting child thread. Main Thread: 2 Main Thread: 1 Main thread exiting.
  • 6. WHAT IS INTERFACES ? 6 An interface is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface. An interface is not a class. Writing an interface is similar to writing a class, but they are two different concepts. A class describes the attributes and behaviors of an object. An interface contains behaviors that a class implements. Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class. An interface is similar to a class in the following ways: a. An interface can contain any number of methods. b. An interface is written in a file with a .java extension, with the name of the interface matching the name of the file. c. The bytecode of an interface appears in a .class file. d. Interfaces appear in packages, and their corresponding bytecode file must be in a directory structure that matches the package name.
  • 7. DECLARING INTERFACES: 7 The interface keyword is used to declare an interface. Here is a simple example to declare an interface: /* File name : NameOfInterface.java */ import java.lang.*; //Any number of import statements public interface NameOfInterface { //Any number of final, static fields //Any number of abstract method declarations } Let us look at an example that depicts encapsulation: Interfaces have the following properties: An interface is implicitly abstract. You do not need to use the abstract keyword when declaring an interface. Each method in an interface is also implicitly abstract, so the abstract keyword is not needed. Methods in an interface are implicitly public.
  • 8. WHAT IS POLYMORPHISM ? 8 Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOPS occurs when a parent class reference is used to refer to a child class object. Any java object that can pass more than one IS-A test is considered to be polymorphic. In Java, all java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object. It is important to know that the only possible way to access an object is through a reference variable. A reference variable can be of only one type. Once declared the type of a reference variable cannot be changed. The reference variable can be reassigned to other objects provided that it is not declared final. The type of the reference variable would determine the methods that it can invoke on the object. A reference variable can refer to any object of its declared type or any subtype of its declared type. A reference variable can be declared as a class or interface type.
  • 9. WHAT IS INHERITANCE ? 9 A class can be built on another class that is already defined and is existing. The already existing class is called base class or parent class. The newly built class is called derived class or child class. The child class inherits all the properties of the parent class, i.e. it inherits all the member variables and methods of the parent class. In addition the child class can have its own member variables and methods. Inheritance may take different forms.
  • 10. BASIC OF INHERITANCE 10 Reusability is one of the most important aspects of OOPS paradigm. Java supports the concept of reusing the code that already exists. Inheritance allows the creation of hierarchical classification. Using inheritance, you can create a general class that defines traits common to a set of related items. The characteristics of this class can then be inherited by other, more specific classes, each adding those aspects that are unique to it. A class that is inherited is called superclass or parent class. The class that does the inheriting is called a subclass or child class.
  • 11. FORMS OF INHERITANCE  A class in java can only extend one other class, i.e. a class can only have one immediate superclass. This is sometimes called linear inheritance. The inheritance relationship can be depicted as an inheritance hierarchy. Inheritance defines is-a relationship between a superclass and its subclass.  This means that an object of a subclass can be used whenever an object of the superclass can be used. This is-a relationship does not hold between peer classes. Multiple inheritance, i.e. a subclass inheriting from more than one superclass is not supported in java. 11
  • 12. WHAT ARE APPLET’S ? 12  An applet is a Java program that runs in a Web browser. An applet can be a fully functional Java application because it has the entire Java API at its disposal. There are some important differences between an applet and a standalone Java application, including the following: 1. An applet is a Java class that extends the java.applet.Applet class. 2. A main() method is not invoked on an applet, and an applet class will not define main(). 3. Applets are designed to be embedded within an HTML page. 4. When a user views an HTML page that contains an applet, the code for the applet is downloaded to the user's machine. 5. A JVM is required to view an applet. The JVM can be either a plug-in of the Web browser or a separate runtime environment. 6. The JVM on the user's machine creates an instance of the applet class and invokes various methods during the applet's lifetime. 7. Applets have strict security rules that are enforced by the Web browser. The security of an applet is often referred to as sandbox security, comparing the applet to a child playing in a sandbox with various rules that must be followed.  Other classes that the applet needs can be downloaded in a single Java Archive (JAR) file.
  • 13. LIFE CYCLE OF AN APPLET: 13  Four methods in the Applet class give you the framework on which you build any serious applet:  init: This method is intended for whatever initialization is needed for your applet. It is called after the param tags inside the applet tag have been processed.  start: This method is automatically called after the browser calls the init method. It is also called whenever the user returns to the page containing the applet after having gone off to other pages.  stop: This method is automatically called when the user moves off the page on which the applet sits. It can, therefore, be called repeatedly in the same applet.  destroy: This method is only called when the browser shuts down normally. Because applets are meant to live on an HTML page, you should not normally leave resources behind after a user leaves the page that contains the applet.  paint: Invoked immediately after the start() method, and also any time the applet needs to repaint itself in the browser. The paint() method is actually inherited from the java.awt.
  • 14. A "HELLO, WORLD" APPLET: 14  The following is a simple applet named HelloWorldApplet.java: import java.applet.*; import java.awt.*; public class HelloWorldApplet extends Applet { public void paint (Graphics g) { g.drawString ("Hello World", 25, 50); } }  These import statements bring the classes into the scope of our applet class: java.applet.Applet. java.awt.Graphics.  Without those import statements, the Java compiler would not recognize the classes Applet and Graphics, which the applet class refers to.
  • 15. WHAT IS PUBLIC STATIC VOID MAIN ? Every word in the above statement has got a meaning to the JVM. 1. public: It is a keyword and denotes that any other class (JVM) can call the main() method without any restrictions. 2. static: It is a keyword and denotes that any other class (JVM) can call the main() method without the help of an object. More about static is available at static Keyword – Philosophy. 3. void: It is a keyword and denotes that the main() method does not return a value. 4. main(): It is the name of the method. 15