Java Conversions and Promotions

Paul Richard
Updated on 15-Jun-2020 05:55:04

206 Views

We can convert one data types into another data type using casting. Narrowing ConversionNarrowing refers to passing a higher size data type like int to a lower size data type like short. It may lead to data loss. Following program output will be 44.public class MyFirstJavaProgram {    public static void main(String []args) {       int a = 300;       byte b = (byte)a; // narrowing       System.out.println(b);    } }Widening/Promotion ConversionWidening refers to passing a lower size data type like int to a higher size data type like long. public class MyFirstJavaProgram {    public ... Read More

Java Overflow and Underflow

Arjun Thakur
Updated on 15-Jun-2020 05:47:33

4K+ Views

OverflowOverflow occurs when we assign such a value to a variable which is more than the maximum permissible value.UnderflowUnderflow occurs when we assign such a value to a variable which is less than the minimum permissible value.JVM does not throw any exception in case Overflow or underflow occurs, it simply changes the value. Its programmer responsibility to check the possibility of an overflow/underflow condition and act accordingly. Example (Overflow)Consider the case of int variable, it is of 32 bit and any value which is more than Integer.MAX_VALUE (2147483647) is rolled over. For example, Integer.MAX_VALUE + 1 returns -2147483648 (Integer.MIN_VALUE).As int data ... Read More

Java Variable Declaration Best Practices

Fendadis John
Updated on 15-Jun-2020 05:46:54

2K+ Views

Following are the best practices while declaring a variable.Variables names should be short or long enough as per the scope. For example, loop counter variable, i is fine whereas employee as a loop variable.Specific words should not be used as equals, compare, data.Use meaningful names which can explain the purpose of the variable. For example cnt Vs counter.Don't use _ to declare a variable name, Use camel casing. For example, employeeName is better than employee_name.Each organization has its own syntax specific standards. Follow those rules to maintain consistency and readability.

Avoid Increment (++) and Decrement (--) Operators in JavaScript

Rahul Sharma
Updated on 15-Jun-2020 05:41:11

525 Views

The increment and decrement operators should be avoided since it can lead to unexpected results. Here are some of the conditions:In an assignment statement, it can lead to unfavorable results:ExampleLive Demo                    var a = 5;          var b = ++a; var c = a++;          var d = ++c;          document.write(a);          document.write("\r"+b);          document.write("\r"+c);          document.write("\r"+d);           OutputWhitespace between the operator and variable can also lead to unexpected results:a = b = c = 1; ++a ; b -- ; c;

Increment (++) Operator in JavaScript

Amit Sharma
Updated on 15-Jun-2020 05:39:26

785 Views

The increment operator increases an integer value by one. Here’s an example where the value of a is incremented twice using the increment operator twiceExampleLive Demo                    var a = 33;          a = ++a;          document.write("++a = ");          result = ++a;          document.write(result);          

Check for Not Defined Variable in JavaScript

Rahul Sharma
Updated on 15-Jun-2020 05:26:32

292 Views

To check a variable is ‘undefined’, you need to check using the following. If the result is “false”, it means the variable is not defined. Here, the variable results in “True” −ExampleLive Demo                    var points = 100;             if(points){                document.write("True");             }else{                document.write("False");             }          

Difference Between var functionName() and function functionName() in JavaScript

Johar Ali
Updated on 15-Jun-2020 05:25:58

393 Views

functionDisplayOne is a function expression, however, functionDisplayTwo is a function declaration. It is defined as soon as its surrounding function is executed.Both the ways are used to declare functions in JavaScript and functionDisplayOne is an anonymous function.Here’s the function expression −functionDisplayOne(); var functionDisplayOne = function() {    console.log("Hello!"); };The following is the function declaration −functionDisplayTwo(); function functionDisplayTwo() {    console.log("Hello!"); }

Generate Random Whole Numbers in JavaScript in a Specific Range

Amit Sharma
Updated on 15-Jun-2020 05:25:14

295 Views

To generate a random number, use the JavaScript Math.random() method. Here set the minimum and maximum value and generate a random number between them as in the following code −ExampleLive Demo                    var max = 6          var min = 2          var random = Math.floor(Math.random() * (max - min + 1)) + min;          document.write(random)          

SAP Associate Level Exam Preparation

Sharon Christine
Updated on 13-Jun-2020 14:45:10

144 Views

First, let me make your core basics clear.When you are referring to SAP ECC, you are referring to SAP ERP Central Component which is more or less equivalent to the prior SAP R3 System.  ABAP does not play any much part over here.But ABAP resides in the kernel of SAP which is referred to SAP BASIS.Speaking about your pointers for referenceHorst Keller - ABAP objects (For ABAP)Help.SAP.com  - (overall SAP)SAP ECC 6.0 Black book Then there are blogs, Q&A, and other online help always available. You can start from anywhere and when you move along, you will discover online assets as ... Read More

Use jQuery wrapAll to Wrap Multiple Elements

Amit D
Updated on 13-Jun-2020 14:41:16

2K+ Views

To wrap multiple elements in jQuery, use the wrapAll() method. The wrapAll( ) method wraps all the elements in the matched set into a single wrapper element.Here is the description of all the parameters used by this method:html − A string of HTML that will be created on the fly and wrapped around each target.ExampleYou can try to run the following code to learn how to use jQuery.wrapAll() method to wrap multiple elements −Live Demo           jQuery wrap() method                              $(document).ready(function() ... Read More

Advertisements