






































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
In this course, Introduction to Programming in Java, we learned all programming concepts and implement them in java. Key points in these lecture slides are: Grouping Objects, Call-By-Value, Arrays, Collections, Iterators, Parameter Passing, Similar But Different, Grouping Objects, Notebook, Fixed-Size Collections
Typology: Slides
1 / 78
This page cannot be seen from the preview
Don't miss anything!
public class SimpleCalls { public static void main(String[] args) { int x = 3; System.out.println("1. x = " + x); squareBad (x); // x = squareGood (x); System.out.println("2. x = " + x); } // end of main()
private static void squareBad(int x) { System.out.println("sqBad 1. x = " + x); x = xx; System.out.println("sqBad 2. x = " + x); } private static int squareGood(int x) { System.out.println("sqGood 1. x = " + x); x = xx; System.out.println("sqGood 2. x = " + x); return x; } } // end of SimpleCalls class
Declaring and Allocating Arrays
import javax.swing.JOptionPane; public class UseArray { public static void main(String[] args) { int n[]; // declare array name n = new int[10]; // allocate memory to array // no values stored in n[], so will contain 0's String output = "Cell Value\n"; for(int i = 0; i < n.length; i++) output += "n[" + i + "] == " + n[i] + "\n"; JOptionPane.showMessageDialog( null, output, "Using an Array", JOptionPane.INFORMATION_MESSAGE ); } // end of main() } // end of UseArray class
n[i]
for( int i = 0; i < n.length; i++) { System.out.println(i + ": " + n[i]); } int i = 0; while(i < n.length) { System.out.println(i + ": " + n[i]); i++; } for loop version while loop version