Java

Java

Introducing the Java  and Oracle Platforms

Objectives


After completing this lesson, you should be able to do the following:

 •Identify the key elements of Java

 •Describe the role of the Java Virtual Machine (JVM)

 •Describe how Java is used to build applications

 •Identify the key components of the Java SE Java Development Kit (known as JDK or SDK) 

•List Java deployment options 

•Recognize how the JDeveloper IDE supports the development of Java applications


What Is Java?

Java:

Is a platform and an object-oriented language

Was originally designed by Sun Microsystems for consumer electronics

Contains a class library

Uses a virtual machine for program execution

Key Benefits of Java

Object-oriented

Interpreted and platform independent

Dynamic and distributedMultithreaded

Robust and secure


Object-Oriented Approach

Objects and classes:

An object is a run-time representation of a “thing.”

A class is a “static definition of things.”

Class models elaborate:

Existing classes and objects

Behavior, purpose, and structure

Relationships between classes

Relationships between run-time objects

Class models are used throughout the project.

Design Patterns

A design pattern describes a proven solution to a recurring design problem.

Why use design patterns?

They have been proven.

They are reusable.

They are expressive.

The MVC Design Pattern

The Model-View-Controller (MVC) design pattern:

Is one of the most popular architectural patterns for object-oriented design

Splits an application into three distinct parts:

The Model handles data and logic.

The View handles output.

The Controller handles input.

Platform Independence

Java source code is stored as text in a .java file.

The .java file is compiled into .class files.

A .class file contains Java bytecodes (instructions).

The bytecodes are interpreted at run time.The Java .class file is the executable code.


Using Java with Enterprise Internet Computing

Using the Java Virtual Machine

How Does the JVM Work?

•The class loader loads all required classes. 

  • The JVM uses a CLASSPATH setting to locate class files.

 •The JVM Verifier checks for illegal bytecodes.

 •The JVM Verifier executes bytecodes.

  •  The JVM may invoke a just-in-time (JIT) compiler. 

•Memory Manager releases memory used by the dereferenced object back to the OS. 

  • The JVM handles garbage collection.

Benefits of JIT Compilers

JIT compilers:

 •Improve performance 

•Are useful if the same bytecodes are executed repeatedly 

•Translate bytecodes to native instructions 

•Optimize repetitive code, such as loops 

•Use Java HotSpot VM for better performance and reliability


Implementing Security in the Java Environment

Deployment of Java Applications

Client-side deployment:

  • JVM runs stand-alone applications from the command line
  • Classes load from a local disk, eliminating the need to load classes over a network

Server-side deployment:

  • Serves multiple clients from a single source
  • Is compatible with a multitier model for Internet computing

Using Java with Oracle 11g

Java Software Development Kit

Sun Java SE (known as JDK and Java SDK) provides:

  • Compiler (javac)
  • Core class library
  • rt.jar
  • Debugger (jdb)
  • Bytecode interpreter: JVM (java)
  • Documentation generator (javadoc)
  • Java Archive utility (jar)
  • Others

Using the Appropriate Development Kit

Java comes in three sizes:

 •Java ME (Micro Edition): Version specifically targeted to the consumer space

 •Java SE (Standard Edition): Complete ground-up development environment for the Internet 

•Java EE (Enterprise Edition): Everything in Java SE plus an application server and prototyping tools 

–*Earlier releases of Java used the following naming convention: J2ME, J2SE, and J2EE


Java SE 6

Highlights of technology changes in Java SE 6 include enhancements to:

  • The Collections Framework
  • Deployment by using Java Web Start and Java Plug-in
  • Internationalization support
  • Input/output (I/O)
  • Security support

Integrated Development Environment

Summary

In this lesson, you should have learned how to:

 •Identify the key elements of Java 

•Describe the key benefits of Java 

•List the key components of the Java SE Java Development Kit (known as JDK or SDK) 

•List the Java deployment options 

•Recognize how the JDeveloper IDE supports the development of Java applications


Arithmetic Operators

Which of the following can be operands of arithmetic operators?ultiple choice question

  • Numeric
  • Boolean
  • Characters
  • Both Numeric & Characters

Modulus operator, %, can be applied to which of these?

  • Integers
  • Floating – point numbers
  • Both Integers and floating – point numbers.
  • None of the mentioned

Decrement operator, –, decreases value of variable by what number?

  • 1
  • 2
  • 3
  • 4

Which of these statements are incorrect?

  • Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms.
  • Assignment operators run faster than their equivalent long forms.
  • Assignment operators can be used only with numeric and character data type.
  • None

What is the output of this program below ?


  • 1 1
  • 0 1
  • 1.5 1
  • 1.5 1.0

Bitwise Operators

Which of these is not a bitwise operator?

  • &
  • &=
  • |=
  • ^

Which of these statements are incorrect?

  • The left shift operator, <<, shifts all of the bite in a value to the left specified number of times.
  • The right shift operator, >>, shifts all of the bite in a value to the right specified number of times.
  • The left shift operator can be used as an alternative to multiplying by 2.
  • The right shift operator automatically fills the higher order bits with 0.

What is the output of this program shown below ?


  • 42 42
  • 43 43
  • 42 -43
  • 42 43

Untitled multiple choice question

  • Put your answer option here
  • Put your answer option here

Relational Operators and Boolean Logic Operators

What is the output of relational operators?

  • Integer
  • Boolean
  • Characters
  • Double

Class Fundamentals & Declaring objects

What is the stored in the object obj in following lines of code?

  • Memory address of allocated memory of object.
  • NULL
  • Any arbitrary pointer
  • Garbage

Which of these keywords is used to make a class?

  • class
  • struct
  • int
  • None of the mentioned

Which of the following is a valid declaration of an object of class Box?

  • Box obj = new Box();
  • Box obj = new Box;
  • obj = new Box();
  • new Box obj;

Which of these operators is used to allocate memory for an object?

  • malloc
  • alloc
  • new
  • give

Which of these statement is incorrect?

  • Every class must contain a main() method.
  • Applets do not require a main() method at all.
  • There can be only one main() method in a program.
  • main() method must be made public.

Which of the following statements is correct?

  • Public method is accessible to all other classes in the hierarchy
  • Public method is accessible only to subclasses of its parent class
  • Public method can only be called by object of its class.
  • Public method can be accessed by calling object of the public class.

What is the output of this program shown below ?


  • 0
  • 1
  • Runtime error
  • Garbage value

Core Java API Packages

Which of these package is used for graphical user interface?

  • java.applet
  • java.awt
  • java.awt.image
  • java.io

Which of these package is used for analyzing code during run-time?

  • java.applet
  • java.awt
  • java.io
  • java.lang.reflect

Which of these package is used for handling security related issues in a program?

  • java.security
  • java.lang.security
  • java.awt.image
  • java.io.security

Which of these class allows us to get real time data about private and protected member of a class?

  • java.io
  • GetInformation
  • ReflectPermission
  • MembersPermission

Which of these package is used for invoking a method remotely?

  • java.rmi
  • java.awt
  • java.lang.text
  • java.text.mofify

Inheritance – Abstract Class and Super

Which of these keywords are used to define an abstract class?

  • abst
  • abstract
  • Abstract
  • abstract class

Which of these is not abstract?

  • Thread
  • AbstractList
  • List
  • None of the Mentioned

If a class inheriting an abstract class does not define all of its function then it will be known as?

  • abstract
  • A simple class
  • Static class
  • None of the mentioned

Which of these is not a correct statement?

  • Every class containing abstract method must be declared abstract.
  • Abstract class defines only the structure of the class not its implementation.
  • Abstract class can be initiated by new operator.
  • Abstract class can be inherited.

Which of these packages contains abstract keyword?

  • java.lang
  • java.util
  • java.io
  • java.system

Generic Methods

What are generic methods?

  • Generic methods are the methods defined in a generic class.
  • Generic methods are the methods that extend generic class’s methods.
  • Generic methods are methods that introduce their own type parameters.
  • Generic methods are methods that take void parameters.

Which of these type parameters is used for a generic methods to return and accept any type of object?

  • K
  • N
  • T
  • V

Which of these type parameters is used for a generic methods to return and accept a number?

  • K
  • N
  • T
  • V

Which of these is an correct way of defining generic method?

  • name(T1, T2, …, Tn) { /* … */ }
  • public name { /* … */ }
  • class name[T1, T2, …, Tn] { /* … */ }
  • name{T1, T2, …, Tn} { /* … */ }

Which of the following is incorrect statement regarding the use of generics and parameterized types in Java?

  • Generics provide type safety by shifting more type checking responsibilities to the compiler.
  • Generics and parameterized types eliminate the need for down casts when using Java Collections.
  • When designing your own collections class (say, a linked list), generics and parameterized types allow you to achieve type safety with just a single class definition as opposed to defining multiple classes.
  • All of the mentioned

Which of the following allows us to call generic methods as a normal method?

  • Type Interface
  • Interface
  • Inner class
  • All of the mentioned

Collection Framework Overview

Which of these packages contain all the collection classes?

  • java.lang
  • java.util
  • java.net
  • java.awt

Which of these classes is not part of Java’s collection framework?

  • Maps
  • Array
  • Stack
  • Queue

Which of these methods deletes all the elements from invoking collection?

  • clear()
  • reset()
  • delete()
  • refresh()

What is Collection in Java?

  • A group of objects
  • A group of classes
  • A group of interfaces
  • None of the mentioned

Java.lang – Boolean Wrapper Advance

Which of these methods of Boolean wrapper returns boolean equivalent of an object.

  • getBool()
  • booleanValue()
  • getbooleanValue()
  • getboolValue()

Which of the following constant are defined in Boolean wrapper?

  • TRUE
  • FLASE
  • TYPE
  • All of the mentioned

Which of these methods return string equivalent of Boolean object?

  • getString()
  • toString()
  • converString()
  • getStringObject()

Which of these methods is used to know whether a string contains “true”?

  • valueOf()
  • valueOfString()
  • getString()
  • None of the mentioned

Which of these class have only one field?

  • Character
  • Boolean
  • Byte
  • void

Access Control

Which of these access specifiers must be used for main() method?

  • private
  • public
  • protected
  • None of the mentioned

Which of these is used to access member of class before object of that class is created?

  • public
  • private
  • static
  • protected

Which of these is used as default for a member of a class if no access specifier is used for it?

  • private
  • public
  • public, within its own package
  • protected