Spread the love

Empty Statements in Java

Spread the love

Empty Statements in Java
Empty Statements in Java

Empty Statements in Java:

An empty statement in java consists of only a semicolon(;) It tells JVM not to do anything.
It is particularly useful while implementing delays in the code.

Few Examples of Empty Statements:


if(x<0){
x=-x;
};
//it is legal in java but JVM will consider this an empty statement

another example:


if(done)
;//empty statement
else
System.out.println("Oh no");
// it is equivalent to
if(done)
{}//empty statement
else
System.out.println("Oh no");

Interesting one:


for(int i=0;i<10;i++);
System.out.println("Hello");
//it will print Hello only once.

As we have put the semicolon at the end of the for loop. JVM will consider this as the empty statement and it is equivalent to:


for(int i=0;i<10;i++){
; //empty statement
}
System.out.println("Hello");

for creating delay:


for(int i=0;i<1000;i++){
for(int j=0;i<10000;i++){
;
}
}




Spread the love
READ  How to Communicate Using TCP/IP In Java
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...

EDITOR PICKS


Spread the love