Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Jai Janardhan
40 articles
How Server-Sent Events Works in HTML5?
Server-sent events standardize how we stream data from the server to the client. To use Server-Sent Events in a web application, you would need to add an element to the document.The src attribute of element should point to an URL which should provide a persistent HTTP connection that sends a data stream containing the events.The URL would point to a PHP, PERL or any Python script which would take care of sending event data consistently. Following is a simple example of web application which would expect server time.You can try to run the following code to learn how ...
Read MoreHow to work with document.embeds in JavaScript?
Use the document.embeds property in JavaScript to get the number of tags in a document.ExampleYou can try to run the following code to implement document.embeds property in JavaScript. JavaScript Example var num = document.embeds.length; document.write("How many embed tags: "+num);
Read MoreDemonstrate static variables, methods and blocks in Java
The static variable is a class level variable and it is common to all the class objects i.e. a single copy of the static variable is shared among all the class objects.A static method manipulates the static variables in a class. It belongs to the class instead of the class objects and can be invoked without using a class object.The static initialization blocks can only initialize the static instance variables. These blocks are only executed once when the class is loaded.A program that demonstrates this is given as follows:Examplepublic class Demo { static int x = 10; static ...
Read MoreHow to use the asList() method of the Arrays class to create a Vector object
A Vector can be created from an Array using the java.util.Arrays.asList() method.A program that demonstrates this is given as follows:Exampleimport java.util.Arrays; import java.util.Vector; public class Demo { public static void main(String args[]) { Integer[] arr = { 3, 1, 9, 6, 4, 8, 7 }; Vector vec = new Vector(Arrays.asList(arr)); System.out.println("The Vector elements are: " + vec); } }OutputThe Vector elements are: [3, 1, 9, 6, 4, 8, 7]Now let us understand the above program.The Integer Array arr[] is defined. Then a Vector is created using the Arrays.asList() ...
Read MoreCreating a Multilevel Inheritance Hierarchy in Java
Inheritance involves an object acquiring the properties and behaviour of another object. So basically, using inheritance can extend the functionality of the class by creating a new class that builds on the previous class by inheriting it.Multilevel inheritance is when a class inherits a class which inherits another class. An example of this is class C inherits class B and class B in turn inherits class A.A program that demonstrates a multilevel inheritance hierarchy in Java is given as follows:Exampleclass A { void funcA() { System.out.println("This is class A"); } } class B extends A ...
Read MoreWhat is Default access level in Java?
The default access level is available when no access level is specified. All the classes, data members, methods etc. which have the default access level can only be accessed inside the same package.A program that demonstrates the default access level in Java is given as follows:Exampleclass Employee { int empno; String name; void insert(int e, String n) { empno = e; name = n; } void display() { System.out.println("Employee Number: " + empno); System.out.println("Name: " + name); } } public class Demo ...
Read MoreLoop through the Vector elements using an Iterator in Java
An Iterator can be used to loop through the Vector elements. The method hasNext( ) returns true if there are more elements in the Vector and false otherwise. The method next( ) returns the next element in the Vector and throws the exception NoSuchElementException if there is no next element.A program that demonstrates this is given as follows −Exampleimport java.util.Iterator; import java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(); vec.add(4); vec.add(1); vec.add(3); vec.add(9); ...
Read MoreFind the minimum element of a Vector in Java
The minimum element of a Vector can be obtained using the java.util.Collections.min() method. This method contains a single parameter i.e. the Vector whose minimum element is determined and it returns the minimum element from the Vector.A program that demonstrates this is given as follows −Exampleimport java.util.Collections; import java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(); vec.add(7); vec.add(3); vec.add(9); vec.add(5); vec.add(8); System.out.println("The Vector elements are: " + vec); ...
Read MoreSwap two variables in one line in Java
In order to swap two variable using single expression or in single line we could use bitwise XOR operator of Java. As we now that in Java XOR functions as XOR of two numbers a and b returns a number which has all the bits as 1 wherever bits of a and b differs. So for swapping of two variable we would use this operator as Example public class SwapUsingBitwise { public static void main(String[] args) { int a = 8 ; int b = 10; ...
Read MoreWhat are final, abstract, synchronized non-access modifiers in Java?
The abstract keyword is used to declare methods abstract methods and abstract classes. Once a method is declared abstract we should not specify body for those. And once a class is declared abstract it cannot be instantiated. Example abstract class Employee { private String name; private String address; private int number; public Employee(String name, String address, int number) { System.out.println("Constructing an Employee"); this.name = name; ...
Read More