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 Rishi Raj
77 articles
How to use splash vector graphics on your Responsive Site?
Graphics for your responsive site can make it slower, but balancing it with vector graphics can help in minimizing the bandwidth. Through this, amazing graphics work great on mobile site too. Generally, canvas and SVG is used for this purpose.Use HTML5 Scalable Vector Graphics (SVG) to create a design for multiple screen sizes, since it handles it perfectly. Easily present vector based line drawings and do not worry about the pixels on your device since the graphics created with SVG are resolution independent. It scales the result and looks great in the browser.Here, we will look how to work with ...
Read MoreHow to use JavaScript to redirect an HTML page?
You might have encountered a situation where you clicked a URL to reach a page X but internally you were directed to another page Y. It happens due to page redirection.It is quite simple to do a page redirect using JavaScript on the client side. To redirect your site visitors to a new page, you just need to add a line in your head section as follows.You can try to run the following code to learn how to use JavaScript to redirect an HTML page. Here, we will redirect to the homepageExample ...
Read MoreInstance variables in Java
Instance variables are declared in a class, but outside a method, constructor or any block.When space is allocated for an object in the heap, a slot for each instance variable value is created.Instance variables are created when an object is created with the use of the keyword 'new' and destroyed when the object is destroyed.Instance variables hold values that must be referenced by more than one method, constructor or block, or essential parts of an object's state that must be present throughout the class.Instance variables can be declared at the class level before or after use.Access modifiers can be given ...
Read MoreHow to extract the first n characters from a string using Java?
To find the consonants in the given String compare every character in it using the charAt() method with the vowel letters and remaining are consonants.Examplepublic class FindingConsonants { public static void main(String args[]) { String str = new String("Hi Welcome to Tutorialspoint"); for(int i=0; i
Read MoreHow to use JavaScript to hide a DIV when the user clicks outside of it?
To hide a div when the user clicks outside of it, try to run the following codeExample window.onload = function(){ var hideMe = document.getElementById('hideMe'); document.onclick = function(e){ if(e.target.id !== 'hideMe'){ hideMe.style.display = 'none'; } }; }; Click outside this div and hide it.
Read MoreInitializer for final static field in Java
The final static field variable is a constant variable. There is only one copy of this variable available. It is mandatory to initialize the final static field variable explicitly as the default value for it is not provided by the JVM. Also, this variable cannot be reinitialized.A program that initializes the final static field variable using a static initialization block is given as follows:Examplepublic class Demo { final static int num; static { System.out.println("Running static initialization block."); num = 6; } public static void main(String[] args) { ...
Read MoreFinding all words that start with an 'a' in Java
All the words that start with a can be found in a string by using regular expressions in Java. The regular expressions are character sequences that can be used to match other strings using a specific pattern syntax. The regular expressions are available in the java.util.regex package which has many classes but the most important are Pattern class and Matcher class.A program that finds all words that start with an 'a' is using regular expressions is given as follows:Exampleimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) throws Exception { String str ...
Read MoreA Reluctant qualifier in Java Regular Expressions
The reluctant qualifier starts with the shortest string size as possible. If a match is found by the engine, the process continues to find more matches otherwise the engine adds a character to the searched string section and tries again. This continues until a match is obtained or the string is used up.The regex "B+?" is used to find the match in the string "SkyIsBlue".A program that demonstrates this is given as follows:Exampleimport java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { String regex = "B+?"; String str = ...
Read MoreWhy variables are declared final in Java
A variable cannot be modified after it is declared as final. In other words, a final variable is constant. So, a final variable must be initialized and an error occurs if there is any attempt to change the value.A program that demonstrates a final variable in Java is given as follows −Examplepublic class Demo { public static void main(String[] args) { final double PI = 3.141592653589793; System.out.println("The value of pi is: " + PI); } }OutputThe value of pi is: 3.141592653589793Now let us understand the above program.In the main() method in class ...
Read MoreDuplicating Objects using a Constructor in Java
A copy constructor can be used to duplicate an object in Java. The copy constructor takes a single parameter i.e. the object of the same class that is to be copied. However, the copy constructor can only be explicitly created by the programmer as there is no default copy constructor provided by Java.A program that demonstrates this is given as follows −Exampleclass NumberValue { private int num; public NumberValue(int n) { num = n; } public NumberValue(NumberValue obj) { num = obj.num; } public void display() { ...
Read More