Java Complete Exam Flashcards
Java Complete Exam Flashcards
Java was developed by James Gosling at Sun Microsystems in 1995. Originally called Oak, it was designed
for embedded systems but evolved into a full-featured programming language for building cross-platform
applications. It became popular due to its portability, enabled by the Java Virtual Machine (JVM).
Bytecode
Bytecode is an intermediate representation of Java code, generated after compiling a Java source file. It is
platform-independent and executed by the Java Virtual Machine (JVM), enabling Java's 'write once, run
anywhere' capability.
Java Buzzwords
Iteration Statements
Jump Statements
Class Fundamentals
Classes are blueprints for objects. They contain fields (variables) and methods (functions). Syntax:
Declaring Objects
To create an object: ClassName obj = new ClassName(); This allocates memory and invokes the constructor.
Constructors initialize objects. They have the same name as the class and no return type. 'this' refers to the
Java handles memory using automatic garbage collection. The finalize() method is called before an object is
Java Programming - Exam Flashcards
Overloading: Defining multiple methods with the same name but different parameters. Recursion: A method
Access modifiers (public, private, protected, default) control visibility. Static members belong to the class
Final Keyword
Inheritance Basics
Allows a new class (subclass) to inherit members from an existing class (superclass). Syntax: class Subclass
extends Superclass {}
super refers to the parent class. It is used to access superclass methods/constructors. Constructors in the
A class inherits from a subclass which itself inherits from another class. Overriding allows redefining a
Determines which method to call at runtime based on the object type. Enables polymorphism.
Abstract classes contain abstract methods (no body) and cannot be instantiated. The final keyword prevents
Packages group related classes. Access protection controls visibility outside the package. Use import to
Interfaces
Defines a contract for classes. Contains abstract methods only. A class implements an interface using
'implements' keyword.
An exception is an abnormal condition. Java handles them using try-catch-finally blocks. try encloses code
Checked (compile-time) and Unchecked (runtime) exceptions. Multiple catch blocks handle different
try blocks can be nested for more precise error handling. throw manually throws an exception. throws
finally always executes, used for cleanup. Custom exceptions are created by extending Exception class.
Multithreading allows concurrent execution. The main thread starts automatically in a Java program.
Threads can be created by extending Thread or implementing Runnable. join() waits for a thread to finish.
Thread priority affects scheduling. Synchronization prevents data inconsistency when multiple threads access
shared resources.
Java Programming - Exam Flashcards
Interthread Communication
Threads communicate using wait(), notify(), and notifyAll() methods. These are used to coordinate actions
among threads.
The java.io package provides classes for file handling. Files are handled using FileInputStream,
Stream Classes
Streams are used to read/write data. Byte streams handle raw binary data, while character streams handle
text.
Applets are small Java programs run in a browser or viewer. Lifecycle methods: init(), start(), paint(), stop(),
destroy().
Two types: local (via viewer) and remote (via browser). Applet architecture includes lifecycle methods and
Display output using paint(). repaint() requests the applet to redraw itself.
Use showStatus() to show messages in the browser's status bar. The APPLET tag embeds applets in HTML.
Use <param> in HTML to pass parameters. getDocumentBase() returns page URL; getCodeBase() returns
AppletContext allows communication between applets. showDocument() opens a webpage from the applet.