Programming in Java Notes
Subject Overview
Programming in Java covers OOP fundamentals and Java language basics, classes/
Subject at a glance
4
Units
39
Topics
5
Credits
4
Infographics
Unit-wise Syllabus
4 units — open any unit for detailed topic-wise notes, diagrams and important exam questions
- Object-oriented paradigm basics
- Java history and features
- differences from C/C++
- Java environment
- simple Java program structure
- tokens and statements
- constants/variables/data types
- operators and expressions
- decision making/branching/looping statements
- 1Write .java source
- 2javac compiles to bytecode
.class file
- 3JVM loads the class
- 4Bytecode verifier checks it
- 5JIT compiles and runs it
Write once, run anywhere
Study guide
This unit introduces Java: the OOP basics, history and features, differences from C and C++, the Java environment, program structure, tokens, constants, variables, data types, operators and expressions and decision-making and looping. Write and run a small program to understand compilation to bytecode.
- Defining classes
- adding variables and methods
- creating objects
- constructors
- method overloading
- static members
- extending a class
- overriding methods
- final variables/methods/classes
- arrays/jagged arrays/strings/vectors
- defining and implementing interfaces
- multiple inheritance via interfaces
- creating and accessing packages
Where
Same class
Subclass
Signature
Different parameters
Same parameters
Binding
Compile time
Run time
Purpose
Same name, different inputs
Change inherited behaviour
Study guide
You study classes and objects, constructors, method overloading, static members, inheritance, overriding, final, arrays, strings, vectors, interfaces, multiple inheritance through interfaces and packages. Understand why Java uses interfaces instead of multiple inheritance of classes.
- Types of errors and exceptions
- try/catch/finally blocks
- throwing custom exceptions
- applet life cycle
- creating executable applets
- passing parameters
- the Graphics class
- drawing lines/rectangles/circles/ellipses/arcs/polygons
- line graphs and bar charts
- 1. init(): Called once to set up
- 2. start(): Applet becomes active
- 3. paint(): Draws on screen
- 4. stop(): Applet leaves view
- 5. destroy(): Final clean-up
Study guide
You study errors and exceptions, try, catch and finally, custom exceptions, the applet life cycle, applets, passing parameters, the Graphics class and drawing shapes, line graphs and bar charts. Note that applets are now obsolete in browsers but the concepts of graphics remain useful.
- Java AWT package containers
- UI components and layouts
- event delegation approach
- ActionListener/MouseListener/WindowListener/KeyListener
- I/O file handling — input/output streams
- FileInputStream/FileOutputStream
- reader/writer streams
- random access files
- 1User acts
Clicks a button
- 2Source creates an event object
ActionEvent
- 3Event sent to registered listener
- 4Listener method runs
actionPerformed()
Study guide
You study AWT containers, components and layouts, event delegation, listener interfaces and I/O: streams, file input and output, reader and writer streams and random access files. Build a small GUI application that responds to events.
Why Programming in Java Matters
Java is one of the most widely used enterprise languages and the base of Android development, so it opens many job opportunities. It is also common in campus placement coding tests.
How to Prepare for Programming in Java
- Code every concept and run it; Java is learned by writing programs.
- Learn exception handling and collections thoroughly.
- Build a small project, such as a student management application.
Programming in Java: Frequently Asked Questions
Why is Java called platform independent?
Java source code compiles into bytecode that runs on the Java Virtual Machine, which is available for many operating systems.
What is the difference between an interface and an abstract class?
An interface defines method signatures that implementing classes must provide, while an abstract class can also hold implemented methods and state.
