Preview

03 - Java Basics and Code Structure

 1. Which of the following are examples of suitable IDEs for Java?
Eclipse
Netbeans
IntelliJ IDEA 
JDK
JRE
Dr Java

  None of them

  Just Eclipse

  All of them

  All of them, except for JDK and JRE

 2. There are two major components of code. These are blocks, and statements. A statement is a ________________. A block can contain multiple statements.
Note: Statements always end in a semicolon

  sentence written in binary

  single executable instruction

  mutable indestructible sentence

  binary coded class document

 3. A sequence of characters is called a string. Strings in Java are enclosed in double-quotes.Identify the string in the below code:
System.out.println("Hello World");

  out

  String

  println

  Hello World

 4. The commands System.out.print and System.out. println both are responsible for:

  printing black and white strings

  printing out information to the printer

  printing to an online or virtually simulated printed

  displaying information on the computer monitor

 5. System.out.println moves the cursor to a ________ after the information has been displayed, while System.out.print does not.

  new line

  different method

  different class

  new class

 6. Both these examples seek to create a class header. Which of the following statements is correct?
#1.
Public class MyFile {


#2.
public Class MyFile {

  #2 is incorrect, as class should always be written in capitals

  Both are incorrect, #1 - public should be lowercase; #2 - class should be lower case

  Both are correct, although option #1 is the preferrable method

  #1 is incorrect as public should be lowercase and class should be in capitals

 7. Suppose you wanted to output a string like the one shown below. What is Java's solution to this? (take special note of the fact that the word 'Java' is in quotation marks.
Hello, I am Learning "Java"

  Use of ASCII and Unicode

  Use of the compiler to create binary-based code

  Use of binary bytecodes

  Use of Character escape Sequence in Java

 8. The following code shows a class called Addition that contains a:
public class Addition {
	
	
	public static void main(String[] args){  
	int a=10;  
	int b=10;  
	int c=a+b;  
	System.out.println(c);  
	
	}
	
}

  property class that contains two variables

  sub class that is called 'main'

  main method that adds two integers; a and b

  string integer that can be concatenated

 9. What is the output of the code above?

 10. Read the paragraph below and fill in the blanks.
A ________ program is a text file that contains a program
written in a programming language. Since it contains ordinary text (stored as bytes) it can not be directly executed (run) 
by the computer system. As a text file, you can print it, 
display it on the monitor, or alter it with a text editor. 

 11. Reserved words are certain keywords that have particular meaning in Java and cannot be used. Which of the following statements below is correct?
Reserved words: You can find a complete list here: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html

Are all of these reserved words in Java?

1 - but
2 - class
3 - if
4 - main
5 - public
6 - super 
7 - this 

  There are no reserved words in Java. This makes it different from other languages.

  The words 'if' and 'class' are reserved words in Java. There is a long list of others too!

  The word 'username' is a reserved word in Java and cannot be used as a variable

  The word 'javacode' is a reserved word in Java. It can never be used in any context

 12. JVM (Java _______ Machine) is an abstract machine. It is called a _______machine because it doesn't physically exist.
Additional Notes:  It is a specification that provides a runtime environment in which Java bytecode can be executed. It can also run those programs which are written in other languages and compiled to Java bytecode.

The JVM performs the following main tasks:

Loads code
Verifies code
Executes code
Provides runtime environment

  vehement

  vortex

  virtual

  visionary

 13. It is possible for a processor chip to be built that executes Java bytecodes directly, just as an Intel processor chip executes its machine language directly?

  TRUE

  FALSE

 14. The code below shows a class called 'Hello'. Which of the following statements are true of a class?
class Hello
{
  public static void main ( String[] args )
  {
    System.out.println("Hello World!");
  }
}

  A class can be thought of as a blueprint or template for objects.

  A class helps with efficient organisation of code and contains methods and properties

  A class can inherit properties and methods from parent classes

  All of the mentioned statements are true of a class

 15. What does the figure below illustrate and confirm?
mutipleclasses.png

  This shows multiple classes in a java source file. It is possible to have multiple classes.

  This shows several methods, confirming that methods must be created outside classes

  This shows a single class in a java source file.

  This shows a class within a class, confirming it is only possible to create classes inside classes.

 16. In the following example, lines 1,3 and 4 are examples of single (line 1) and multiline (lines 3 and 4) __________. They are not executed by the compiler.
  //This is a java code snippet  
    public class FirstExample2 {  
    public static void main(String[] args) {  
    /* Let's declare and 
     print variable in java. */  
        int i=10;  
        System.out.println(i);  
    }  
    }  

 17. Fill in the blanks in the paragraph below. (Just type in one word that fits in each of the blanks)
_______ is a keyword. The _______ keyword is used to ______ built-in and 
user-defined packages into your java source file so that your class can 
refer to a class that is in another package by directly using its name

 18. Which of the following options have followed the preferred naming conventions in Java?
1-class MONEY
2-class money
3-final int BANK_DEPOSIT
4-int bankDeposit
5-int BankDeposit

  1,5

  1,2,3

  1,4

  3,4

 19. The company 'Apple' has just come out with a new computer and wants this computer to run Java programs. What must Apple do?
Important note: When the Java interpreter is running on a computer system, that system acts just like a hardware Java bytecode processor. It is a Java Virtual Machine.

 20. Java programs are portable, which means that the same bytecode program can run on any computer system that has a Java interpreter

  FALSE

  TRUE

 21. An______ is a Java bytecode program that runs on a Web browser. Most up-to-date Web browsers include a Java interpreter.

  javlet

  applet

  weblet

  mini-app

 22. If you're using an IDE like Eclipse, you'll notice a Source folder and bin folder. Fill in the blanks for the sentence below.
To describe this in another way, "src" folder contains the 
human readable code and "bin" contains the ______________
___________________________________________________________.

  junk code which is not recognisable

  binary that the java virtual machine executes.

  source code that contains other junk code

  non binary code that the java virtual machine will delete

 23. _______ are values passed to a function when the function is called. x and y in this example are ________.
public class Example { 
  
    public static int multiply(int a, int b) 
    { 
        return a + b; 
    } 
  
    public static void main(String[] args) 
    { 
        int x = 2; 
        int y = 5; 
  
        // the variables x and y are arguments 
        int sum = multiply(x, y); 
  
        System.out.println("SUM IS: " + sum); 
    } 

 24. There is a subtle, but important difference between arguments and parameters. For the following example, which one of these options is correct?
package com.example.works;

public class ArithmeticOperations {

    public static int add(int x, int y) { //x, y are parameters here
        return x + y;
    }

    public static void main(String[] args) {
        int x = 10;
        int y = 20;
        int sum = add(x, y); //x, y are arguments here
        System.out.println("SUM IS: " +sum);
    }

}

  In the 'main' method, x and y are parameters, and they are also parameters in the 'add' method

  There are no arguments or parameters anywhere in this program

  In both methods, x and y are arguments

  In the 'add' method, x and y are parameters. In the main method, x and y are arguments

 25. Can you save a java source file by other name than the class name?

  Yes, if the class is not public

  Yes, but only if the class contains at least two methods

  No, never

  Yes, but only if the class contains both methods and properties