Java Articles

Page 317 of 450

Java labelled for loop

Vikyath Ram
Vikyath Ram
Updated on 15-Jun-2020 2K+ Views

Following program is using labeled for loops. Example public class Tester {     public static void main(String args[]) {                first:            for (int i = 0; i 

Read More

Java labelled statement

Kumar Varma
Kumar Varma
Updated on 15-Jun-2020 4K+ Views

Yes. Java supports labeled statements. You can put a label before a for statement and use the break/continue controls to jump to that label. Example See the example below. public class Tester {    public static void main(String args[]) {      first:          for (int i = 0; i 

Read More

Java labelled statement

Kumar Varma
Kumar Varma
Updated on 15-Jun-2020 4K+ Views

Yes. Java supports labeled statements. You can put a label before a for statement and use the break/continue controls to jump to that label. Example See the example below. public class Tester {    public static void main(String args[]) {      first:          for (int i = 0; i 

Read More

Java Conversions and Promotions

Paul Richard
Paul Richard
Updated on 15-Jun-2020 227 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 ...

Read More

Java Conversions and Promotions

Paul Richard
Paul Richard
Updated on 15-Jun-2020 227 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 ...

Read More

Java overflow and underflow

Arjun Thakur
Arjun Thakur
Updated on 15-Jun-2020 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 ...

Read More

Java overflow and underflow

Arjun Thakur
Arjun Thakur
Updated on 15-Jun-2020 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 ...

Read More

Java variable declaration best practices

Fendadis John
Fendadis John
Updated on 15-Jun-2020 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.

Read More

Java variable declaration best practices

Fendadis John
Fendadis John
Updated on 15-Jun-2020 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.

Read More

Why is Java slower than C++ programs?

Akshaya Akki
Akshaya Akki
Updated on 13-Jun-2020 1K+ Views

Modern Java is quite fast and is comparable to C++ code base but it still takes lot of memory. Slowness of Java programs is primarily because of bad programming practices. But following areas are where Java can be improved.Java libraries are written keeping readability and correctness in mind, not performance.Slow String based operations as Strings are UTF-16 encoded objects and are immutable. So more String are used, more memory is required.Boundary checks on arrays also make its operations bit slow.I/O Stream operations are slow considering synchronization checks on each access.Lacking low level functionality like C also attributes to slowness in ...

Read More
Showing 3161–3170 of 4,498 articles
« Prev 1 315 316 317 318 319 450 Next »
Advertisements