You are on page 1of 30

Unit I

Java Basics Review: Components and event handling – Threading concepts –


Networking features – Media techniques

BASICS OF JAVA

What is Java Architecture?

● In Java, there is a process of compilation and interpretation.


● The code written in JAVA is converted into byte codes which is done by the Java
Compiler.
● The byte codes, then are converted into machine code by the JVM.

● The Machine code is executed directly by the machine.

This diagram illustrates the internal working of a Java code, or precisely, Java Architecture!

Components of Java Architecture

⮚ There are three main components of Java language: JVM, JRE, and JDK.

⮚ Java Virtual Machine, Java Runtime Environment and Java Development Kit
respectively.
⮚ Let me elaborate each one of them one by one:

Java Virtual Machine:


Ever heard about WORA? (Write once Run Anywhere). Well, Java applications are
called WORA because of their ability to run a code on any platform. This is done only
because of JVM. The JVM is a Java platform component that provides an environment for
executing Java programs. JVM interprets the bytecode into machine code which is executed
in the machine in which the Java program runs.

So, in a nutshell, JVM performs the following functions:

● Loads the code


● Verifies the code
● Executes the code
● Provides runtime environment

JVM architecture

Explanation:

Class Loader:

Class loader is a subsystem of JVM. It is used to load class files. Whenever we run the java
program, class loader loads it first.
Class method area:

It is one of the Data Area in JVM, in which Class data will be stored. Static Variables, Static
Blocks, Static Methods, Instance Methods are stored in this area.

Heap:

A heap is created when the JVM starts up. It may increase or decrease in size while the
application runs.

Stack:

JVM stack is known as a thread stack. It is a data area in the JVM memory which is created
for a single execution thread. The JVM stack of a thread is used by the thread to store
various elements (i.e) local variables, partial results, and data for calling method and
returns.

Native stack: It subsumes all the native methods used in your application.

Execution Engine:

● JIT compiler
● Garbage collector

JIT compiler:

The Just-In-Time (JIT) compiler is a part of the runtime environment. It helps in improving
the performance of Java applications by compiling bytecodes to machine code at run time.
The JIT compiler is enabled by default. When a method is compiled, the JVM calls the
compiled code of that method directly. The JIT compiler compiles the bytecode of that
method into machine code, compiling it “just in time” to run.

Garbage collector:

As the name explains that Garbage Collector means to collect the unused material. Well, in
JVM this work is done by Garbage collection. It tracks each and every object available in the
JVM heap space and removes unwanted ones.
Garbage collector works in two simple steps known as Mark and Sweep:
● Mark – it is where the garbage collector identifies which piece of memory is in use
and which are not
● Sweep – it removes objects identified during the “mark” phase.

Java Runtime Environment:

The JRE software builds a runtime environment in which Java programs can be executed.
The JRE is the on-disk system that takes your Java code, combines it with the needed
libraries, and starts the JVM to execute it. The JRE contains libraries and software needed
by your Java programs to run. JRE is a part of JDK (which we will study later) but can be
downloaded separately.

Java Development Kit:

The Java Development Kit (JDK) is a software development environment used to develop
Java applications and applets. It contains JRE and several development tools, an
interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator
(javadoc) accompanied with another tool.
The blue area shown in the diagram is JDK.

java : it is the launcher for all the java applications.


javac : complier of the java programming languages.
javadoc: it is the API documentation generator.
jar: creates and manage all the JAR files.

How is Java platform independent?

When is any programming language called as platform-independent? Well, if and only if it


can run on all available operating systems with respect to its development and compilation.
Now, Java is platform-independent just because of the bytecode. In simple terms
bytecode is a code of the JVM which is machine-understandable.
Bytecode execution in Java proves it is a platform-independent language.
Here, I will show you the steps involved in the process of java bytecode execution.

Below is the explanation of the steps involved:

sample.java → javac (sample. class) → JVM(sample.obj) → final output

First source code is used by java compiler and is converted in .class file. The class file code
is in byte code form and that class file is used by JVM to convert into an object file. After
that, you can see the final output on your screen.
Event Handling in Java

Source and Events

While understanding the concept of event handling you might have come across terms such
as sources, events, etc. Sources and events are some of the basic terms which are to be
understood before we look at event handling.

Event
When you press a button in your program or Android application the state of the button
changes from ‘Unclicked’ to ‘Clicked’.This change in the state of our button is called an
Event. Events are generated based on how you interact with the GUI. For example- entering
some text through the keyboard, moving your cursor, scrolling, etc generates events.

Source
In Java, nearly everything is an object. The button you press is an object too. Sorce is the
object which generates an event. In other words, a source is an object which undergoes
state change. It also provides information about the event to the listener. We will talk about
the listener in the other half of this post.

Listeners

Now we know about the events and the sources. This is a good time to talk about the
listeners. Listeners are also called as event handlers as they are the ones responsible to
handle events occurring at the source. Listeners are interfaces and different types of
listeners are used according to the event.

Steps to perform Event Handling

Following steps are required to perform event handling:

1. Register the component with the Listener

Registration Methods

For registering the component with the Listener, many classes provide the registration
methods. For example:
⮚ Button
o public void addActionListener(ActionListener a){}

⮚ MenuItem
o public void addActionListener(ActionListener a){}

⮚ TextField
o public void addActionListener(ActionListener a){}
o public void addTextListener(TextListener a){}

⮚ TextArea
o public void addTextListener(TextListener a){}

⮚ Checkbox
o public void addItemListener(ItemListener a){}

⮚ Choice
o public void addItemListener(ItemListener a){}

⮚ List
o public void addActionListener(ActionListener a){}
o public void addItemListener(ItemListener a){}

We can put the event handling code into one of the following places:

1. Within class
2. Other class
3. Anonymous class

Java event handling by implementing ActionListener


1. import java.awt.*;
2. import java.awt.event.*;
3. class AEvent extends Frame implements ActionListener{
4. TextField tf;
5. AEvent(){
6.
7. //create components
8. tf=new TextField();
9. tf.setBounds(60,50,170,20);
10. Button b=new Button("click me");
11. b.setBounds(100,120,80,30);
12.
13. //register listener
14. b.addActionListener(this);//passing current instance
15.
16. //add components and set size, layout and visibility
17. add(b);add(tf);
18. setSize(300,300);
19. setLayout(null);
20. setVisible(true);
21. }
22. public void actionPerformed(ActionEvent e){
23. tf.setText("Welcome");
24. }
25. public static void main(String args[]){
26. new AEvent();
27. }
28. }
public void setBounds(int xaxis, int yaxis, int width, int height); have been used in the
above example that sets the position of the component it may be button, textfield etc.

Event Methods to ‘Override’ EvenListener

ActionEvent- Events generated actionPerformed(ActionEvent


ActionListener
from buttons, menu items, etc. e)
keyPressed(KeyEvent ke)
KeyEvent- Events generaated when
keyTyped(KeyEvent ke) KeyListener
input is received from the keyboard.
keyReleased(KeyEvent ke)

ItemEvent- Events generated from itemStateChanged(ItemEvent


ItemListener
List, Radio Button, etc. ie )

mouseMoved(MouseEvent me)
MouseEvent– Event generated by
MouseMotionListener
the mouse mouseDragged(MouseEvent
me)

2) Java event handling by outer class


1. import java.awt.*;
2. import java.awt.event.*;
3. class AEvent2 extends Frame{
4. TextField tf;
5. AEvent2(){
6. //create components
7. tf=new TextField();
8. tf.setBounds(60,50,170,20);
9. Button b=new Button("click me");
10. b.setBounds(100,120,80,30);
11. //register listener
12. Outer o=new Outer(this);
13. b.addActionListener(o);//passing outer class instance
14. //add components and set size, layout and visibility
15. add(b);add(tf);
16. setSize(300,300);
17. setLayout(null);
18. setVisible(true);
19. }
20. public static void main(String args[]){
21. new AEvent2();
22. }
23. }
1. import java.awt.event.*;
2. class Outer implements ActionListener{
3. AEvent2 obj;
4. Outer(AEvent2 obj){
5. this.obj=obj;
6. }
7. public void actionPerformed(ActionEvent e){
8. obj.tf.setText("welcome");
9. }
10. }
3) Java event handling by anonymous class
1. import java.awt.*;
2. import java.awt.event.*;
3. class AEvent3 extends Frame{
4. TextField tf;
5. AEvent3(){
6. tf=new TextField();
7. tf.setBounds(60,50,170,20);
8. Button b=new Button("click me");
9. b.setBounds(50,120,80,30);
10.
11. b.addActionListener(new ActionListener(){
12. public void actionPerformed(){
13. tf.setText("hello");
14. }
15. });
16. add(b);add(tf);
17. setSize(300,300);
18. setLayout(null);
19. setVisible(true);
20. }
21. public static void main(String args[]){
22. new AEvent3();
23. }
24. }

Threading concepts
Java is a multi-threaded programming language which means we can develop multi-
threaded program using Java. A multi-threaded program contains two or more parts that
can run concurrently and each part can handle a different task at the same time making
optimal use of the available resources specially when your computer has multiple CPUs.
By definition, multitasking is when multiple processes share common processing
resources such as a CPU. Multi-threading extends the idea of multitasking into
applications where you can subdivide specific operations within a single application into
individual threads. Each of the threads can run in parallel. The OS divides processing time
not only among different applications, but also among each thread within an application.
Multi-threading enables you to write in a way where multiple activities can proceed
concurrently in the same program.
Life Cycle of a Thread
A thread goes through various stages in its life cycle. For example, a thread is born,
started, runs, and then dies. The following diagram shows the complete life cycle of a
thread.

Following are the stages of the life cycle:

● 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 (Dead) − A runnable thread enters the terminated state when it


completes its task or otherwise terminates.

Thread Priorities
Every Java thread has a priority that helps the operating system determine the order in
which threads are scheduled.
Java thread 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 are very much platform dependent.

How to Create a Java Thread?

Java lets you create thread in following two ways:-

● By implementing the Runnable interface.


● By extending the Thread

Create a Thread by Implementing a Runnable Interface

If your class is intended to be executed as a thread then you can achieve this by
implementing a Runnable interface. You will need to follow three basic steps −
Step 1
As a first step, you need to implement a run() method provided by a Runnable interface.
This method provides an entry point for the thread and you will put your complete
business logic inside this method. Following is a simple syntax of the run() method −
public void run( )
Step 2
As a second step, you will instantiate a Thread object using the following constructor −
Thread(Runnable threadObj, String threadName);
Where, threadObj is an instance of a class that implements the Runnable interface
and threadName is the name given to the new thread.
Step 3
Once a Thread object is created, you can start it by calling start() method, which executes
a call to run( ) method. Following is a simple syntax of start() method −
void start();
Runnable Interface
The easiest way to create a thread is to create a class that implements
the Runnable interface.

To implement Runnable interface, a class need only implement a single method called
run( ), which is declared like this:

public void run( )

Inside run( ), we will define the code that constitutes the new thread

Example:

public class MyClass implements Runnable {

public void run(){

System.out.println("MyClass running");

}}

To execute the run() method by a thread, pass an instance of MyClass to a Thread in its
constructor(A constructor in Java is a block of code similar to a method that’s called when
an instance of an object is created). Here is how that is done:

Thread t1 = new Thread(new MyClass ());

t1.start();

When the thread is started it will call the run() method of the MyClass instance instead of
executing its own run() method. The above example would print out the text “MyClass
running“.

Extending Java Thread


The second way to create a thread is to create a new class that extends Thread, then
override the run() method and then to create an instance of that class. The run() method is
what is executed by the thread after you call start(). Here is an example of creating a Java
Thread subclass:

public class MyClass extends Thread {

public void run(){

System.out.println("MyClass running");

}
}

To create and start the above thread you can do like this:

MyClass t1 = new MyClass ();

T1.start();

When the run() method executes it will print out the text “MyClass running“.

Creating Multiple Threads

class MyThread implements Runnable {

String name;

Thread t;

MyThread (String thread){

name = threadname;

t = new Thread(this, name);

System.out.println("New thread: " + t);

t.start();

public void run() {

try {

for(int i = 5; i > 0; i--) {

System.out.println(name + ": " + i);

Thread.sleep(1000);

}catch (InterruptedException e) {

System.out.println(name + "Interrupted");

}
System.out.println(name + " exiting.");

class MultiThread {

public static void main(String args[]) {

new MyThread("One");

new MyThread("Two");

new NewThread("Three");

try {

Thread.sleep(10000);

} catch (InterruptedException e) {

System.out.println("Main thread Interrupted");

System.out.println("Main thread exiting.");

The output from this program is shown here:

New thread: Thread[One,5,main]


New thread: Thread[Two,5,main]
New thread: Thread[Three,5,main]
One: 5
Two: 5
Three: 5
One: 4
Two: 4
Three: 4
One: 3
Three: 3
Two: 3
One: 2
Three: 2
Two: 2
One: 1
Three: 1
Two: 1
One exiting.
Two exiting.
Three exiting.
Main thread exiting.
This is how multithreading in java works. This brings us to the end of Java Thread blog. I
hope this was informative and helpful to you. In the next blog of Java Tutorial Blog Series,
you will learn about Java Collection.

Thread Methods

Following is the list of important methods available in the Thread class.

Sr.No Method & Description


.

1 public void start()


Starts the thread in a separate path of execution, then invokes the run() method on
this Thread object.

2 public void run()


If this Thread object was instantiated using a separate Runnable target, the run()
method is invoked on that Runnable object.

3 public final void setName(String name)


Changes the name of the Thread object. There is also a getName() method for
retrieving the name.

4 public final void setPriority(int priority)


Sets the priority of this Thread object. The possible values are between 1 and 10.
5 public final void setDaemon(boolean on)
A parameter of true denotes this Thread as a daemon thread.

6 public final void join(long millisec)


The current thread invokes this method on a second thread, causing the current
thread to block until the second thread terminates or the specified number of
milliseconds passes.

7 public void interrupt()


Interrupts this thread, causing it to continue execution if it was blocked for any
reason.

8 public final boolean isAlive()


Returns true if the thread is alive, which is any time after the thread has been started
but before it runs to completion.

The previous methods are invoked on a particular Thread object. The following methods
in the Thread class are static. Invoking one of the static methods performs the operation
on the currently running thread.

Sr.No Method & Description


.

1 public static void yield()


Causes the currently running thread to yield to any other threads of the same
priority that are waiting to be scheduled.

2 public static void sleep(long millisec)


Causes the currently running thread to block for at least the specified number of
milliseconds.

3 public static boolean holdsLock(Object x)


Returns true if the current thread holds the lock on the given Object.
4 public static Thread currentThread()
Returns a reference to the currently running thread, which is the thread that invokes
this method.

5 public static void dumpStack()


Prints the stack trace for the currently running thread, which is useful when
debugging a multithreaded application.

Networking features:

Java Networking is a concept of connecting two or more computing devices together so that
we can share resources. Java socket programming provides facility to share data between
different computing devices.

Advantage of Java Networking


1. Sharing resources
2. Centralize software management

The java.net package supports two protocols,

1. TCP: Transmission Control Protocol provides reliable communication between the


sender and receiver. TCP is used along with the Internet Protocol referred as
TCP/IP.
2. UDP: User Datagram Protocol provides a connection-less protocol service by
allowing packet of data to be transferred along two or more nodes

Java Networking Terminology

The widely used Java networking terminologies are given below:

1. IP Address
2. Protocol
3. Port Number
4. MAC Address
5. Connection-oriented and connection-less protocol
6. Socket
1) IP Address
IP address is a unique number assigned to a node of a network e.g. 192.168.0.1 . It is
composed of octets that range from 0 to 255.

It is a logical address that can be changed.

2) Protocol
A protocol is a set of rules basically that is followed for communication. For example:

o TCP
o FTP
o Telnet
o SMTP
o POP etc.

3) Port Number
The port number is used to uniquely identify different applications. It acts as a
communication endpoint between applications.

The port number is associated with the IP address for communication between two
applications.

4) MAC Address
MAC (Media Access Control) address is a unique identifier of NIC (Network Interface
Controller). A network node can have multiple NIC but each with unique MAC address.

For example, an ethernet card may have a MAC address of 00:0d:83::b1:c0:8e.

5) Connection-oriented and connection-less protocol


In connection-oriented protocol, acknowledgement is sent by the receiver. So it is reliable
but slow. The example of connection-oriented protocol is TCP.

But, in connection-less protocol, acknowledgement is not sent by the receiver. So it is not


reliable but fast. The example of connection-less protocol is UDP.

6) Socket
A socket is an endpoint between two way communications.

Visit next page for Java socket programming.

java.net package

The java.net package can be divided into two sections:

1. A Low-Level API: It deals with the abstractions of addresses i.e. networking


identifiers, Sockets i.e. bidirectional data communication mechanism and Interfaces
i.e. network interfaces.
2. A High Level API: It deals with the abstraction of URIs i.e. Universal Resource
Identifier, URLs i.e. Universal Resource Locator, and Connections i.e. connections to
the resource pointed by URLs.

The java.net package provides many classes to deal with networking applications in Java. A
list of these classes is given below:

o Authenticator
o CacheRequest
o CacheResponse
o ContentHandler
o CookieHandler
o CookieManager
o DatagramPacket
o DatagramSocket
o DatagramSocketImpl
o InterfaceAddress
o JarURLConnection
o MulticastSocket
o InetSocketAddress
o InetAddress
o Inet4Address
o Inet6Address
o IDN
o HttpURLConnection
o HttpCookie
o NetPermission
o NetworkInterface
o PasswordAuthentication
o Proxy
o ProxySelector
o ResponseCache
o SecureCacheResponse
o ServerSocket
o Socket
o SocketAddress
o SocketImpl
o SocketPermission
o StandardSocketOptions
o URI
o URL
o URLClassLoader
o URLConnection
o URLDecoder
o URLEncoder
o URLStreamHandler

List of interfaces available in java.net package:

o ContentHandlerFactory
o CookiePolicy
o CookieStore
o DatagramSocketImplFactory
o FileNameMap
o SocketOption<T>
o SocketOptions
o SocketImplFactory
o URLStreamHandlerFactory
o ProtocolFamily

Media techniques:

Modern world's rich internet applications must be capable to play and edit the media files
when required. JavaFX provides the media-rich API that can play audio and video on the
user's demand.

JavaFX Media API enables the users to incorporate audio and video into the rich internet
applications (RIAs). JavaFX media API can distribute the media content across the different
range of devices like TV, Mobile, Tablets and many more.

In this part of the tutorial, we will discuss the capability of JavaFX to deal with the media
files in an interactive way. For this purpose, JavaFX provides the
package javafx.scene.media that contains all the necessary
classes. javafx.scene.media contains the following classes.

1. javafx.scene.media.Media
2. javafx.scene.media.MediaPlayer
3. javafx.scene.media.MediaStatus
4. javafx.scene.media.MediaView

Media Events

The JavaFX team have designed media API to be event driven. The callback behaviour
attached with the media functions are used to handle media events. Instead of typing code
for a button via a EventHandler, a code is implemented that responds to the triggering of
the media player's OnXXXX events where XXXX is the event name.

java.lang.Runnable functional interfaces are used as the callbacks which are invoked
when an event is encountered. When playing the media content in javafx, we would create
the Lambda expressions (java.lang.Runnable interfaces) to be set on the onReady event.
Consider the following example.

Media media = new Media(url);


MediaPlayer mediaPlayer = new MediaPlayer(media);
Runnable playMusic = () -> mediaPlayer.play();
mediaPlayer.setOnReady(playMusic);

The playMusic variable is assigned to a lambda expression. This get passed into the Media
player's setOnReady() method. The Lambda expression will get invoked when the onReady
event is encountered

lass Set On Method Description

Media setOnError() This method is invoked when an error occurs. It is


the part of the class Media.

MediaPlayer setOnEndOfMedia() The method is invoked when end of the media play
is reached.

MediaPlayer setOnError() This method is invoked when an error occurs.

MediaPlayer setOnHalted() This method is invoked when the status of media


changes to halted.

MediaPlayer setOnMarker() This method is invoked when the Marker event is


triggered.

MediaPlayer setOnPaused() This method is invoked when a pause event occurs.

MediaPlayer setOnPlaying() This method is invoked when the play event occurs.

MediaPlayer setOnReady() This method is invoked when the media is in ready


state.

MediaPlayer setOnRepeat() This method is invoked when the repeat property is


set.

MediaPlayer setOnStalled() This method is invoked when the media player is


stalled.

MediaPlayer setOnStopped() This method is invoked when the media player has
stopped.

MediaView setOnError() This method is invoked when an error occurs in the


media view.

We must notice that MediaPlayer class contains the most number of events triggered while
MediaView and Media classes contains one event each.

javafx.scene.media.Media class

The properties of the class are described in the following table. All the properties are the
read only except onError.

Possible media and media-player events are discussed in the following table.

Property Description

duration The duration of the source media in seconds. This property is of object type
of the class Duration.

error This is a property set to media exception value when an error occurs. This
property is of the type object of the class MediaException.

height The height of the source media in pixels. This is an integer type property.

onError The event handler which is called when the error occurs. The
method setOnError() is used to set this property.

width The width of the source media in pixels. This is an integer type property
We must notice that MediaPlayer class contains the most number of events triggered while
MediaView and Media classes contains one event each.

javafx.scene.media.Media class

The properties of the class are described in the following table. All the properties are the
read only except onError.

Property Description

duration The duration of the source media in seconds. This property is of object type
of the class Duration.

error This is a property set to media exception value when an error occurs. This
property is of the type object of the class MediaException.

height The height of the source media in pixels. This is an integer type property.

onError The event handler which is called when the error occurs. The
method setOnError() is used to set this property.

width The width of the source media in pixels. This is an integer type property

Constructors
There is a single constructor in the table.

public Media(java.lang.String source): it instantiate the class Media with the specified
source file.

JavaFX.scene.media.MediaPlayer class

The properties of the class along with the setter methods are described in the following
table.

Property Property Setter Methods

audioSpectrumInterva This is a double type setAudioSpectrumInterval (double value)


l property. It indicates
the interval between
the spectrum
updates in seconds.

audioSpectrumListene This is an object type setAudioSpectrumListener(AudioSpectrumL


r property of the class istener listener)
AudioSpectrumListe
ner. It indicates the
audiospectrumlisten
er for an audio
spectrum.

audioSpectrumNumBa This is an integer setAudioSpectrumNumBands(int value)


nds type property. It
indicates the
number of bands
between the audio
spectrum.

audioSpectrumThresh This is an integer setAudioSpectrumThreshold(int value)


old type property. It
indicates the
sensitivity threshold

autoPlay This is the boolean setAutoPlay(Boolean value)


type property. The
true value indicates
the playing will be
started as soon as
possible.

balance This is a double type setBalance(double value)


property. It indicates
the balance of the
audio output.

bufferProgressTime This is an object type Can not be set as it is read only property.
property of the class
Duration. It indicates
the duration of the
media which can be
played without
stalling the media-
player.

currentCount This is read only Can not be set as it is read only property.
integer type
property. It indicates
the number of
completed playback
cycles.

currentRate This is a double type Can not be set as it is read only property.
property. It indicates
the current rate of
the playback. It is
read only property.

currentTime This is an object type Can not be set as it is read only property.
property of the class
Duration. It indicates
the current media
playback time.

cycleCount It is the integer type setCycleCount(int value)


property. It indicates
the number of times,
the media will be
played.

cycleDuration It is the ready only Can not be set as it is read only property.
property. It is of the
type object of the
class Duration. It
indicates the amount
of time between the
start time and stop
time of the media.

error It is a read only Can not be set as it is read only property.


property. It is an
object type property
of the class
MediaException. It is
set to a Media-
Exception if an error
occurs.

mute It is a boolean type SetMute(boolean value)


property. It indicates
whether the audio is
muted or not.

onEndOfMedia It is an object type setOnEndOfMedia(java.lang.Runnable


property of the value)
interface Runnable.
It is set to an Event
Handler which will
be invoked when the
end of the media file
is reached.

onError It is an object type setOnHalted(java.lang.Runnable value)


property of the
interface Runnable.
It indicates the
Event Handler which
will be invoked
when the status
changes to halted.

onMarker It is an object type setOnMarker(EventHandler<MediaMarkerE


property of the class vent> onMarker )
MediaMarkerEvent.
It indicates the
EventHandler which
will be invoked
when the current
time reaches the
media marker.

onPaused It is an object type setOnPaused(java.lang.Runnable value)


property of the
interface Runnable.
It indicates the
EventHandler which
will be invoked
when the status
changed to paused.

onPlaying It is an object type setOnPlaying(java.lang.Runnable value)


property of the
interface Runnable.
It indicates the
EventHandler which
will be invoked
when the status
changed to playing.

onReady It is an object type setOnReady(java.lang.Runnable value)


property of the
interface Runnable.
It indicates the
EventHandler which
will be invoked
when the status
changed to Ready.

onRepeat It is an object type setOnRepeat(java.lang.Runnable value)


property of the class
MediaMarkerEvent.
It indicates the
EventHandler which
will be invoked
when the current
time reaches the
stop time and will be
repeating.

onStalled It is an object type setOnStalled(java.lang.Runnable value)


property of the
interface Runnable.
It indicates the
Event Handler which
will be invoked
when the status
changed to Stalled.

onStopped It is an object type setOnStopped(java.lang.Runnable value)


property of the
interface Runnable.
It indicates the
EventHandler which
will be invoked
when the status
changed to Stopped.

rate It is the double type setRate(double value)


property. It indicates
the rate at which the
media should be
played.

startTime This property is of setStartTime(Duration value)


the type object of the
class Duration. It
indicates the time
where media should
start playing.

status This is the read only Can not be set as it is read only property.
property. It indicates
the current state of
the Media player.

stopTime This property is an setStopTime(double value)


object type of the
class Duration. It
indicates the time
offset where the
media should stop
playing.

totalDuration It is an object type Can not be set as it is read only property.


property of the class
Duration. It indicates
the total time during
which the media
should be played.

volume It is a double type setVolume(double value)


property. It indicates
the volume at which
the media should be
playing.

Constructors
The class contains only a single constructor which is given below.

public MediaPlayer (Media media)

You might also like