0% found this document useful (0 votes)
156 views

Java Fundamentals Worksheet 1

The document contains a worksheet with 11 questions about Java fundamentals such as variables, data types, comments, and the compilation process. The answers explain variables, data types, bytecode, and how to write simple Java programs.

Uploaded by

Shashank
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
156 views

Java Fundamentals Worksheet 1

The document contains a worksheet with 11 questions about Java fundamentals such as variables, data types, comments, and the compilation process. The answers explain variables, data types, bytecode, and how to write simple Java programs.

Uploaded by

Shashank
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Copyright​ ​www.buildappswithpaulo.

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). 

2. What’s​ ​a​ ​variable? 

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? 

 

 

6. Where​ ​do​ ​Java​ ​programs​ ​begin​ ​execution? 

7. What​ ​is​ ​bytecode​ ​and​ ​why​ ​is​ ​it​ ​important? 

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? 

11. ​ ​What’s​ ​the​ ​output​ ​of​ ​the​ ​following​ ​statement? 

  System.out.println(“Hey\nPaulo\n!”); 

 
 
 
 
 
 
 
 
 
 
 

Copyright​ ​www.buildappswithpaulo.com 

 

Answers​ ​to​ ​Questions 


1. The​ ​key​ ​to​ ​answering​ ​this​ ​question​ ​is​ ​to​ ​think​ ​about​ ​what​ ​the​ ​compiler​ ​does​ ​to 
java​ ​source​ ​code,​ ​and​ ​what’s​ ​the​ ​end​ ​result​ ​after​ ​the​ ​compilation​ ​process​ ​is 
completed​ ​(bytecode)​. 

 
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 

 
 
 
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 

 

Copyright​ ​www.buildappswithpaulo.com 

You might also like