Docsity

Java Certification 8 SE Questions with solved solutions, Exams of Java Programming

Toggle sidebar
bg1
Java Certification 8 SE Questions with solved
solutions
Reference Types - ANSWER>>Refers to an object, doesn't hold the value of the object they
refer to, and stores the memory address where the object is located. Can be assigned null.
Object - ANSWER>>Instance of a class
Primitive Types - ANSWER>>Boolean, int, byte, double, float, long, don't have methods
declared to them.
Literal - ANSWER>>Fixed value that doesn't need further calculations in order to be
assigned to a variable
Local Variables - ANSWER>>Defined within a method, must be initialized before use. In
scope from declarations to end of block
System.gc() - ANSWER>>Tells java system now may be a good time for Java to kick a
garbage collection run
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Java Certification 8 SE Questions with solved solutions and more Exams Java Programming in PDF only on Docsity!

Java Certification 8 SE Questions with solved

solutions

Reference Types - ANSWER>>Refers to an object, doesn't hold the value of the object they refer to, and stores the memory address where the object is located. Can be assigned null. Object - ANSWER>>Instance of a class Primitive Types - ANSWER>>Boolean, int, byte, double, float, long, don't have methods declared to them. Literal - ANSWER>>Fixed value that doesn't need further calculations in order to be assigned to a variable Local Variables - ANSWER>>Defined within a method, must be initialized before use. In scope from declarations to end of block System.gc() - ANSWER>>Tells java system now may be a good time for Java to kick a garbage collection run

Object not reachable when: - ANSWER>>No longer has reference pointing to it & All references to the object have gone out of scope. Finalize() - ANSWER>>Only run when object eligible for garbage collection, call could run zero or one time Abstraction in 3 ways - ANSWER>>Hiding details of process from a requestor, defining contract for client & service provider, & defying a contract for all providers before servicing to it's clients Two ways of Abstracting Data - ANSWER>>Through Interface & Abstraction Classes Abstract Class - ANSWER>>1) Class that cannot be instantiated

  1. Modifier makes abstract class
  2. Abstract class but need not have abstract method but concrete class cannot have abstract method Default Value of int num Instance Variable - ANSWER>> Default Value of double d instance variable - ANSWER>>0. Which of the following can null be assigned to in String S Object o

Can import single class/interface. Use asterisk to import all public members Compile Failures- Package Statement - ANSWER>>Package statement at end of class definition Package statement within class definition Multiple package statements for class Compile Failures- Import Statement - ANSWER>>Import Statement appears before package statement. Class Declaration Components - ANSWER>>Access Modifiers Non-access modifiers Class keyword Name of class extends name of base class implements name of implemented interfaces {} Class body within {} (Fields, methods, constructors)

Class - ANSWER>>Design to specify properties and behaviors of an object. Design from which an object can be created Class Variables - ANSWER>>Implements properties of an object, In scope from declaration until program ends Class Methods - ANSWER>>Implement behavior of an object, includes optional argument list Class state - ANSWER>>Defined using attributes or instance variables Class Definition Components - ANSWER>>Attributes or instance variables Methods optional arguments Constructors Comments Instance Variables - ANSWER>>In scope from declaration until object garbage is collected, used to store object state Defined in the class but are outside of the class methods. Each object has it's own copy that isn't shared Instance Attributes - ANSWER>>used to store object states Defined in the class but are outside of the class methods.

Public interface - ANSWER>>Name must match source file name One public interface/class per source file Compiler Errors- Public interface/Class - ANSWER>>Only one public interface/class per source file Java application - ANSWER>>Multiple source code files, one containing executable class Executable Class - ANSWER>>JVM starts execution at main method Main Method - ANSWER>>Method that much accept an argument of a string array or a variable argument of type String public static /status void main Subpackages - ANSWER>>Used for GUIs, database access & networking Import static - ANSWER>>To import a static class member or all static members Accessing all public static members: import static Class definition - ANSWER>>Can only use public or default access modifiers for top class

Top level class - ANSWER>>Defined using only default or Public Access modifiers, isn't defined within another class, not a nested class Access Modifier - ANSWER>>Controls accessibility of class/interface and it's members(methods/variables) Can apply to class, interface and their members(instance and class variables and methods) Cannot apply to local variables Cannot apply to method parameters 4 Types of Access Modifiers - ANSWER>>Public, protected, private, default Default Access - ANSWER>>Access when a class, interface, method, or variable is defined without an explicit access modifier Public Access - ANSWER>>Least restrictive, access across all packages including derived and unrelated classes Protected Access - ANSWER>>Accessible a class/interface in the same package or derived classes in separate packages Derived class can inherit and access protected members of its base class regardless of the package in which its defined, BUT a derived class in a separate package can't access protected members of its base class using reference variables

volatile [variable] - ANSWER>>1) Non-access modifier

  1. Value can be safely modified by different threads
  2. Cannot use with classes, interfaces, methods Abstract modifier - ANSWER>>Non-access modifier, can use with classes/interfaces/methods, can't use with variables Abstract interface - ANSWER>>1) Interface is abstract by default
  3. Interface cannot be instantiated
  4. No need to add "abstract" keyword to interface definition Abstract method - ANSWER>>1) An abstract method doesn't have a body; this means no {} after the method even if {} is empty
  5. An abstract method is typically implemented by a derived class Final modifier - ANSWER>>1) Non-access modifier
  6. Can use with classes, variables, methods
  7. Cannot use with interfaces because interface is abstract by default Final class - ANSWER>>Can't be extended by another class

Final variable - ANSWER>>Can be assigned a value only once and can't reassign a new value, can call a method on it Final method - ANSWER>>Cannot be overridden by a derived class Override method - ANSWER>>Has same signature as base class method Static modifier - ANSWER>>Non access and can use with classes, variables, methods, and interfaces Constants - ANSWER>>Use final and static to define variables who's values cannot change Define them as static allows them to be used across classes and objects Static variables and methods - ANSWER>>1) If non-private, they are inherited by derived classes.

  1. Cannot override static members in a derived class but can redefine them Primitive Data Types - ANSWER>>Char, byte, short, int, long, float, double, boolean Boolean variabel - ANSWER>>can only have literal values of true or false Byte Data Type - ANSWER>>Size: 8 bits
  1. Decimal 9 = Octal 11; 10=12, 11=13; 12=14; 13=15; 14=16; 15=17; 16=
  2. Keep dividing by 8 and record the remainder in reverse order
  3. int intValue = 034; // 28 in decimal int six = 06; // Equal to decimal 6 int seven = 07; // Equal to decimal 7 int eight = 010; // Equal to decimal 8 int nine = 011; // Equal to decimal 9
  4. Literal prefix: 0 Float data type - ANSWER>>1) Less space and smaller range of numbers than double; less precision
  5. Size: 32 bits
  6. f or F; use to distinguish from the default double for decimal numbers
  7. Cannot use to store integer Double Data type - ANSWER>>Size: 64 bits Default decimal literal d or D but not necessary because default for a decimal number Can't use to store integer char - ANSWER>>Single, 16 bit unicode character
  8. Stored as tnsigned integer but can force, e.g.,

char c3 = (char)- 122

  1. Values: \u0000 (or 0) to \uffff (or 65,535)
  2. Use single quotes: 'D'; double quotes for String not char
  3. 122 is base 10 - z; \u0122 is base 16 (0-9; a-f)
  4. Because stored as integer can be used in arithmetic expressions Identifier - ANSWER>>Names of packages, classes, interfaces, methods, variables Allowed- underscore, lowercase, currency Not Allowed- hyphen Keywords - ANSWER>>abstract, assert, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, enum, extends, false, final, finally, float, for, goto, if, implements Object reference variable - ANSWER>>A handle to an object that allows you to access its attributes Object reference - ANSWER>>-A memory address that points to a memory area where an object's data is stored
  • When an object is instantiated with the "new" operator, a heap-memory address to the object is returned and the address is usually assigned to the reference variable

Relational operators - ANSWER>>Compare primitives < <= > >= == != Used to determine whether a primitive value is equal to, less than or greater than another value Result is always true or false Cannot compare incomparable values Logical operators - ANSWER>>Apply NOT, AND, OR logic to primitives I, &&, II Return a boolean value Assignment operator = - ANSWER>>= , used to initialize variables with values, used to reassign new values to variables Assignment operator += - ANSWER>>+=, first add then assign a +=b means a = a + b Assignment operator - = - ANSWER>>-=, first subtract then assign a - = b means a = a - b Assignment operator *= - ANSWER>>multiply then assign a = b means a = ab

Assignment operator /= - ANSWER>>divide then assign a /=b means a = a/b Modulus operator - ANSWER>>% remainder in division 10 % 6 = 4 Unary increment operator - ANSWER>>++ increments by 1 ++10 = 11 Unary decrement operator - ANSWER>>-- decrements by 1 --10 = 9 Logical AND && - ANSWER>>evaluates to true if all operands are true Logical OR II - ANSWER>>evaluates to true if any or all of the operands is true Logical negotiation! - ANSWER>>negates the boolean value and evaluates to true or false

Advantages of Exceptions - ANSWER>>Improving program structure because error handling code separated from normal program function, programmer can choose where to handle he exceptions & allows for new exceptions that are tailored to the particular program An abstract class can be implemented by an interface T/F - ANSWER>>T An abstract class can be extended by a concrete class T/F - ANSWER>>T What is the scope of a class variable or static field? - ANSWER>>Available within all objects of the current class. What is included in a default constructor of a subclass? - ANSWER>>Invocation of the superclass. How many classes can be derived from a parent class? - ANSWER>>Infinite number How many times will statements in a block execute while(true)? - ANSWER>>An Infinite number Interfaces can extend classes T/F? - ANSWER>>False

Interfaces can extend other interfaces T/F? - ANSWER>>True Can you extend more than one class in java? - ANSWER>>No