Checked vs Unchecked Exceptions in Java

karthikeya Boyini
Updated on 18-Jun-2020 13:13:42

8K+ Views

Checked exceptionsA checked exception is an exception that occurs at the compile time, these are also called as compile time exceptions. These exceptions cannot simply be ignored at the time of compilation, the programmer should take care of (handle) these exceptions.For example, if you use FileReader class in your program to read data from a file, if the file specified in its constructor doesn't exist, then a FileNotFoundException occurs, and the compiler prompts the programmer to handle the exception.ExampleLive Demoimport java.io.File; import java.io.FileReader; public class FilenotFound_Demo {    public static void main(String args[]) {         ... Read More

Check Internet Connectivity in Java

Samual Sam
Updated on 18-Jun-2020 13:09:30

6K+ Views

Internet connectivity can be checked using java.net.URL and java.net.URLConnection class. Following are the required steps.Create a URL object and pass it the URL say GoogleCall URL.openConnection() method to get a URLConnection object.Call URLConnection.connect() method to check the internet connectivity. connect() method opens a communications link to the resource referenced by the passed URL if a connection has not already been established.Exampleimport java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; public class Tester {    public static void main(String[] args) {       try {          URL url = new URL("http://www.google.com");          URLConnection connection ... Read More

What is the #define Preprocessor in C++

Jennifer Nicholas
Updated on 18-Jun-2020 13:05:52

577 Views

The #define creates a macro, which is the association of an identifier or parameterized identifier with a token string. After the macro is defined, the compiler can substitute the token string for each occurrence of the identifier in the source file.#define identifier token-stringThis is how the preprocessor is used. The #define directive causes the compiler to substitute token-string for each occurrence of identifier in the source file. The identifier is replaced only when it forms a token. That is, identifier is not replaced if it appears in a comment, in a string, or as part of a longer identifier.example#include #define ... Read More

Clone Method in Java

karthikeya Boyini
Updated on 18-Jun-2020 13:04:31

1K+ Views

Java provides an assignment operator to copy the values but no operator to copy the object. Object class has a clone method which can be used to copy the values of an object without any side-effect. Assignment operator has a side-effect that when a reference is assigned to another reference then a new object is not created and both the reference point to the same object. This means if we change the value in one object then same will reflect in another object as well. clone() method handles this problem. See the below example.ExampleLive Demopublic class Tester {    public ... Read More

Indent If-Else Statement in Python

Malhar Lathkar
Updated on 18-Jun-2020 13:04:11

869 Views

One of the characteristic features of Python is use of uniform indent to denote a block of statements. A block is initiated by − symbol As soon as − symbol is typed and enter pressed, any Python aware editor will take cursor to next line with increased indent. All lines entered subsequently will follow same level of indent. To signal end of block, indent level must be reduced by pressing backspace.Using above procedure give − after if statement and write statements in true block. Then dedent by backspace and write else − In another block of increased indent enter statements ... Read More

Set a Light Grey Border to an Element in Bootstrap 4

Kristi Castro
Updated on 18-Jun-2020 12:59:34

484 Views

To set a light grey border to an element, use the border border-light class in Bootstrap 4.Adding a light border is easy as shown below −   This element has light border You can try to run the following code to implement the border-light-class −ExampleLive Demo       Bootstrap Example                             .demo {       width: 150px;       height: 220px;       margin: 15px;     }             Demo     This element has light border  

Colon Operator in Python

Malhar Lathkar
Updated on 18-Jun-2020 12:59:27

9K+ Views

The : symbol is used for more than one purpose in PythonAs slice operator with sequence −The − operator slices a part from a sequence object such as list, tuple or string. It takes two arguments. First is the index of start of slice and second is index of end of slice. Both operands are optional. If first operand is omitted, it is 0 by default. If second is omitted, it is set to end of sequence.>>> a=[1, 2, 3, 4, 5] >>> a[1:3] [2, 3] >>> a[:3] [1, 2, 3] >>> a[2:] [3, 4, 5] >>> s='computer' >>> s[:3] ... Read More

Blank Final in Java

karthikeya Boyini
Updated on 18-Jun-2020 12:40:21

778 Views

In Java, a final variable can a be assigned only once. It can be assigned during declaration or at a later stage. A final variable if not assigned any value is treated as a blank final variable. Following are the rules governing initialization of a blank final variable.A blank instance level final variable cannot be left uninitialized.The blank Instance level final variable must be initialized in each constructor.The blank Instance level final variable cannot be initialized in class methods.A blank static final variable cannot be left uninitialized.The static final variable must be initialized in a static block.A static final variable cannot ... Read More

Callable and Future in Java

karthikeya Boyini
Updated on 18-Jun-2020 12:31:29

3K+ Views

java.util.concurrent.The callable object can return the computed result done by a thread in contrast to a runnable interface which can only run the thread. The Callable object returns a Future object which provides methods to monitor the progress of a task being executed by a thread. The future object can be used to check the status of a Callable and then retrieve the result from the Callable once the thread is done. It also provides timeout functionality.Syntax//submit the callable using ThreadExecutor //and get the result as a Future object Future result10 = executor.submit(new FactorialService(10));   //get the result using ... Read More

Convert PHP Array to JavaScript Array

Jennifer Nicholas
Updated on 18-Jun-2020 12:30:17

3K+ Views

You can use PHP array in JavaScript. It works for the single as well as the multidimensional array. Use the json_encode() method to achieve this.Let’s say Our PHP array is −$myArr = array('Amit', 'amit@example.com');Converting PHP array into JavaScript. var arr = ; Now, let’s finally learn how to access it to output the email −document.write(arr[1]);

Advertisements