Programming in Java : Terms & Concepts with Program Walkthrough

"Success is the ability to go from one failure to another with no loss of enthusiasm." Winston Churchill

Terms & Concepts

These are some of the terms and concepts you should know or learn. Some will be obvious, others will be confusing for a while. The more you can learn and identify, the easier programming will be...especially when Mr. Meinzen talks about them.

 

Basic Terms/Concepts

Abstract Terms/Concepts

  • comment (Javadoc, single line & multi-line)

  • variable versus literal

  • assignment

  • method

  • scope

  • void

  • object

  • Type of variable

    • primitive (int, double, boolean, etc.)

    • reference (String, Class, etc.)

  • application versus applet versus app

  • public versus private

  • variable declaration

  • object instantiation

  • Constructor method declaration

  • Constructor call

  • method declaration

    • header of method (i.e. method signature)

    • method return Type

    • body of method

    • method return variable

    • parameter(s) of method

  • method call

    • method arguments

    • dot notation (qualified name)

 

 

Program Walkthrough (based upon PetRockGUI.java)

After Mr. Meinzen demonstrates the program walkthrough, answer the following questions:

 

PetRockGUI.java

1  import javax.swing.*;
2  import java.awt.*;
3  import java.awt.event.*;

4  public class PetRockGUI extends JPanel implements ActionListener
5  {

6       private JFrame  frameObject;   
7       private JButton buttonObject;  
8       private JLabel  labelObject;   

9       private int     length;        
10      private int     width;        
11      private String  name;          

12      public static void main(String a[])
13      {
14          PetRockGUI game = new PetRockGUI();
15      }

16      public PetRockGUI()
17      {
18           length = 50;   
19           width  = 100;  
20           name   = "Mr. Meinzen's PetRock";

21           Font niceFont = new Font("Courier New", Font.PLAIN, 24);  

22           labelObject = new JLabel("My name is "+name); 
23           labelObject.setFont(niceFont);                
24           labelObject.setForeground(Color.RED);         
25           this.add(labelObject);                        

26           buttonObject = new JButton("Click me to flip");  
27           buttonObject.addActionListener(this);            
27           this.add(buttonObject);                          
29           frameObject = new JFrame("My First Graphical Application"); 
30           frameObject.setSize(500, 500);                              
31           frameObject.setLayout(null);                                
32           frameObject.setContentPane(this);                           
33           frameObject.setVisible(true);                               
34      }

35      public void paintComponent(Graphics g) 
36      {
37           super.paintComponent(g);         
38           g.setColor(Color.GREEN);         
39           g.fillRect(50,150,length,width); 
40      }

41      public void flip()
42      {
43           int temp = length;
44           length   = width;
45           width    = temp;
46      }

47      public void actionPerformed(ActionEvent e)
48      {
49           flip();
50           repaint();
51      }
52 }
  1. After hitting the "Hammer1" button, what happens and which line does the computer start on?

  2. After hitting the “Hammer2” button, what happens and which line does the computer start on?

  3. Name all the methods in the class.

  4. Name all the variables and their Types.

  5. What is the difference between starting with a capital letter and lower-case letter (i.e. when should you start with a capital letter and when should you start with a lower case letter?)

  6. What is the difference between a Class and an object?

  7. Which line(s) have the following:

    1. a declaration for a Button

    2. an instantiation for a Button

    3. listens for clicks on a Button

    4. puts a Button on the screen

    5. find 3 lines that have a literal being assigned to a variable

    6. find a line where a variable is declared inside a method

    7. which lines have a matching method declaration and method call

    8. find a line that uses a qualified name