Answer the following questions as briefly (but completely) as possible:
NullPointerException
?
System.out.println( 1 / 0 ); System.out.println( 1.0 / 0 );
long value = Long.MAX_VALUE + 1; System.out.println( value );
public class ShowErrors { public static void main ( String [] args ) { ShowErrors t = new ShowErrors( 5 ); } }
public class ShowErrors { public static void main ( String [] args ) { ShowErrors t = new ShowErrors(); t.x(); } }
public class ShowErrors { public void method1 () { Circle c; System.out.println( "What is radius " + c.getRadius() ); c = new Circle(); } }
public class ShowErrors { public static void main(String[] args) { C c = new C(5.0); System.out.println(c.value); } } class C { int value = 2; }
int i = new int(30);
double d[] = new double[30];
char[] r = new char(1..30);
int i[] = (3, 4, 3, 2);
float f[] = {2.3, 4.5, 6.6};
char[] c = new char();
double
s, write Java statements to
do the following:
[2, 4, 7, 10, 11, 45, 50, 59, 60, 66, 69, 70, 79]
.
key is 11 0 1 2 3 4 5 6 7 8 9 10 11 12 11<50 [ 2, 4, 7, 10, 11, 45, 50, 59, 60, 66, 69, 70, 79] low=0 mid=6 hi=12 11>7 [ 2, 4, 7, 10, 11, 45, 50, 59, 60, 66, 69, 70, 79] low=0 mid=2 hi=5 11=11 [ 2, 4, 7, 10, 11, 45, 50, 59, 60, 66, 69, 70, 79] low=3 hi=5 mid=4
(Note how binary search eliminates half of the list from further consideration after each comparison.)
Java.util.Arrays.sort
method?
Does this sort method create a new array?
int[][] r = new int[2];
int[] x = new int[];
int[][] y = new int [3][];
int[][] z = {{1, 2}};
int[][] m = {{1, 2}, {2, 3}};
int[][] n = {{1, 2}, {2, 3}, };
ArrayList
for storing double
values? List
? List
? List
? List
? List
? List
? List
? ArrayList<String> list = new ArrayList<String>(); list.add( "Denver" ); list.add( "Austin" ); list.add( new java.util.Date() ); String city = list.get( 0 ); list.set( 2, "Dallas" ); System.out.println( list.get(2) );
[1, 3]
rather than [2, 3]
.
ArrayList<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(3); list.remove(1); System.out.println( list );
class Test { public static void main ( String [] args ) { Count myCount = new Count(); int times = 0; for ( int i = 0; i < 100; i++ ) increment( myCount, times ); System.out.println( "count is " + myCount.count ); System.out.println( "times is " + times ); } public static void increment ( Count c, int times ) { c.count++; times++; } } class Count { public int count; public Count ( int c ) { count = c; } public Count () { count = 1; } }
public class Test { public static void main ( String [] args ) { java.util.Date[] dates = new java.util.Date[10]; System.out.println( dates[0] ); System.out.println( dates[0].toString() ); } }
private
data fields and no
“set” methods, is the class considered to be immutable?
private
and primitive, and no “set” methods, is the class considered
to be immutable?
public class C { private int p; public C () { System.out.println( "C's no-arg constructor invoked" ); this(0); } public C ( int p ) { p = p; } public void setP ( int p ) { p = p; } }
public class Test { private int id; public void m1 () { this.id = 45; } public void m2 () { Test.id = 45; } }
Email your homework assignment, by copy-and-paste (no attachments please), to (homework submission). If possible use the “text” and not the “HTML” mode of your email program. Please use the subject similar to “Java Programming I Homework Assignment #4 Submission”, so I can tell which emails are submitted homework assignments.
Homework assignments will not be returned. Please do not send as attachments. Refer to the Homework and the Submitting Assignments sections of your syllabus for more information.
Confused? Send questions about the homework assignment to (homework questions). Please use a subject similar to “Java Programming I Homework Assignment #4 Questions” so I can tell which emails are questions about assignment quiz (and not submissions).