Java Fundamentals Worksheet 1
Java Fundamentals Worksheet 1
com
Java Fundamentals
WorkSheet 1
1. In a few words, please explain how to compilation process works in Java?
(Pretend you are explaining this to a 6 year old or an elderly person).
3. How are variables declared in Java? What’s the syntax? Please give 2 examples.
(Hint: String name…)
4. What’s the difference between a String and a Char (character) types? (H
int: think
about how you declare each one of them)
5. A boolean value can have any value you like because any non-zero value is true.
True or False?
1
8. The moon’s gravity is about 17% that of the earth’s. Write a program that
computes your weight on the moon.
9. How do you create a single-line comment? How do you create a multiline
comment?
10. What happens when you miss a semicolon at the end of a statement?
System.out.println(“Hey\nPaulo\n!”);
Copyright www.buildappswithpaulo.com
2
2. A variable is a special place in memory where we can store information. The
contents of a variable can be changed during execution.
3. For example, to declare a string variable we would write as follows:
String name = “name”;
Int age = 21;
4. Here’s how we declare a string variable type: String lastName = “Bond”; A char
variable type is declared as follows: char b = ‘b’; T
he main distinction is the
usage of “ ” (double quotes) for strings, and ‘ ’ single quotes for chars.
5. False. Booleans must only be either true or false.
6. Java programs begin execution at m
ain().
7. Bytecode is the product of the compilation process which “converts” source code
into specialized instructions to carry instructions. Bytecode is the file that’s
executed by the JVM (Java Virtual Machine). This is the only reason Java’s
programs are portable and secure.
Copyright www.buildappswithpaulo.com
3
8. Class Moon{
Public static void main(String args[]) {
double earthWeight;
double moonWeight;
earthWeight = 185;
moonWeight = earthWeight * 0.17; // multiply earth weight by percentage
System.out.println(“Moon weight: “ + moonWeight);
}
}
9. Single-line comment: //single-line comment goes here
Multiline comment:
/*
You can write all you want
Here…. Even a novel.
*/
10. You will get a syntax error. Your program won’t compile until you add the
semicolon.
11. The “\n” command tells the compiler to create a new line; so the output would be:
Hey
Paulo
!
Copyright www.buildappswithpaulo.com
4
Copyright www.buildappswithpaulo.com