1.3_Understanding the Java Class Structure Flashcards

1
Q

What is a keyword?

A

In Java a keyword is a reserved word that has a predefined meaning in the language.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the valid length for a Java class name?

A

1 - 65535 characters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the Java Identifier Rules?

A

o [A-Z],[a-z],[0-9],’‘(underscore),’$’(Dollar sign)
o Can NOT start with numbers
o Valid length 1-65535
o ⚠️Can NOT be ‘
’ (a single underscore)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the syntax to declare a Java variable?

A

{Type} varName;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a Java method?

A

A Java method is a collection of statements that are grouped together to perform an operation. This operation can be invoked by its method signature multiple times avoiding to write those statements again.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the required elements of a method declaration ?

A
o  The method's return type.
o  Method's name
o  A pair of parentheses (). 
o  argument-list
o  ...and body statement between braces, {}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

For Java methods, Is the return type mandatory?

A

Yes, a method must always defines its return type. And when it doesn’t return anything we use the keyword ‘void’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Where should be placed the return type within a method declaration?

A

The return type goes to the immediate left of the method name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does void means as a return type?

A

void means the method wont be returning anything.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What pieces compose the method-signature?

A

method name + parameter-types list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the three kind of comments in Java?

A

o //single-line comment
o /Multi Line comment/
o /** *Java-doc MultiLine comment *@author Efren Diaz */

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the valid main’s method declarations?

A

public static void main(String[] argsName)
public static void main(String argsName[])
static public void main(String… argsName)
*Notice that the argsName could be any valid parameter name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the rules for files containing a Java class definition?

A
o  Each Java file can contain only one public class.
o  The filename must match the public/single class name, including case
o  It must have a .java extension.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How to compile a java class via Terminal?

A

To compile Java code, the file must have the extension .java.
$ javac ClassName.java

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the result of compiling a Java class?

A

The result is a file of bytecodes with the same name, but with a .class filename extension.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is bytecode?

A

bytecode consists of instructions that the JVM knows how to interpret to execute in every OS

17
Q

Which exception may occur while reading main args via launcher(java command)?
$ java HelloWorld FirstArgument SecondArgument

A

If you don’t pass in enough arguments java.lang.ArrayIndexOutOfBoundsException will be thrown

18
Q

What does single-file-source-code means?

A

A single-file program is one where the program fits in a single source file

19
Q

How to launch single-file-source-code in one line?

A

$ java SingleFileClass.java FirstArgument
When running it as a one-liner, we write…
java SingleFileZoo💥️.java💥️

20
Q

Does the single-file-source-code launching, generates a .class file?

A

No, It runs in memory, so it doesn’t create a .class file