Oracle Java SE 8
Programmer I
Certification
Exam 1Z0-808
OPENING REMARKS
ABBREVIATIONS & ACRONYMS
2
actype – actual object’s type at run time
assop – assignment operator
castype – data type specified inside the parens for an explicit
cast
comperr – compilation error
ctor – constructor
dim – dimension
initer – initializer
op – operator
paramlist – list of formal parameters in a lambda expression
preditype – data type specified inside the angle brackets
reftype – reference type
refvar – reference variable
sout – any printing statement such as System.out.println(),
etc.
stat – statement
ternop – ternary operator
var – variable
AIOOBE – ArrayIndexOutOfBoundsException
CCE – ClassCastException
ChE – checked exception
CSR – the Catch-or-Specify Requirement
DTPE – DateTimeParseException
E – an exception (regardless of the type)
IAE – IllegalArgumentException
IOE – IOException
IOOBE – IndexOutOfBoundsException
LDT – any of the new date/time classes in Java 8
LOC – line of code
NFE – NumberFormatException
NPE – NullPointerException
RTE – RuntimeException
SIOOBE – StringIndexOutOfBoundsException
TCF – try-catch-finally construct
Igor Soudakevitch  2019
igor.soudakevitch@mail.ru
KNOW YOUR
ENEMY
3
1
Up Close and Personal
“The certification is designed for beginners
in programming and/or those with a
nonprogramming background who have
basic mathematical, logical, and analytical
problem-solving skills and who want to
begin to learn the Java programming
language at an introductory level…
4
4
Fix This (Java Magazine, July-Aug 2015, pp.14-15)
5
Given this code fragment from file Cart.java:
package shop;
// line n1
{ Cart() {
TEST STRUCTURE
Core
70-80%
Non-random
Advanced
Random
(Tough/Very Tough
in Enthuware)
Guinea Pigs
Average
Not graded
6
– 80 Qs, 150 minutes, 65% passing
score
– 42 Exam Topics in 9 groups (ref.to Oracle Univ)
QUESTIONS
GETTING USED TO EXAM ENVIRONMENT
7
What to expect in a Pearson VUE test center:
https://home.pearsonvue.com/test-taker/security.aspx
TRICKS OF THE TRADE
8
Right-clicking eliminates options
Saving up to TEN Minutes:
"I Accept"  10m  2h30m countdown
“If there’s a particular facet of the Java language that you have
difficulty remembering, try memorizing it before the exam and
write it down as soon as the exam starts.”
– B&S: acceptable types in switch
– list of modifiers
– operator precedence chart
– ‘popular’ ChEs & RTEs + NPE throwing scenarios
MERELY
A SUGGESTION
TRICKS OF THE TRADE, cont’d
9
– code is pretty-typed  do NOT count curly braces
– ‘straight arrows’, ‘curved balls’ & ‘caltrops’ w/‘red herrings’:
Given in the file HiThere.java:
class HiThere {
public static void main(String[] args) {
System.out.print("Hi there" + args[0]);
}
}
Which set of commands prints Hi there! in the console?
A. javac HiThere C. javac HiThere.java !
java HiThere ! java HiThere
B. javac HiThere.java D. javac HiThere.java
java HiThere ! java HiThere.class !
TRICKS OF THE TRADE, cont’d
10
List<Integer> l = new ArrayList<>();
l.add(42);
l.add(null);
for (int i = 0; i<l.size(); i++) System.out.print(l.get(i)); // line 1
for (Object i : l) System.out.print(i); // line 2
for (int i : l) System.out.print(i); // line 3
Given:
int a = 0;
String str = new String("Yell");
str = str.replace("Yell", "Hell");
str = str.insert(4,"o");
if ("Hello" == str && a++ == 0) str = null;
System.out.println(a);
What is the result?
A. The code prints 1
B. The code prints 0
C. Compilation fails
D. The code throws an exception at run time
TRICKS OF THE TRADE, cont’d
11
 Don’t jump to the code. Read – the question – first. Force yourself to read it.
 Give the problem your best shot at the very first pass.
 Do it unhurriedly and never let yourself re-read what you’ve already read carefully.
 Take the code at its face value. Not every snippet is meant to deceive you.
 No cherry picking; do the questions as they come in.
 Treat your Review marks as gold.
 Trust your gut feelings.
 Resist the temptation to redo calculations right away, leave it for the Review.
TRICKS OF THE TRADE, cont’d
12
Overarching Rule:
Read the question first, then options and then code carefully. Subvocalize, even.
int[][] arr2D = new int[][] { { 0, 1, 2, 3 } { 4, 5 } };
 The most ‛obvious’ choice just may be booby-trapped;
 Never assume that the exam creators made a mistake;
 Weird looking, overly complex code is likely to contain:
• out-of-scope vars;
• invalid syntax;
• unreachable stats;
STUDY
ENVIRONMENT
Enhancements
13
2
SETTING UP STUDY ENVIRONMENT
14
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT*shellRun with Java]
[HKEY_CLASSES_ROOT*shellRun with Javacommand]
@="C:JCRWJ.bat %1"
Beating
heart:
javac %1
java %~n1
package org.xlator;
public class HelloWorld{
public static void main(String[] args) {
System.out.println("Hello, hello...");
}}
SETTING UP STUDY ENVIRONMENT,
cont’d
15
In file ClassA.java (to be located in C:Try_Javatempa):
package tempa;
public class ClassA{
public String name;
public ClassA(){
name = this.getClass().getSimpleName(); }
public ClassA(String name) { this.name = name; }
}
In file ClassB.java (in C:Try_Javatempb):
package tempb;
import tempa.*;
public class ClassB extends ClassA{
public ClassB(String name){ super(name); }
}
In file MyClass.java (in C:Try_Javaorgxlator):
package org.xlator;
import tempa.*;
import tempb.*;
public class MyClass {
public static void main(String[] args) {
ClassA ca = new ClassA();
ClassB cb = new ClassB("ClassB");
System.out.println(ca.name + ", " + cb.name + ", " + args[1]); }
}
10 min TRICK TABLES
Memorization Technique
16
3
JAVA MODIFIERS (extract)
17
MNEMONICS
LHS: (pa-pri-pro-pu & a-f-s) RHS: ‘CIC Me Data’ (click/kick) : A-O
Four Crosses Island Lonely Star The Ramp of Doom
JAVA MODIFIERS, cont’d
18
(in file I6.java)
interface I1 {}
// private interface I2 { } // INVALID
// protected interface I3 { } // INVALID
// final interface I4 { } // INVALID
// static interface I5 { } // INVALID
public interface I6 { }
abstract interface I7 { } // abstract keyword is redundant
(in file C6.java)
class C1 { }
// private class C2 { } // INVALID
// protected class C3 { } // INVALID
final class C4 { }
abstract class C5 { abstract void run5(); }
public class C6 {
int a;
private int b;
protected int c;
public int d;
static int e;
final int f = 0;
// abstract int g; // INVALID
private class C7 { } //
protected class C8 { } // all six are VALID
static class C9 { } // but inner classes and interfaces
private interface I8 { } // are not on the 1Z0-808 exam
protected interface I9 { } //
static interface I10 { } //
// final interface I11 { } // INVALID
cont’d:
C6(){ }
private C6(int a){ }
protected C6(int a, int b){ }
public C6(int a, int b, int c){ }
// abstract C6(){ } // INVALID
// final C6(){ } // INVALID
// static C6(){ } // INVALID
void run1(){
int a;
final int f;
// private int b; // INVALID
// protected int c; // INVALID
// public int d; // INVALID
// static int e; // INVALID
// abstract int h; // INVALID
}
private void run2(){ }
protected void run3(){ }
public void run4(){ }
}
One and only! 
JAVA MODIFIERS, cont’d
19
 static entities belong to the class;
 interfaces cannot be final;
 no abstract ctors;
 no static ctors;
 no final ctors;
 only final inside methods, ctors or initers;
 sneaky ctors: static & non-static semantics.
SUGGESTED PATTERN TO MEMORIZE
QUESTION: What about abstract static void run() ? is it possible? and why?
PRIORITY OF OPERATORS
20
1 of 2
FULL FORM
PRIORITY OF OPERATORS, cont’d
21
2 of 2
FULL FORM
PRIORITY OF OPERATORS, cont’d
22
 postfix / prefix increment / decrement operators are of the top
priority;
 all arithmetic ops including comparison come before equality testing;
 assignment, including its compound forms, is of the lowest priority.
TO MEMORIZE:
ASSUMPTIONS
23
 Missing package and import statements:
If sample code does not include package or import statements, and the
question does not explicitly refer to these missing statements, then assume
that all sample code is in the same package, and import statements exist to
support the code.
Typical; used in most of the questions that use core Java classes outside of
java.lang such as java.io.IOException, java.util.List,
java.util.function.Predicate and so on.
Source: Oracle Univ.
ASSUMPTIONS, cont’d
24
 No file or directory path names for classes:
If no file names or directory locations of classes  assume one of the
following, whichever enables the code to compile and run:
– All classes are in one file;
– Each class is contained in a separate file, and all files are in one directory.
Also quite common.
ASSUMPTIONS, cont’d
25
 Unintended line breaks:
Sample code may have unintended line breaks. If you see a line of code
that looks like it has wrapped, and this creates a situation where the
wrapping is significant (for example, a quoted string literal has wrapped),
assume that the wrapping is an extension of the same line, and the line
does not contain a hard carriage return that would cause a compilation
failure.
Didn’t meet this one; all code is pretty-typed.
ASSUMPTIONS, cont’d
26
 Code fragments:
A code fragment is a small section of source code that is presented without
its context. Assume that all necessary supporting code exists and that the
environment fully supports the correct compilation and execution of the
code shown and its omitted environment.
A good half of the questions contains such code fragments.
ASSUMPTIONS, cont’d
27
 Descriptive comments:
Take descriptive comments, such as "setters and getters go here," at face
value. Assume that correct code exists, compiles, and runs successfully to
create the described effect.
Met it once, in the form “setter and getter methods go here”.
WORD OF CAUTION
28
WEB RESOURCES: heavy reliance not advisable
“For convenience, the Java compiler automatically imports three entire packages for
each source file: (1) the package with no name, (2) the java.lang package, and (3) the
current package (the package for the current file).”
Current JLS8 (Chapter 7, Packages, preamble):
A package consists of a number of compilation units. A compilation unit automatically
has access to all types declared in its package and also automatically imports all of
the public types declared in the predefined package java.lang.”
NB
STUDY TIPS & SUGGESTIONS
29
 Keep a written record of your errors;
 Start and finish your day by going through this list of failures;
 Use colors, invent mnemonic formulas;
 Draw pictures on paper and in your mind;
 Do not worry much about the ‘Extra’ stuff;
 Concentrate instead on the ‘Core’ rules because…
…you will encounter something very close to them on the exam.
REMINDER: THE ‘QUOC’ PRINCIPLE
30
questio
n
options code

More Related Content

PDF
Java concepts and questions
PDF
Certified Core Java Developer
DOCX
CIS 407 STUDY Inspiring Innovation--cis407study.com
PDF
Core Java Certification
PDF
1z0 851 exam-java standard edition 6 programmer certified professional
DOCX
FSOFT - Test Java Exam
PPTX
Java basics-includes java classes, methods ,OOPs concepts
DOCX
Some tips for taking the High School AP Java college board exam
Java concepts and questions
Certified Core Java Developer
CIS 407 STUDY Inspiring Innovation--cis407study.com
Core Java Certification
1z0 851 exam-java standard edition 6 programmer certified professional
FSOFT - Test Java Exam
Java basics-includes java classes, methods ,OOPs concepts
Some tips for taking the High School AP Java college board exam

Similar to OCA_1Z0-808_Module00_Introduction_Java.pptx (20)

PDF
Java Software Solutions 9th Edition Lewis Solutions Manual
PDF
Oca Java Se 8 Programmer I Certification Guide Mala Gupta
DOC
MX Server is my friend
DOC
MX Server is my friend
DOC
MX Server is my friend
DOC
MX Server is my friend
DOCX
Jist of Java
DOCX
JAVA CONCEPTS AND PRACTICES
PPTX
Java introduction
PDF
1z0-808-certification-questions-sample
PPTX
Java For Automation
PDF
Test Bank for Java Software Solutions, 9th Edition John Lewis
PDF
Java Software Solutions Foundations of Program Design 7th Edition Lewis Test ...
PPTX
Proposals for new function in Java SE 9 and beyond
PDF
Java Software Solutions Foundations of Program Design 7th Edition Lewis Test ...
PDF
Java Software Solutions 8th Edition Lewis Test Bank
PDF
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
PPTX
Javascript
PPTX
Java programmingjsjdjdjdjdjdjdjdjdiidiei
Java Software Solutions 9th Edition Lewis Solutions Manual
Oca Java Se 8 Programmer I Certification Guide Mala Gupta
MX Server is my friend
MX Server is my friend
MX Server is my friend
MX Server is my friend
Jist of Java
JAVA CONCEPTS AND PRACTICES
Java introduction
1z0-808-certification-questions-sample
Java For Automation
Test Bank for Java Software Solutions, 9th Edition John Lewis
Java Software Solutions Foundations of Program Design 7th Edition Lewis Test ...
Proposals for new function in Java SE 9 and beyond
Java Software Solutions Foundations of Program Design 7th Edition Lewis Test ...
Java Software Solutions 8th Edition Lewis Test Bank
Java Software Solutions Foundations of Program Design 7th Edition Lewis Solut...
Javascript
Java programmingjsjdjdjdjdjdjdjdjdiidiei
Ad

Recently uploaded (20)

PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PPTX
"Secure File Sharing Solutions on AWS".pptx
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
MCP Security Tutorial - Beginner to Advanced
PDF
Microsoft Office 365 Crack Download Free
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
PPTX
Advanced SystemCare Ultimate Crack + Portable (2025)
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
CCleaner 6.39.11548 Crack 2025 License Key
PDF
Time Tracking Features That Teams and Organizations Actually Need
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Computer Software and OS of computer science of grade 11.pptx
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
PDF
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
PDF
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
"Secure File Sharing Solutions on AWS".pptx
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
MCP Security Tutorial - Beginner to Advanced
Microsoft Office 365 Crack Download Free
How to Use SharePoint as an ISO-Compliant Document Management System
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
Advanced SystemCare Ultimate Crack + Portable (2025)
Trending Python Topics for Data Visualization in 2025
CCleaner 6.39.11548 Crack 2025 License Key
Time Tracking Features That Teams and Organizations Actually Need
iTop VPN Crack Latest Version Full Key 2025
Why Generative AI is the Future of Content, Code & Creativity?
Computer Software and OS of computer science of grade 11.pptx
Weekly report ppt - harsh dattuprasad patel.pptx
Multiverse AI Review 2025: Access All TOP AI Model-Versions!
AI/ML Infra Meetup | Beyond S3's Basics: Architecting for AI-Native Data Access
Oracle Fusion HCM Cloud Demo for Beginners
DNT Brochure 2025 – ISV Solutions @ D365
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Ad

OCA_1Z0-808_Module00_Introduction_Java.pptx

  • 1. Oracle Java SE 8 Programmer I Certification Exam 1Z0-808 OPENING REMARKS
  • 2. ABBREVIATIONS & ACRONYMS 2 actype – actual object’s type at run time assop – assignment operator castype – data type specified inside the parens for an explicit cast comperr – compilation error ctor – constructor dim – dimension initer – initializer op – operator paramlist – list of formal parameters in a lambda expression preditype – data type specified inside the angle brackets reftype – reference type refvar – reference variable sout – any printing statement such as System.out.println(), etc. stat – statement ternop – ternary operator var – variable AIOOBE – ArrayIndexOutOfBoundsException CCE – ClassCastException ChE – checked exception CSR – the Catch-or-Specify Requirement DTPE – DateTimeParseException E – an exception (regardless of the type) IAE – IllegalArgumentException IOE – IOException IOOBE – IndexOutOfBoundsException LDT – any of the new date/time classes in Java 8 LOC – line of code NFE – NumberFormatException NPE – NullPointerException RTE – RuntimeException SIOOBE – StringIndexOutOfBoundsException TCF – try-catch-finally construct Igor Soudakevitch  2019 igor.soudakevitch@mail.ru
  • 4. “The certification is designed for beginners in programming and/or those with a nonprogramming background who have basic mathematical, logical, and analytical problem-solving skills and who want to begin to learn the Java programming language at an introductory level… 4 4
  • 5. Fix This (Java Magazine, July-Aug 2015, pp.14-15) 5 Given this code fragment from file Cart.java: package shop; // line n1 { Cart() {
  • 6. TEST STRUCTURE Core 70-80% Non-random Advanced Random (Tough/Very Tough in Enthuware) Guinea Pigs Average Not graded 6 – 80 Qs, 150 minutes, 65% passing score – 42 Exam Topics in 9 groups (ref.to Oracle Univ) QUESTIONS
  • 7. GETTING USED TO EXAM ENVIRONMENT 7 What to expect in a Pearson VUE test center: https://home.pearsonvue.com/test-taker/security.aspx
  • 8. TRICKS OF THE TRADE 8 Right-clicking eliminates options Saving up to TEN Minutes: "I Accept"  10m  2h30m countdown “If there’s a particular facet of the Java language that you have difficulty remembering, try memorizing it before the exam and write it down as soon as the exam starts.” – B&S: acceptable types in switch – list of modifiers – operator precedence chart – ‘popular’ ChEs & RTEs + NPE throwing scenarios MERELY A SUGGESTION
  • 9. TRICKS OF THE TRADE, cont’d 9 – code is pretty-typed  do NOT count curly braces – ‘straight arrows’, ‘curved balls’ & ‘caltrops’ w/‘red herrings’: Given in the file HiThere.java: class HiThere { public static void main(String[] args) { System.out.print("Hi there" + args[0]); } } Which set of commands prints Hi there! in the console? A. javac HiThere C. javac HiThere.java ! java HiThere ! java HiThere B. javac HiThere.java D. javac HiThere.java java HiThere ! java HiThere.class !
  • 10. TRICKS OF THE TRADE, cont’d 10 List<Integer> l = new ArrayList<>(); l.add(42); l.add(null); for (int i = 0; i<l.size(); i++) System.out.print(l.get(i)); // line 1 for (Object i : l) System.out.print(i); // line 2 for (int i : l) System.out.print(i); // line 3 Given: int a = 0; String str = new String("Yell"); str = str.replace("Yell", "Hell"); str = str.insert(4,"o"); if ("Hello" == str && a++ == 0) str = null; System.out.println(a); What is the result? A. The code prints 1 B. The code prints 0 C. Compilation fails D. The code throws an exception at run time
  • 11. TRICKS OF THE TRADE, cont’d 11  Don’t jump to the code. Read – the question – first. Force yourself to read it.  Give the problem your best shot at the very first pass.  Do it unhurriedly and never let yourself re-read what you’ve already read carefully.  Take the code at its face value. Not every snippet is meant to deceive you.  No cherry picking; do the questions as they come in.  Treat your Review marks as gold.  Trust your gut feelings.  Resist the temptation to redo calculations right away, leave it for the Review.
  • 12. TRICKS OF THE TRADE, cont’d 12 Overarching Rule: Read the question first, then options and then code carefully. Subvocalize, even. int[][] arr2D = new int[][] { { 0, 1, 2, 3 } { 4, 5 } };  The most ‛obvious’ choice just may be booby-trapped;  Never assume that the exam creators made a mistake;  Weird looking, overly complex code is likely to contain: • out-of-scope vars; • invalid syntax; • unreachable stats;
  • 14. SETTING UP STUDY ENVIRONMENT 14 Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT*shellRun with Java] [HKEY_CLASSES_ROOT*shellRun with Javacommand] @="C:JCRWJ.bat %1" Beating heart: javac %1 java %~n1 package org.xlator; public class HelloWorld{ public static void main(String[] args) { System.out.println("Hello, hello..."); }}
  • 15. SETTING UP STUDY ENVIRONMENT, cont’d 15 In file ClassA.java (to be located in C:Try_Javatempa): package tempa; public class ClassA{ public String name; public ClassA(){ name = this.getClass().getSimpleName(); } public ClassA(String name) { this.name = name; } } In file ClassB.java (in C:Try_Javatempb): package tempb; import tempa.*; public class ClassB extends ClassA{ public ClassB(String name){ super(name); } } In file MyClass.java (in C:Try_Javaorgxlator): package org.xlator; import tempa.*; import tempb.*; public class MyClass { public static void main(String[] args) { ClassA ca = new ClassA(); ClassB cb = new ClassB("ClassB"); System.out.println(ca.name + ", " + cb.name + ", " + args[1]); } }
  • 16. 10 min TRICK TABLES Memorization Technique 16 3
  • 17. JAVA MODIFIERS (extract) 17 MNEMONICS LHS: (pa-pri-pro-pu & a-f-s) RHS: ‘CIC Me Data’ (click/kick) : A-O Four Crosses Island Lonely Star The Ramp of Doom
  • 18. JAVA MODIFIERS, cont’d 18 (in file I6.java) interface I1 {} // private interface I2 { } // INVALID // protected interface I3 { } // INVALID // final interface I4 { } // INVALID // static interface I5 { } // INVALID public interface I6 { } abstract interface I7 { } // abstract keyword is redundant (in file C6.java) class C1 { } // private class C2 { } // INVALID // protected class C3 { } // INVALID final class C4 { } abstract class C5 { abstract void run5(); } public class C6 { int a; private int b; protected int c; public int d; static int e; final int f = 0; // abstract int g; // INVALID private class C7 { } // protected class C8 { } // all six are VALID static class C9 { } // but inner classes and interfaces private interface I8 { } // are not on the 1Z0-808 exam protected interface I9 { } // static interface I10 { } // // final interface I11 { } // INVALID cont’d: C6(){ } private C6(int a){ } protected C6(int a, int b){ } public C6(int a, int b, int c){ } // abstract C6(){ } // INVALID // final C6(){ } // INVALID // static C6(){ } // INVALID void run1(){ int a; final int f; // private int b; // INVALID // protected int c; // INVALID // public int d; // INVALID // static int e; // INVALID // abstract int h; // INVALID } private void run2(){ } protected void run3(){ } public void run4(){ } } One and only! 
  • 19. JAVA MODIFIERS, cont’d 19  static entities belong to the class;  interfaces cannot be final;  no abstract ctors;  no static ctors;  no final ctors;  only final inside methods, ctors or initers;  sneaky ctors: static & non-static semantics. SUGGESTED PATTERN TO MEMORIZE QUESTION: What about abstract static void run() ? is it possible? and why?
  • 20. PRIORITY OF OPERATORS 20 1 of 2 FULL FORM
  • 21. PRIORITY OF OPERATORS, cont’d 21 2 of 2 FULL FORM
  • 22. PRIORITY OF OPERATORS, cont’d 22  postfix / prefix increment / decrement operators are of the top priority;  all arithmetic ops including comparison come before equality testing;  assignment, including its compound forms, is of the lowest priority. TO MEMORIZE:
  • 23. ASSUMPTIONS 23  Missing package and import statements: If sample code does not include package or import statements, and the question does not explicitly refer to these missing statements, then assume that all sample code is in the same package, and import statements exist to support the code. Typical; used in most of the questions that use core Java classes outside of java.lang such as java.io.IOException, java.util.List, java.util.function.Predicate and so on. Source: Oracle Univ.
  • 24. ASSUMPTIONS, cont’d 24  No file or directory path names for classes: If no file names or directory locations of classes  assume one of the following, whichever enables the code to compile and run: – All classes are in one file; – Each class is contained in a separate file, and all files are in one directory. Also quite common.
  • 25. ASSUMPTIONS, cont’d 25  Unintended line breaks: Sample code may have unintended line breaks. If you see a line of code that looks like it has wrapped, and this creates a situation where the wrapping is significant (for example, a quoted string literal has wrapped), assume that the wrapping is an extension of the same line, and the line does not contain a hard carriage return that would cause a compilation failure. Didn’t meet this one; all code is pretty-typed.
  • 26. ASSUMPTIONS, cont’d 26  Code fragments: A code fragment is a small section of source code that is presented without its context. Assume that all necessary supporting code exists and that the environment fully supports the correct compilation and execution of the code shown and its omitted environment. A good half of the questions contains such code fragments.
  • 27. ASSUMPTIONS, cont’d 27  Descriptive comments: Take descriptive comments, such as "setters and getters go here," at face value. Assume that correct code exists, compiles, and runs successfully to create the described effect. Met it once, in the form “setter and getter methods go here”.
  • 28. WORD OF CAUTION 28 WEB RESOURCES: heavy reliance not advisable “For convenience, the Java compiler automatically imports three entire packages for each source file: (1) the package with no name, (2) the java.lang package, and (3) the current package (the package for the current file).” Current JLS8 (Chapter 7, Packages, preamble): A package consists of a number of compilation units. A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang.” NB
  • 29. STUDY TIPS & SUGGESTIONS 29  Keep a written record of your errors;  Start and finish your day by going through this list of failures;  Use colors, invent mnemonic formulas;  Draw pictures on paper and in your mind;  Do not worry much about the ‘Extra’ stuff;  Concentrate instead on the ‘Core’ rules because… …you will encounter something very close to them on the exam.
  • 30. REMINDER: THE ‘QUOC’ PRINCIPLE 30 questio n options code

Editor's Notes

  • #14: RWJ.bat: echo off rem ********************************************************************************** rem * RWJ.bat: Compiles Java classes and launches JVM * rem * Coded by Igor Soudakevitch; www.igor.host * rem * Distributed under the terms and conditions of the GPL * rem ********************************************************************************** rem ver.0.18 / Jan.24, 2016 / rem ----------------- Just a reminder: javac & JVM invocation ----------------------- rem javac -encoding UTF-8 -d C:\Garbage\classes org\xlator\_main_class_.java rem java -cp C:\Garbage\classes org.xlator._main_class_ rem Resulting cp dir structure: C:\Garbage\classes\org\xlator rem Suppose we’ve got RunMe.java with a reference to ClassA, which is defined in rem ClassA.java located in the same dir. Both classes belong to the same package rem org.xlator, and are located in the _whatever_dir_\org\xlator. rem In this case run from _whatever_dir_: rem javac .\org\xlator\RunMe.java where .\ is actually redundant rem java org.xlator.RunMe rem Source files should be UTF-8 encoded to correctly support Unicode output rem ------------------ End of introductory comments --------------------------------- rem This is THE ONLY place to mutate settings; refer to ’RULES’ below set args=1234 1Z0-808 5678 set packaged=ON set javac_d_switch_cp=C:\Garbage\classes set package_name=org.xlator set pack_root_dir=C:\Try_Java set dos_pack_path=org\xlator set added_path1=tempa set added_path2=tempb set all_added=.\%added_path1%;.\%added_path2% set enc=-encoding UTF-8 rem set enc= set enc_type=UTF-8 rem set enc_type= rem set Xlint= set Xlint=-Xlint:unchecked set warn= rem set warn=-nowarn rem set Xdiags= set Xdiags=-Xdiags:verbose set add_cp=;%CLASSPATH% rem set add_cp= set removal=ON rem set removal=NO rem RULES: rem Added paths must be present BELOW %pack_root_dir%, e.g.: rem C:\ rem |--- .......... rem |--- Try_Java rem | | rem | |--- org rem | | |--- xlator rem | | rem | |--- tempa rem | |--- tempb rem |--- .......... rem --- ’packaged’ var defines whether the source files contain the package statements rem --- If packaged==NO then classes will be compiled and run according to rem --- the ’simple_process’ section (i.e., within the current dir) rem --- If packaged==YES then the compiled classes will be placed inside rem --- the javac_d_switch_cp dir that is to be used with -d switch (ref.to javac -help) if "%enc%" == "" ( set enc_flag=OFF ) ELSE ( set enc_flag=ON ) if "%add_cp%" == "" ( set add_cp_flag=OFF ) ELSE ( set add_cp_flag=ON ) if "%warn%" == "" ( set warn_flag=ON ) ELSE ( set warn_flag=OFF ) if "%Xlint%" == "" ( set Xlint_flag=OFF ) ELSE ( set Xlint_flag=ON ) if "%Xdiags%" == "" ( set Xdiags_flag=OFF ) ELSE ( set Xdiags_flag=ON ) if "%packaged%" == "ON" ( goto packaged_process ) ELSE ( goto simple_process ) :simple_process echo. echo. echo ------------------------------- FYI ----------------------------------- echo. echo args : %args% echo main class package : void echo package path : void echo referenced class package(s) : void echo javac -d switch classpath : void echo appended CLASSPATH env var : void echo forced encoding : %enc_flag% (%enc_type%) echo -Xlint:unchecked : %Xlint_flag% echo -Xdiags:verbose : %Xdiags_flag% echo warnings : %warn_flag% echo *.class removal : %removal% echo. echo -------------------- End of batch file messages ----------------------- echo. echo. echo. javac %enc% %Xlint% %Xdiags% %1 java -cp . %~n1 echo. echo ****************************************************************************** echo * all classes in the current dir(s) will be removed now; hit ^^C to abort * echo ****************************************************************************** echo. if "%removal%" == "ON" del *.class pause exit :packaged_process cls rem The following ’if’ checks whether the specified dir exists rem because a special file named ’nul’ is present in every dir. rem And one more thing: the ’exist’ test only checks for *files*; rem that’s precisely why we have to use \nul if exist %javac_d_switch_cp%\nul goto get_to_it echo * echo * echo ******************************************************* echo * Packaged mode is ON but echo * %javac_d_switch_cp% dir doesn’t exist echo ******************************************************* echo * echo * set /p answer=Do you want to create it now (Y/N)? if /i "%answer:~,1%" EQU "Y" goto create_dir if /i "%answer:~,1%" EQU "N" goto exiting :create_dir md %javac_d_switch_cp% echo. echo. if not errorlevel 1 ( echo %javac_d_switch_cp% dir created successfully. ) ELSE ( echo Uh-huh! Couldn’t create %javac_d_switch_cp% dir! echo. echo. pause exit ) goto get_to_it :exiting echo. echo. echo I ain’t got nothing to do then. Bye. echo. echo. pause rem to set errorlevel, use ’\b’ switch on exit, like this: exit \b exit :get_to_it echo. echo. echo ------------------------------- FYI ----------------------------------- echo. echo args : %args% echo main class package : %package_name% echo package path : %pack_root_dir%\%dos_pack_path% echo referenced class package(s) : %pack_root_dir%\%added_path1%;%pack_root_dir%\%added_path2% echo javac -d switch classpath : %javac_d_switch_cp%\%dos_pack_path% echo appended CLASSPATH env var : %add_cp_flag% echo forced encoding : %enc_flag% (%enc_type%) echo -Xlint:unchecked : %Xlint_flag% echo -Xdiags:verbose : %Xdiags_flag% echo warnings : %warn_flag% echo *.class removal : %removal% echo. echo -------------------- End of batch file messages ----------------------- echo. echo. echo. cd %pack_root_dir% javac %enc% -cp %all_added%%add_cp% -d %javac_d_switch_cp% %Xlint% %Xdiags% %1 java -cp %javac_d_switch_cp%%add_cp% %package_name%.%~n1 %args% echo. echo **************************** CLEANING UP ****************************** echo * all classes in -d cp dir(s) will be removed now; hit ^^C to abort * echo *********************************************************************** echo. pause if "%removal%" == "ON" ( del %javac_d_switch_cp%\%dos_pack_path%\*.class if exist %javac_d_switch_cp%\%added_path1%\*.class del %javac_d_switch_cp%\%added_path1%\*.class if exist %javac_d_switch_cp%\%added_path2%\*.class del %javac_d_switch_cp%\%added_path2%\*.class )
  • #15: ClassA.java: ======================================= package tempa; public class ClassA{ public String name; public ClassA(){ name = this.getClass().getSimpleName(); } public ClassA(String name) { this.name = name; } } ClassB.java: ======================================= package tempb; import tempa.*; public class ClassB extends ClassA{ public ClassB(String name){ super(name); } } MyClass.java: ======================================= package org.xlator; import tempa.*; import tempb.*; public class MyClass { public static void main(String[] args) { ClassA ca = new ClassA(); ClassB cb = new ClassB("ClassB"); System.out.println(ca.name + ", " + cb.name + ", " + args[1]); } }