Sunteți pe pagina 1din 3

a) List three features of every object-oriented programming language.

Encapsulation-Encapsulation refers to the creation of self-contained modules that bind


processing functions to the data.
Inheritance-That means less programming is required when adding functions to
complex systems. If a step is added at the bottom of a hierarchy, only the processing
and data associated with that unique step needs to be added.
Polymorphism-Object-oriented programming allows procedures about objects to be
created whose exact type is not known until runtime
Write a statement that declares a class named AverageScore that is available to
any code.
import java.util.Scanner;
public class averagescore
{ public static void main(String[] args)
{ // display a welcome message
System.out.println("Welcome to the Invoice Total Calculator");
System.out.println(); // print a blank line
// get the input from the user Scanner sc = new Scanner(System.in);
System.out.print("10 ");
double subtotal = sc.nextDouble(); // calculate the discount amount and total double
discountPercent = .2;
double discountAmount = 10* discountPercent;
double invoiceTotal = subtotal - discountAmount; // format and display the result String
message = "Discount percent: " + discountPercent + "\n" + "Discount amount: " +
discountAmount + "\n" + "Invoice total: " + invoiceTotal + "\n"; System.out.println(“you've
got” total);

Explain the difference between source code and bytecode.


The difference between source code and bytecode is that the source code is a
collection of computer instructions written using a human-readable programming
language while the bytecode is the intermediate code between source code and
machine code that is executed by a virtual machine

Describe machine code.


Machine code is a computer program written in machine language. It uses the
instruction set of a particular computer architecture. It is usually written in binary.
Machine code is the lowest level of software. Other programming languages are
translated into machine code so the computer can execute them.

Explain the difference between a Java compiler and the Java VM.
Java Virtual Machine(JVM) is part of Java Runtime Environment(JRE). JVM is where
the compiled byte code executes(runs). JVM sometimes contains a Just in time
compiler(JIT) whose job is to convert byte code to native machine code.
What is the advantage of compiling Java source code using a JIT?
The JIT compiler requires less memory usage as only the methods that are required at
run-time are compiled into machine code by the JIT Compiler. Page faults are reduced
by using the JIT compiler as the methods required together are most probably in the
same memory page.
The following application has seven syntax errors. What are they?
//its empty
* Test.java cannot do * without /*
* What's wrong application.
* Student Name
*/
package testMyKnowledge;
/**
* The Test class should display a string,if you want to say something beside you have
to do //
*/
public class Test {
private static int main(string[] args) {
System.out.println("Testing...)forgot the “ in the end and ;
Explain the difference between the print() and println() methods.
The println("...") method prints the string "..." and moves the cursor to a new line. The
print("...") method instead prints just the string "...", but does not move the cursor to a
new line. Hence, subsequent printing instructions will print on the same line.
Explain the advantages of using the format() method in place of the print()and
println() methods.
The alternative to using println() is to use a proper Logger. Which print/println/printf you
use doesn't matter. Use the one is most appropriate for what you want to do

There are five places in which the application below does not follow the code
conventions outlined in this chapter. Where are they?
/*
* getGreeting.java
* What's wrong application.
* Student Name
*/
package notSoGood;
/**
* Good Morning is displayed.
*/
public class getGreeting { public static void main(String[] args) {
//Output Good Morning to the screen
System.out.println("Good Morning");
}}

statements in a method should be indented.


An open curly brace (
{
) should be placed on the same line as
the class or method declaration, and the closing curly brace (
}
)
should be on a separate line and aligned with the class or method
declaration

S-ar putea să vă placă și