Computer Science Homework Solutions
Problem
#25648

Java - Compiler errors

In Code3 there are (6) numbered items. Do only the first four "compiler errors." Explain why each will produce a compiler error and what you would do to fix the problem.

1.  What the JVM will do when you remove the comments.

2.  What caused the problem in the first place.

3.  What can be done (all the solutions) to fixing the problem.
-------------------------------------------------------
4.  What is the difference between "typecasting" and "promotion."

Attached file(s):
Attachments
Code3.doc  View File

Attachment Content Summary (Note: view attachment at the above link before purchasing. Actual attachment content may vary slightly from that shown below.)

Code3.doc
// This program illustrates the use of Java datatypes.

import java.io.*;

import java.lang.*;

public class Code3

{ //begins Nums

public static void main(String args[])

{

int x= 5;

int y= 2;

int z = 0;

long a, b = 0;

double d= 5.12345;

byte c = 0;

//float e = 34.2; compiler error: (1)

float e = 34.2F; //or float e = (float) 34.2;

short f,g,h;

f =2; g = f;

//h = f * g; complier error (2)

//c = a; compiler error (3)

//z = 5L; compiler error (4)

a = 6; //promotion of int to long

b = 1000L;

z = (int) (5000L + b); // (5)

c = (byte) (x*y); // (6)

a = c;

System.out.println(c);

System.out.println(c * a);

System.out.println(b);

z = (int) d; // lose decimal places

System.out.println(z);

} //end main

} //end Nums
Solution
What is this?
By OTA - Overall OTA Rating
Tyler Xie, MSc (IP) - 4.5/5
Purchase Cost Now
$2.19 CAD (was ~$19.95)
Included in Download
  • Plain text response
  • Attached file(s):
    • Code3.class
    • Reply.txt
$2.19 Instant Download
Add to Cart
Why you can trust BrainMass.com
  • Your Information is Secure
  • Best Online Academic Help Service
  • Students find real academic Success
Related Solutions
  • Java Programming Language - 1. How does inheritance improve a programmer’s productivity? 2. Describe the difference between robustness and reliability and how design affects these characteristics
  • Write a syntax for the following - 1. Write the syntax for a 2D array which prints four rows and five columns of stars 2. Write the syntax for a 2D array which has four rows. The first row will have 10 elements and the second row ...
  • Solutions to array - Solutions to eight-member one-dimensional array. See attached file for full problem description.
  • SQL - Use statement - Create the following queries and save them all in a file called P1.SQL. Please note that you can execute individual queries in a query file by highlighting the lines that you want to execute before ru ...
  • The difference between int and Integer. - What is the difference between an int and an Integer?
Browse