0% found this document useful (0 votes)
2 views24 pages

Java

The document outlines the differences between scripting and programming languages, highlighting that scripting languages are platform-specific and interpreted, while programming languages are platform-independent and compiled. It also explains how to add JavaScript to HTML using embedding, inline, and external files, and provides various JavaScript programs for tasks such as calculating sums, checking even/odd numbers, and converting temperatures. Additionally, it includes PHP programs for swapping values, adding numbers, and finding prime numbers.

Uploaded by

amitpatel.game
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)
2 views24 pages

Java

The document outlines the differences between scripting and programming languages, highlighting that scripting languages are platform-specific and interpreted, while programming languages are platform-independent and compiled. It also explains how to add JavaScript to HTML using embedding, inline, and external files, and provides various JavaScript programs for tasks such as calculating sums, checking even/odd numbers, and converting temperatures. Additionally, it includes PHP programs for swapping values, adding numbers, and finding prime numbers.

Uploaded by

amitpatel.game
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

1.

Difference between scripting language and


programming language.
Scripting Language Programming Language
Scripting language are platform-specific 1 Programming language are platform
independent.
Most of the scripting languages are 2 Most of the programming language are
interpreted. complied.
Developer has to write less code 3 Developer has to write much code compared
compared to programming language. to scripting language.
Examples, JavaScript, VBScript 4 Examples, C, C++, Java etc.
Scripting languages run inside other 5 It is not dependent on other programs to run.
programs. It is dependent on other It is independent.
programming language.

[Link] between server side scripting and client side


scripting.
How can we add java-script to the html ?
JavaScript, also known as JS, is one of the client-side scripting languages, that is usually used in web
development to create modern and interactive web-pages.

we can add js in 3 different ways :-

1. Embedding code

2. Inline code

3. External file

1. Embedding code:- To add the JavaScript code into the HTML pages, we can use the
<Script>….</Script> tags of the HTML that wrap around JavaScript code inside the HTML
program.

2. Inline code:-
We can also place JavaScript code inline by inserting it directly inside the html tag using the
special tag events like onclick , on mouseover ,on keypress , onload , etc.
<HTML>
<HEAD>
<TITLE>INLINE JS</TITLE>
</HEAD>
<BODY>
<BUTTON onclick="alert('hello world')>Click me </BUTTON>
</BODY>
</HTML>
[Link] External file :-
We can also place our JS code into a separate file with a .js extension , and
then call that file in our document through the src attribute of the <script > tag, like this :
<script src="js/[Link]"></script>

<HTML>
<HEAD>
<TITLE>INLINE JS</TITLE>
<script src="js/[Link]"></script>
</HEAD>
<BODY>
<BUTTON onclick="sayhello()>Click me </BUTTON>
</BODY>
</HTML>
EXAMPLE OF SWITCH CASE
<html>
<head>
<title>Switch Case Example</title>
</head>
<body>
<input type="number" id="dayInput" min="1" max="7">
<button onclick="getDayName()">Get Day</button>
<p id="result"></p>
<script>
function getDayName() {
const day =
parseInt([Link]("dayInput").value);
switch (day) {
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
case 7:
dayName = "Sunday";
break;
default:
dayName = "Invalid day! Please enter a number from 1 to
7.";
}
[Link]("result").textContent = dayName;
}
</script>
</body>
</html>

[Link] a JavaScript program to input two numbers and find out its sum.

<head>
<title>
add
</title>
</head>
<body>
First number:<input type="number" id="num1" >
second number:<input type="number" id="num2" >
<br>
<div>
<button onclick="add()">sum</button>
</div>
<script>
function add(){
a =parseInt([Link]("num1").value);
b =parseInt([Link]("num2").value);
c=a+b;
[Link]("the sum of two number is : ",c);
}
</script>
</body>
</html>

[Link] a program to find the given number is even or odd.


<html >
<head>
<title>
Even or odd
</title>
</head>
<body>
Number:<input type="number" id="num1" >
<br>
<div>
<button onclick="bis()">clickme</button>
</div>
<script>
function bis(){
a = [Link]("num1").value;
c=a % 2;
if(c==0){
[Link]("the number is even");
}
else {
[Link]("number is odd");
}
}
</script>

</body>
</html>

WAP to calculate the simple interest using principal, rate and time.
<html>
<head>
<title>
simple interest
</title>
</head>
<body>
Principal:<input type="number" id="p" >
Rate:<input type="number" id="r" >
Time in years:<input type="number" id="t">
<br>
<button onclick="Si()">calculate</button>
<script>
function Si(){
pi = [Link]("p").value;
ra= [Link]("r").value;
ti= [Link]("t").value;
sim= (pi*ti*ra)/100;
[Link]("the simple intrest is : ",sim);
}
</script>
</body>
</html>
WAP to convert Fahrenheit to Celsius
head>
<title>
convert F to C
</title>
</head>
<body>
<div class="problem">
<h3>2. Convert Fahrenheit to Celsius</h3>
<label>Fahrenheit: <input type="number" id="fahrenheit"
/></label><br>
<button onclick="fahrenheitToCelsius()">Convert</button>

<script>
function fahrenheitToCelsius() {
let
fahrenheit=parseFloat([Link]('fahrenheit').value);
let celsius = (fahrenheit - 32) * (5 / 9);
[Link]("the conversion fahrenheit to celsius is :
",celsius);
}
</script>
</div>
</body>
</html>

program to check the given number is positive or negative.


<html>
<head>
<title> Positive or negative</title>
</head>
<body>
<div>
<label>Number: <input type="number" id="number1" /></label><br>
<button onclick="checkPositiveOrNegative()">Check</button>
<script>
function checkPositiveOrNegative() {
let num = parseFloat([Link]('number1').value);
let result = num >= 0 ? "Positive" : "Negative";
[Link]("the number is ",result);
}
</script>
</div>
</body>
</html>
Program to check the given number is even or odd .
<head>
<title>
Even or odd
</title>
</head>
<body>
<div>
Number: <input type="number" id="number2" /><br>
<button onclick="checkEvenOrOdd()">Check</button>
<script>
function checkEvenOrOdd() {
let num = parseFloat([Link]('number2').value);
let result = num % 2 === 0 ? "Even" : "Odd";
[Link]("the given number is ",result);
}
</script>
</div>
</body>
</html>

Find the greatest number between any 3 number.


<head>
<title>
Greatest between three number
</title>
</head>
<body>
First Number: <input type="number" id="number1" /><br>
Second Number: <input type="number" id="number2" /><br>
Third Number: <input type="number" id="number3" /><br>
<button onclick="great()">Check</button>
<script>
function great() {
let num1 = parseInt([Link]('number1').value);
let num2 = parseInt([Link]('number2').value);
let num3 = parseInt([Link]('number3').value);
let largest = [Link](num1, num2, num3);
[Link]("the largest number is ",largest);
}
</script>
</body>
</html>

Find the reversed of the given number


<head>
<title>
reverse
</title>
</head>
<body>
<div>
Number: <input type="number" id="number1" /><br>
<button onclick="reverseNumber()">Reverse</button>
<script>
function reverseNumber(){
let num = [Link]("number1").value;
let re = 0 ;
while ( num > 0 ){
d = num % 10 ;
re = re * 10 + d ;
num = [Link](n / 10 );
}
[Link]("the reverse is ",re);
</script>
</body>
</html>

find the factorial of given number


<head>
<title> facto </title>
</head>
<body>
Number: <input type="number" id="number1" /><br>
<button onclick="fact()">facto</button>
<script>
function fact(){
let num = [Link]("number1").value;
if (isNaN(num) || num < 0) {

[Link]("Please enter a valid non-negative number.");


return;
s=1
for(i=1;i<=num;i++){
let s=s*i;
}
[Link]("the factorial of given number is : ",s);
}
</script>
</div>
</body>
</html>
Find the largest and smallest number among 10 elements of an array.

<script>
function findLargestAndSmallest(arr) {
let largest = arr[0];
let smallest = arr[0];
for (let i = 1; i < [Link]; i++) {
if (arr[i] > largest) {
largest = arr[i];
}
if (arr[i] < smallest) {
smallest = arr[i];
}
}
[Link]("Largest number: " + largest);
[Link]("Smallest number: " + smallest);
}
</script>

Program to sorts the data of an array


<html>
<head>
<title>
sort the element
</title>
</head>
<body>
<button onclick="sortArray()">sort array</button>
<script>
function sortArray() {
const array = [34, 7, 23, 32, 5, 62];
[Link](function(a,b){
return a – b ;

}
</script>
</body>
</html>

Write a java script program to reverse the given string

<html>
<head>
<title>
reverse the element
</title>
</head>
<body>
<input type="text" id="userInput">
<button onclick="reverseInput()">Reversed</button>
<script>
function reverseInput() {
const input = [Link]("userInput").value;
if ([Link]() === "") {
[Link]("Enter the string ");
return;
}
const reversed = [Link]("").reverse().join("");
[Link]("the reversed word is ",reversed);
}
</script>
</body>
</html>
Count the vowel letter in a strings or word

<html>
<head>
<title>count</title>
</head>
<body>
<input type="text" id="userInput">
<button onclick="countVowels()">count</button>
<script>
function countVowels() {
str=[Link]("userInput").value;
const lowerStr = [Link]();
let vowelCount = 0;
for (let i = 0; i < [Link]; i++) {
if (['a', 'e', 'i', 'o', 'u'].includes(lowerStr[i])) {
vowelCount++;
}
}
[Link]("the number of vowel in the string is : ",vowelCount);
}
</script>
</body>
</html>
WAP to calculate the factorial of a number using the concept of recursion.

<html>
<head>
<title>Factorial Calculator</title>
</head>
<body>
<input type="number" id="userInput">
<button onclick="calculateFactorial()">Calculate Factorial</button>
<script>
function factorial(n) {
if (n === 0 || n === 1) {
return 1;
}
return n * factorial(n - 1);
}
function calculateFactorial() {
const n =
parseInt([Link]("userInput").value);
if (isNaN(n) || n < 0) {
[Link]("Enter a valid number");
return;
}
const result = factorial(n);
[Link]("the factorial of the given number is
",result);
}
</script>
</body>
</html>
PHP PROGRAMS:-
WRITE THE PHP PROGRAMS TO SWAP THE VALUES OF TWO VARIABLES.
<!DOCTYPE html>
<html lang="en">
<head>
<title>swaping values</title>
</head>
<body>
<form method="post">
first number :<input type="number" name="num1">
second number :<input type="number" name="num2">
<button name="submit">submit
</form>
<?php
if (isset($_POST['submit'])) {
$a = $_POST['num1'];
$b = $_POST['num2'];

$temp = $a;
$a = $b;
$b = $temp;
echo "After Swapping:";
echo "First Number: $a";
echo "Second Number: $b";
}
?>
</body>
</html>

PHP program to add two number


<html>
<head>
<title>ADD TWO NUMBERS</title>
</head>
<body>
<?php
$a = 2 ;
$b = 5 ;
$c= $a + $b ;
echo "The sum is :".$c

?>
</body>
</html>
PHP program find the number is even or odd
<html>
<head>
<title>ADD TWO NUMBERS</title>
</head>
<body>
<?php
$a = 7 ;
$c=$a % 2;
if ($c == 0) {
echo "The number is even"
}
else {
echo "The number is odd"
}
?>
</body>
</html>

PHP TO CALCULATE THE SUM OF NUMBER FROM 1 TO 10


<html>
<head>
<title>Sum of 1 to 10</title>
</head>
<body>
<?php
$sum = 0;
for ($i = 1; $i <= 10; $i++) {
$sum += $i;
}
echo "<p>The sum of numbers from 1 to 10 is: $sum</p>";
?>
</body>
</html>

PHP PROGRAM TO SUM OF ALL EVEN NUMBERS UP TO 100


<html>
<head>
<title>Sum of Even Numbers up to 100</title>
</head>
<body>
<?php
$sum = 0;
for ($i = 2; $i <= 100; $i += 2) {
$sum = $sum + $i;
}
echo "<p>The sum of all even numbers up to 100 is: $sum</p>";
?>
</body>
</html>

PHP PROGRAMS TO PRINT THE PRIME NUMBER LESS THAN 100


<html>
<head>
<title>Prime Numbers Less Than 100</title>
</head>
<body>
<?php
echo "<p>Prime numbers less than 100:</p>";
for ($i = 2; $i < 100; $i++) {
$isPrime = true;
for ($j = 2; $j <= sqrt($i); $j++) {
if ($i % $j == 0) {
$isPrime = false;
break;
}
}
if ($isPrime) {
echo $i . " ";
}
}
?>
</body>
</html>

HOW CAN WE USE ARRAY IN PHP DEMONSTRATE WITH A SUITABLE


EXAMPLE ?
An array is a data structure that stores one or more similar or dissimilar types of values In a
single value. There are three different kinds of array used in php they are,
1. Numeric array :- An array with a numeric index. Values are stored and accessed in linear
fashion , These arrays can store number ,string , and any object but their index will be
represented by numbers.
example:
<?php

echo "<h3>Indexed Array:</h3>";

$fruits = array("Apple", "Banana", "Orange");

foreach ($fruits as $fruit) {


echo $fruit . "<br>";
?>
}
[Link] array :
An array with string as index. This stores element values in association with key values
rather than in a strict linear index order.
Example:
<?php

echo "<h3>Associative Array:</h3>";


$student = array("Name" => "John", "Age" => 20, "Grade" => "A");
foreach ($student as $key => $value) {
echo "$key: $value<br>";
}
?>

[Link] array:-
An array containing one or more arrays and values are accessed using multiple indices.
Example :

<?php

$matrix = array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9)
);
for ($i = 0; $i < 3; $i++) {
for ($j = 0; $j < 3; $j++) {
echo $matrix[$i][$j] . " ";
}
echo "<br>";
}

WRITE A PHP PROGRAM TO PRINT THE LARGEST AND SMALLEST NUMBER AMONG 10
ELEMENT OF AN ARRAY

<?php

$numbers = array(23, 45, 12, 67, 34, 89, 2, 78, 56, 9);
$largest = $numbers[0];
$smallest = $numbers[0];
foreach ($numbers as $num) {
if ($num > $largest) {
$largest = $num;
}
if ($num < $smallest) {
$smallest = $num;
}
}
echo "<p>The largest number is: $largest</p>";
echo "<p>The smallest number is: $smallest</p>";
?>

PHP PROGRAM TO SORT THE DATA OF AN ARRAY


<html>
<head>
<title>Sorting Data in PHP</title>
</head>
<body>
<?php
$numbers = array(23, 12, 45, 67, 34, 89, 56, 2, 78, 9);
echo "<h3>Original Array:</h3>";
echo implode(", ", $numbers) . "<br>";
sort($numbers);
echo "<h3>Sorted Array in Ascending Order:</h3>";
echo implode(", ", $numbers) . "<br>";
rsort($numbers);
echo "<h3>Sorted Array in Descending Order:</h3>";
echo implode(", ", $numbers) . "<br>";
?>
</body>
</html>

PHP PROGRAM TO CHECK THE STRING IS PALINDROME OR NOT


<?php
function isPalindrome($string) {
$string = strtolower(str_replace(" ", "", $string));
$reversedString = strrev($string);
if ($string === $reversedString) {
echo "'$string' is a palindrome.";
} else {
echo "'$string' is not a palindrome.";
}
}
$isPalindromeString = $_POST['input'];
isPalindrome($isPalindromeString);
?>

1. What is Web Technology? Explain Static and Dynamic Web Pages.

Web Technology refers to the tools and techniques used to create, deliver, and manage web-
based applications. It includes protocols (HTTP, HTTPS), programming languages (HTML,
CSS, JavaScript), databases, and web servers.

Static Web Page:

 Displays the same content for all users.


 Written in HTML and CSS.
 No interaction or database connection.
 Example: A simple company info webpage.

Dynamic Web Page:

 Content changes based on user interaction or data.


 Built with server-side languages (e.g., PHP, Python) and client-side scripts (e.g.,
JavaScript).
 Connected to a database for personalized content.
 Example: Social media profiles.

2. Differentiate Between Server-Side and Client-Side Scripting Languages.

Feature Client-Side Scripting Server-Side Scripting

Execution Location Browser (client). Server.


Feature Client-Side Scripting Server-Side Scripting

Languages JavaScript, HTML, CSS. PHP, Python, Ruby.

Purpose User interface interactivity. Backend logic and database.

Speed Faster (no server delay). Slower (server processing).

Examples Form validation. User authentication.

3. What is the Importance of Scripts in Web Programming?

Scripts are essential for:

1. Interactivity: Enable dynamic user interaction (e.g., form validation, animations).


2. Client-Server Communication: Facilitate AJAX requests to update content without
reloading.
3. Backend Processing: Handle logic, database queries, and authentication.
4. Customization: Deliver personalized content to users.
5. Efficiency: Automate repetitive tasks, enhancing user experience.

5. What is JavaScript? Explain Major Features and Importance.

JavaScript is a lightweight, interpreted scripting language used for adding interactivity to web
pages.

Features:

1. Dynamic Typing: No need to specify variable types.


2. Event-Driven: Responds to user actions (click, hover).
3. Cross-Platform: Works on all browsers.
4. Asynchronous: Handles multiple tasks simultaneously (e.g., AJAX).
5. Object-Oriented: Supports objects and prototypes.

Importance:

 Enables interactive content.


 Works seamlessly with HTML and CSS.
 Widely used for front-end and back-end ([Link]).

6. What is OOP? Explain the Concept of OOP in JavaScript.


OOP (Object-Oriented Programming) is a paradigm where code is organized into objects with
properties (data) and methods (functions).

OOP Concepts in JavaScript:

1. Classes: Templates for creating objects.

class Person {
constructor(name) {
[Link] = name;
}
greet() {
return `Hello, ${[Link]}`;
}
}

2. Inheritance: Create subclasses from a parent class.


3. Encapsulation: Bundle data and methods.
4. Polymorphism: Override methods in subclasses.

What is an Event? List Any Four Popular Events.

Event: An event is any user action or system-generated occurrence that JavaScript can respond
to (e.g., clicking a button, loading a page).

Popular Events:

1. onclick: Triggered when an element is clicked.


2. onload: Triggered when a page or resource is fully loaded.
3. onmouseover: Triggered when the mouse hovers over an element.
4. onsubmit: Triggered when a form is submitted

You might also like