Lab Activity Java Basic
Lab Activity Java Basic
JAVA BASICS
WEEK 2 AND 3
PART A
1. What is the difference between C++ object oriented programming approach and
Java programming approach?
6. If you have the source code for a Java program, and you want to run that program,
you will need both a compiler and an interpreter. What does the Java compiler do
and what does the Java interpreter do?
8. The class name must be the same as the file name. (Yes/No)
System.out.println(“\nThis\nis\na\nJava\Programming”);
11. What are variables? (There are four different ideas associated with variables in Java.
Try to mention all four aspects in your answer. Hint: One of the aspects is the
variable's name.)
12. Which of the following is NOT a primitive data types? What is it’s data type?
15. Write a Java statement that initializes a String object with your name.
16. By assuming that String object had been initialized with this word Welcome, write
a Java statement that can print that word three times on the same line.
1
17. Which object that allow user to read primitive data type values and strings?
PART B
Exercise 1
import javax.swing.JOptionPane;
public class Hello
{
2
//read in second number from user as a string
secondNum = JOptionPane.showInputDialog( "Enter second
integer" );
// add numbers
sum = num1 + num2;
//display result
JOptionPane.showMessageDialog( null, "The sum is: "
+ sum);
Exercise 3
import java.util.*;
import java.text.*;
//Get input
System.out.print("Enter radius: ");
radius = console.nextDouble();
3
Exercise 4
String name;
int n;
boolean startWord;
Exercise 5