Comparing Enum Members in Java

karthikeya Boyini
Updated on 18-Jun-2020 14:54:47

16K+ Views

The java.lang.Enum class is the common base class of all Java language enumeration types.Class DeclarationFollowing is the declaration for java.lang.Enum class -public abstract class Enum    extends Object       implements Comparable, SerializableWe can compare enum variables using the following ways.Using Enum.compareTo() method. compareTo() method compares this enum with the specified object for order.Using Enum.equals() method. equals() method returns true if the specified object is equal to this enum constant.Using == operator. The == operator checks the type and makes a null-safe comparison of the same type of enum constants.ExampleLive Demopublic class Tester {    // enum showing topics ... Read More

Comparison of Autoboxed Integer Object in Java

Samual Sam
Updated on 18-Jun-2020 14:52:30

357 Views

When we assigned an int to Integer object, it is first converted to an Integer Object and then assigned. This process is termed as autoboxing. But there are certain things which you should consider while comparison of such objects using == operator. See the below example first.ExampleLive Demopublic class Tester {    public static void main(String[] args) {       Integer i1 = new Integer(100);       Integer i2 = 100;               //Scenario 1:       System.out.println("Scenario 1: " + (i1 == i2));       Integer i3 = ... Read More

Comparison of Double and Float Primitive Types in Java

karthikeya Boyini
Updated on 18-Jun-2020 14:50:29

754 Views

If we compare a float and a double value with .5 or .0 or .1235 (ending with 5 or 0), then == operator returns true, otherwise it will return false. See the below example.ExampleLive Demopublic class Tester {    public static void main(String[] args) {       double d1 = 2.5;       float f1 = 2.5f;       System.out.println(d1 == f1);       double d2 = 2.4;       float f2 = 2.4f;       System.out.println(d2 == f2);    } }Outputtrue falseThe reason behind this logic is the approximation of float and ... Read More

Compilation and Execution of Java Program

Samual Sam
Updated on 18-Jun-2020 14:46:45

18K+ Views

Let us look at a simple code first that will print the words Hello World.ExampleLive Demopublic class MyFirstJavaProgram {    /* This is my first java program.        * This will print 'Hello World' as the output        */    public static void main(String []args) {       System.out.println("Hello World"); // prints Hello World    } }Let's look at how to save the file, compile, and run the program. Please follow the subsequent steps −Open notepad and add the code as above.Save the file as: MyFirstJavaProgram.java.Open a command prompt window and go to ... Read More

Compound Assignment Operators in Java

karthikeya Boyini
Updated on 18-Jun-2020 14:44:15

1K+ Views

The Assignment OperatorsFollowing are the assignment operators supported by Java language −OperatorDescriptionExample=Simple assignment operator. Assigns values from right side operands to left side operand.C = A + B will assign value of A + B into C+=Add AND assignment operator. It adds right operand to the left operand and assigns the result to left operand.C += A is equivalent to C = C + A-=Subtract AND assignment operator. It subtracts the right operand from the left operand and assigns the result to left operand.C -= A is equivalent to C = C � A*=Multiply AND assignment operator. It multiplies right ... Read More

Bootstrap 4 d-flex Class Implementation

David Meador
Updated on 18-Jun-2020 14:37:41

294 Views

Use the d-flex class in Bootstrap to create a flexbox container.Here, I have set two flex items −     One   Two You can try to run the following code to implement the .d-flex class −ExampleLive Demo       Bootstrap Example                             Understanding Flex             One       Two      

Bootstrap 4 Card Group Class

David Meador
Updated on 18-Jun-2020 14:35:59

431 Views

Use the card-group class to create a group of cards in Bootstrap 4 −                         Let us create a group of cards like a grid in Bootstrap −ExampleLive Demo       Bootstrap Example                             Group of Messages                             Argentina won convincingly!                                       Demo Text!                                       Do not cross!                                       I did it!                                       It worked!                    

Bootstrap Modal Toggle Method

David Meador
Updated on 18-Jun-2020 14:33:59

2K+ Views

Use the .modal(“toggle”) method in Bootstrap to toggle the modal.As shown below, the modal generates on the click of a button −$(document).ready(function(){   $("#button1").click(function(){     $("#newModal").modal("toggle");   }); });Here is the button used above −   Modal One You can try to run the following code to implement the modal(“toggle”) method −ExampleLive Demo       Bootstrap Example                             Sample     Modal One                                         ×             Sample Modal                                 Click outside to close it.                                 Close                                   $(document).ready(function(){     $("#button1").click(function(){       $("#newModal").modal("toggle");     });   });  

Create a Grid of Bootstrap 4 Cards

David Meador
Updated on 18-Jun-2020 14:31:59

369 Views

To set a container for Bootstrap card and set it like a group, use the card-group class.Use it and create a grid like the following with two Bootstrap cards −             Demo Text!                          Warning!           The following is an example to create a grid (group of cards) in Bootstrap −ExampleLive Demo       Bootstrap Example                             Group of Messages                             Demo Text!                                       Warning!                                        Well done!                                       Selected!                        

Bootstrap 4 Flex Wrap Class

Alex Onsman
Updated on 18-Jun-2020 14:29:50

2K+ Views

Use the flex-wrap class in Bootstrap 4 to wrap flex items. The following is the code snippet to wrap the flex items −   .   .  

Advertisements