answersLogoWhite

0

What is java block?

Updated: 10/25/2022
User Avatar

Wiki User

13y ago

Best Answer

A Java block is a section of code enclosed within curly braces {} within a method. For example, here is a segment of code with several blocks:

public static void main(String[] args) {

for(int i = 0; i < 5; i++) {

System.out.println("Inside a for loop block for the " + i + "th time");

}

if(System.currentTimeInMillis() > 1000) {

// Inside a if block

}

}

Some other blocks are: switch blocks, case blocks, for-each blocks, while blocks, and anomonous methods and classes (and all the methods and blocks inside.)

I hope that answers your question.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is java block?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are block of statements in java?

In computer programming, a block or code block is a lexical structure of source code which is grouped together. In Java it is sed in the same way: to group code and separate it from the rest.


Why do you use synchronized block in java?

A Synchronized block is a block of code enclosed by the {} braces that has a synchronized keyword before it. This block of code is similar to a synchronized method and only one thread can access it at a time.


What is mean by component in java?

A component is a Reusable building block .


What is the purpose of catch block in java?

to provide an action in case the code block in the try statement fails.


What is the use of catch block in java?

the catch block catches the exception from the try block to display a proper message about the exception. Answered by, SOORAJ.M.S


How do you block runescape on explorer 7?

It is coded on Java 3, that's so old that even windows 98 can't block it.


Why use catch keyword in java?

no, because catch is used to handle exceptions which are generated from try block


Does Norton antivirus block you from signing up to Bebo?

Norton will not block you. But if you have asked norton to turn off java script you will need to turn that back on.


Can you print some message on the console without using main in java?

By using the static block


How you use if condition in java?

The if block is used in java to check a true or false condition. for ex: if(age &gt; 18) { system.out.println("You are an Adult"); } else { system.out.println("Sorry, you are still a kid"); }


What is global variable in java?

A local class is declared locally within a block of Java code.You can even have classes declared inside a method. such classes are called local classes.


Define a catch block?

A Catch block is part of the exception handling mechanism in Java. It is used along with the try block. Ex: try { ... } catch (Exception e) { ... } The catch block is used to catch &amp; handle the exception that gets thrown in the try block.