0% found this document useful (0 votes)
6 views8 pages

JAVASCRIPT

JavaScript is a dynamic, interpreted programming language used for interactive web applications, supporting both client-side and server-side development. It allows for the creation of objects using object literals or constructors and integrates with HTML and CSS to create dynamic web pages. Additionally, Java Applets, though now deprecated, were small Java programs that ran in web browsers, enhancing interactivity before being largely replaced by modern web technologies.

Uploaded by

gagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views8 pages

JAVASCRIPT

JavaScript is a dynamic, interpreted programming language used for interactive web applications, supporting both client-side and server-side development. It allows for the creation of objects using object literals or constructors and integrates with HTML and CSS to create dynamic web pages. Additionally, Java Applets, though now deprecated, were small Java programs that ran in web browsers, enhancing interactivity before being largely replaced by modern web technologies.

Uploaded by

gagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

avaScript is a versatile, dynamically typed programming language used

for interactive web applications, supporting both client-side and server-


side development, and integrating seamlessly with HTML, CSS, and a rich
standard library.
 JavaScript is a single-threaded language that executes one task at a
time.
 It is an Interpreted language which means it executes the code line by
line.
 The data type of the variable is decided at run-time in JavaScript that’s
why it is called dynamically typed.

“Hello, World!” Program in Browser Console


A “Hello, World!” program is the simplest way to get started with any
programming language. Here’s how you can write one using JavaScript.
<html>
<head></head>
<body>
<h1>Check the console for the message!</h1>
<script>
// This is our first JavaScript program
console.log("Hello, World!");
</script>
</body>
</html>
In this example
 The<script> tag is used to include JavaScript code inside an HTML
document.
 console.log() prints messages to the browser’s developer console.
Open the browser console to see the “Hello, World!” message.
bjects in Javascript
Last Updated : 07 Mar, 2025



An object in JavaScript is a data structure used to store related data


collections. It stores data as key-value pairs, where each key is a unique
identifier for the associated value. Objects are dynamic, which means the
properties can be added, modified, or deleted at runtime.
There are two primary ways to create an object in JavaScript: Object
Literal and Object Constructor.
1. Creation Using Object Literal
The object literal syntax allows you to define and initialize an object with
curly braces {}, setting properties as key-value pairs.
let obj = {
name: "Sourav",
age: 23,
job: "Developer"
};
console.log(obj);

Output
{ name: 'Sourav', age: 23, job: 'Developer' }

2. Creation Using new Object() Constructor


let obj = new Object();
obj.name= "Sourav",
obj.age= 23,
obj.job= "Developer"

console.log(obj);

Output
{ name: 'Sourav', age: 23, job: 'Developer' }

DHTML stands for Dynamic HTML. Dynamic means that the content of
the web page can be customized or changed according to user inputs i.e.
a page that is interactive with the user. In earlier times, HTML was used to
create a static page. It only defined the structure of the content that was
displayed on the page. With the help of CSS, we can beautify the HTML
page by changing various properties like text size, background color, etc.
The HTML and CSS could manage to navigate between static pages but
couldn’t do anything else. If 1000 users view a page that had their
information for eg. Admit card then there was a problem because 1000
static pages for this application build to work. As the number of users
increases, the problem also increases, and at some point, it becomes
impossible to handle this problem. To overcome this problem, DHTML
came into existence. DHTML included JavaScript along with HTML and
CSS to make the page dynamic. This combo made the web pages
dynamic and eliminated the problem of creating static pages for each
user. To integrate JavaScript into HTML, a Document Object Model(DOM)
is made for the HTML document. In DOM, the document is represented as
nodes and objects which are accessed by different languages like
JavaScript to manipulate the document.
DHTML JavaScript

HTML document include JavaScript:: The JavaScript document is


included in our html page using the html tag. <src> tag is used to specify
the source of external JavaScript file. Following are some of the tasks that
can be performed with JavaScript:
 Performing html tasks
 Performing CSS tasks
 Handling events
 Validating inputs
Example 1: Example to understand how to use JavaScript in DHTML.
 HTML

<h1>

GeeksforGeeks

</h1>

<p id = "geeks">

Hello Geeks!

</p>

<script>
document.getElementById("geeks").innerHTML =

"A computer science portal for geeks";

</script>

Output:

Explanation: In the above example, change the text of the paragraph


using id. A document is an object of HTML that is displayed in the current
window or object of DOM. The getElementById(id) gives the element id.
The innerHTML defines the content within the id element. The id attribute
is used to change an HTML document and its property. Paragraph content
changed by document id. For example
document.getElementById(“geeks”).style.color = “blue”; It is used to set
the paragraph color using the id of elements.

Java Applets was once a very popular feature of web applications. Java
Applets were small programs written in Java that ran inside a web
browser. Learning about Applet helps us understand how Java has
evolved and how it handles graphics.
Note: java.applet package has been deprecated in Java 9 and later
versions, as applets are no longer widely used on the web.
Java Applets
A Java Applet is a Java program that runs inside a web browser. An
Applet is embedded in an HTML file using <applet> or <objects> tags.
Applets are used to make the website more dynamic and entertaining.
Applets are executed in a sandbox for security, restricting access to local
system resources.
Key Points:
 Applet Basics: Every applet is a child/subclass of the
java.applet.Applet class.
 Not Standalone: Applets don’t run on their own like regular Java
programs. They need a web browser or a special tool called the applet
viewer (which comes with Java).
 No main() Method: Applets don’t start with main() method.
 Display Output: Applets don’t use System.out.prinln() for displaying
the output, instead they use graphics methods like drawString() from
the AWT (Abstract Window ToolKit) .
Java Applet Life Cycle
The below diagram demonstrates the life cycle of Java Applet:

It is important to understand the order in which the various methods


shown in the above image are called.
 When an applet begins, the following methods are called, in this
sequence:
o init( )
o start( )
o paint( )
 When an applet is terminated, the following sequence of method calls
takes place:
o stop( )
o destroy( )
Let’s look more closely at these methods.
1. init( ): The init( ) method is the first method to be called. This is where
you should initialize variables. This method is called only once during the
run time of your applet.
2. start( ): The start( ) method is called after init( ). It is also called to
restart an applet after it has been stopped.
Note: init( ) is called once i.e. when the first time an applet is loaded
whereas start( ) is called each time an applet’s HTML document is
displayed onscreen. So, if a user leaves a web page and comes back, the
applet resumes execution at start( )
3. paint( ): The paint( ) method is called each time an AWT-based
applet’s output must be redrawn. This situation can occur for several
reasons. For example, the window in which the applet is running may be
overwritten by another window and then uncovered. Or the applet window
may be minimized and then restored.
 paint( ) is also called when the applet begins execution. Whatever the
cause, whenever the applet must redraw its output, paint( ) is called.
 The paint( ) method has one parameter of type Graphics. This
parameter will contain the graphics context, which describes the
graphics environment in which the applet is running. This context is
used whenever output to the applet is required.
 paint() is the only method among all the methods mention above
(which is parameterized).
Event Types
JavaScript supports a variety of event types. Common categories include:
 Mouse Events: click, dblclick, mousemove, mouseover, mouseout
 Keyboard Events: keydown, keypress, keyup
 Form Events: submit, change, focus, blur
 Window Events: load, resize, scroll
Common JavaScript Events
Event Attribute Description

onclick Triggered when an element is clicked.

onmouseover Fired when the mouse pointer moves over an element.

onmouseout Occurs when the mouse pointer leaves an element.

onkeydown Fired when a key is pressed down.


Event Attribute Description

onkeyup Fired when a key is released.

onchange Triggered when the value of an input element changes.

onload Occurs when a page has finished loading.

onsubmit Fired when a form is submitted.

onfocus Occurs when an element gets focus.

onblur Fired when an element loses focus.

AWT (Abstract Window Toolkit) is not used in JavaScript — it's a part of Java, specifically for creating
graphical user interfaces (GUIs) in desktop applications. JavaScript, on the other hand, is used
primarily in web development for creating interactive web pages. However, if you're looking for
JavaScript equivalents to AWT-style GUI programming, here's how the comparison works:

🖥️AWT in Java vs. GUI in JavaScript


Feature Java (AWT) JavaScript (Web UI)

HTML elements (<button>, <div>,


GUI Toolkit AWT (Button, Frame, Label, etc.)
<input>)

Rendering Native OS GUI Web browser rendering engine

Layout Managers (e.g.,


Layout Control CSS (e.g., Flexbox, Grid)
FlowLayout)

ActionListener, addEventListener('click', ...) in


Event Handling
MouseListener, etc. JS

Component HTML + CSS + JavaScript libraries (e.g.,


Built-in Java classes
Library React)
import java.awt.*;
import java.awt.event.*;

public class MyApp {


public static void main(String[] args) {
Frame f = new Frame("My AWT App");
Button b = new Button("Click Me");
b.setBounds(100, 100, 80, 30);
b.addActionListener(e -> System.out.println("Button Clicked"));
f.add(b);
f.setSize(300, 200);
f.setLayout(null);
f.setVisible(true);
}
}

You might also like