What is the terminology for each expression in the following class :
for e.g :
class Test {
int a=0;
void method(boolean boo){
String b="";
try
{
new Thread().sleep(1000);
}
catch(InterruptedException e){}
JOptionPane.showMessageDialog(null,"test");
BufferedImage image=ImageIO.read(new File("C:\\file.png"));
}
}
From what i know a
is a field, boo
is a parameter, b
and image
are local variables.
What is the terminology used for
new Thread().sleep()
JOptionPane.showMessageDialog()
ImageIO.read()
new File()
InterruptedException
new Thread().sleep()
:This is a two-part expression. The first part i.e,
new Thread()
is actually documented in the Java Language Specification (JLS) as an unqualified class instance creation expression :You basically create an instance of the
Thread
class when you saynew Thread()
. The second part of the statement is.sleep()
which is known as a method call.new File()
:This is also an unqualified class instance creation expression just like the expression
new Thread()
but creates an instance of theFile
class instead of theThread
class.JOptionPane.showMessageDialog()
:If you take a look at the source code for the JOptionPane.showMessageDialog method, you will see that the method is a
static
method. Also, the JLS explains how to access static methods :What the JLS indirectly says is that you can access a
static
method outside the class in which it is defined using the name of the class.Another important fact to understand here is that there are well defined Java naming conventions.
XyzAbc
, assume that it is either aclass
or aninterface
. For example,JOptionPane
andImage
are class names.doSomething
,getSomething
,setSomething
,showMessageDialog()
.. you should know that it is a method.Putting all this understanding together, we can deduce that
JOptionPane.showMessageDialog()
calls astatic
method fromJOptionPane
.InterruptedException
:If you understood the naming conventions explained above, you should know by now that
InterruptedException
is aclass
. How it differs from any other class inJava
is that it can be thrown around using thethrow
clause and then caught using atry-catch
statement. You can read more about exception handling in the Oracle documentation.