Basics of Java Flashcards
Why is Java so useful?
the Java Virtual Machine ensures the same Java code can be run on different operating systems and platforms (MacOs, Windows API, UNIX) - Sun Microsystems’ slogan for Java was “write once, run everywhere”.
The difference between System.out.println() & System.out.print()?
Unlike System.out.println(), this type of print statement outputs everything on the same line.
What are the three types of comments you can make?
When comments are short we use the single-line syntax: //
When comments are long we use the multi-line syntax: /*
and */
the Javadoc comment which is represented by /**
and */
. Javadoc comments are used to create documentation for APIs
What is the purpose of the compiler in Java?
he code we write in a .java file is transformed into byte code by a compiler before it is executed by the Java Virtual Machine.
The compiling process catches mistakes before the computer runs our code. Code that does not pass these checks will not be compiled.
What is the terminal command to compile a file?
A successful compilation produces a .class file: Plankton.class. What is the terminal command we execute?
javac Plankton.java
java Plankton
What happens to an unsuccessful compilation?
An unsuccessful compilation produces a list of errors. No .class file is made until the errors are corrected and the compile command is run again.
What is an IDE?
enables programmers to consolidate the different aspects of writing a computer program
increase programmer productivity by combining common activities of writing software into a single application: editing source code, building executables, and debugging.
How do IDEs facilitate editing source code
They have features like syntax highlighting and autocomplete
How do IDEs facilitate syntax highlighting?
By providing visual cues. Keywords, words that have special meaning like class in Java, are highlighted with different colors. Syntax highlighting makes code easier to read by visually clarifying different elements of language syntax.
How do IDEs facilitate autocomplete?
It can anticipate what you’re going to type next!
how does IDE facilitate debugging?
IDEs provide debugging tools that allow programmers to examine different variables and inspect their code in a deliberate way.
What is a string?
What are the two ways to create a String object?
A String literal is any sequence of characters enclosed in double-quotes (“”)
we declare a String
variable by specifying the type first:
~~~
String greeting =”Hello World”;
~~~
We could also create a new String object by calling the String
class when declaring a String
like so:
~~~
String salutations =new String(“Hello World”);
~~~
How can we add quotation marks and backslashes to a String value?
The " escape sequence:
System.out.println(“"Hello World"”);
// Prints: “Hello World”
the \ escape sequence :
System.out.println(“This is the backslash symbol: \”);
// Prints: This is the backslash symbol: \