Mkotla has Published 77 Articles

How to write a global error handler in JavaScript?

mkotla

mkotla

Updated on 16-Jun-2020 11:40:30

2K+ Views

The following global error handler will show how to catch unhandled exception −Example                    window.onerror = function(errMsg, url, line, column, error) {             var result = !column ? '' : 'column: ' + column;             result += !error;             document.write("Error= " + errMsg + "url= " + url + "line= " + line + result);             var suppressErrorAlert = true;             return suppressErrorAlert;          };          setTimeout(function() {             eval("{");          }, 500)          

What is a default constructor in JavaScript?

mkotla

mkotla

Updated on 12-Jun-2020 14:04:17

871 Views

If a constructor method is not added, then a default constructor should be used. A default constructor is created when nothing is defined.SyntaxHere’s the syntax −constructor() {}The syntax for derived class −constructor(...args) {    super(...args); }

What is the basic syntax to access Python Dictionary Elements?

mkotla

mkotla

Updated on 05-Mar-2020 10:02:01

249 Views

You can access a dictionary value to a variable in Python using the access operator []. examplemy_dict = {    'foo': 42, 'bar': 12.5 } new_var = my_dict['foo'] print(new_var)OutputThis will give the output −42You can also access the value using the get method on the dictionary. examplemy_dict = {    'foo': 42, ... Read More

HTML5 check if audio is playing

mkotla

mkotla

Updated on 04-Mar-2020 04:59:44

5K+ Views

Use the following to check if audio is playing −functionisPlaying(audelem) {    return!audelem.paused; }The above code can be used to check ifaudio is playing or not. The audio tag has a paused property.The paused property returns whether the audio/video is paused.You can also toggle −functiontogglePause() {    if(newAudio.paused && newAudio.currentTime > 0 ... Read More

Execute a script after the document is printed in HTML?

mkotla

mkotla

Updated on 03-Mar-2020 12:31:48

294 Views

Use the HTML onafterprint attribute to execute a script after the document is printed or it is printing.ExampleYou can try to run the following code to implement onafterprint attribute −                    function display() {             alert("Success!");          }          

Set the shape of the area in HTML

mkotla

mkotla

Updated on 03-Mar-2020 11:10:57

182 Views

Use the shape attribute to set the shape of the area in HTML. You can try to run the following code to implement shape attribute −Example           HTML shape attribute                                              

How to specify that the element should automatically get focus when the page loads in HTML?

mkotla

mkotla

Updated on 02-Mar-2020 12:43:31

297 Views

Use the autofocus attribute to specify that the element should get focus automatically on page load in HTML −ExampleYou can try to run the following code to learn how to implement autofocus attribute in HTML −           Click on the below button to generate an alert box.       Result    

How multiple inheritance is implemented using interfaces in Java?

mkotla

mkotla

Updated on 25-Feb-2020 12:33:24

2K+ Views

Java does not support multiple inheritance. This means that a class cannot extend more than one class. Therefore, following is illegal −Examplepublic class extends Animal, Mammal{}However, a class can implement one or more interfaces, which has helped Java get rid of the impossibility of multiple inheritance.The extends keyword is used ... Read More

How can I clear or empty a StringBuilder in Java.

mkotla

mkotla

Updated on 24-Feb-2020 12:21:39

3K+ Views

You can either setLength to be 0 or create a new StringBuilder() instance. See the example below −Examplepublic class Tester {    public static void main(String[] args) {       StringBuilder builder = new StringBuilder();       builder.append("sample");       System.out.println(builder.toString());       builder.setLength(0);     ... Read More

How to install JDK in Windows and set up the environment variables?

mkotla

mkotla

Updated on 18-Feb-2020 07:53:47

2K+ Views

Download the latest version of Java from the official site. Run the .exe to install Java on your machine. Once you installed Java on your machine, you will need to set environment variables to point to correct installation directories −Setting Up the Path for Windows:Assuming you have installed Java in ... Read More

Advertisements