[Go to site: main page, start]

0% found this document useful (0 votes)
3 views9 pages

Java Programming Concepts Explained

The document provides an overview of Java programming concepts, including class structure, methods, abstraction, encapsulation, polymorphism, exception handling, and input/output operations. It covers key topics such as constructors, collections, annotations, multithreading, and thread synchronization. Additionally, it explains the significance of access specifiers and the Java exception hierarchy.

Uploaded by

assignment99735
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views9 pages

Java Programming Concepts Explained

The document provides an overview of Java programming concepts, including class structure, methods, abstraction, encapsulation, polymorphism, exception handling, and input/output operations. It covers key topics such as constructors, collections, annotations, multithreading, and thread synchronization. Additionally, it explains the significance of access specifiers and the Java exception hierarchy.

Uploaded by

assignment99735
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Wipro TilentNext 2025

---
public class HelloWorld
public: This keyword means the class is accessible from
anywhere.

class: Declares a class, which is a blueprint for objects or a


container for code.

HelloWorld: The name of the class. It must match the


filename ([Link]).

public static void main(String[] args)


This is the main method, the entry point of every Java
program.

public: This method is accessible from anywhere.

static: It can be run without creating an instance of the class.

void: It doesn't return any value.

main: The name of the method Java looks for to start


execution.

String[] args: An array to receive command-line arguments.

[Link]("Hello, World!");
System: A built-in class in Java.
out: A static object of the PrintStream class connected to the
console.

println(): A method that prints the text and moves to the


next line.

"Hello, World!": The string that gets printed to the console.

Command-Line Arguments : Command-line arguments are


values passed to a Java program when you run it from the
command line

Abstraction : process of focusing on relevant detail and


leaving out the irrelevant detail
behaviour dikhna chahiye
attribute hide karna h

Abstract Class: Abstract methos ho sakta ha, Eska object nhi


ban sakta hai. Inherit kar sakta hai.

Encapsulation: wrapping up of attributes (data) and


behaviour in a single unit

Polymorphism: one name different form


-> Through method overloading
-> Through method overriding using
dynamic method dispatch

-> Access specifiers (public, private, default, protected)


-> Getter and Setter method
-> 'this' keywords
-> Method Overloading

-> 'static' member of class

-> Inheritance:
Advantage: Reusability

Provider is a super class (Super class is a parent class)


lene wala is a sub class/ child class (sub class is a child class)

-> Constructors
-> Constructors in Inheritance

Object Class: implicit of other class of super class

-> Method overloading: Jiske sath jayada matching ho uske


sath pahle perfect(prefare) karega

Interger: it is raper class in java

Exception: Run time error


-> Exception
-> Need for Exception handling
-> Java's default Exception handler and its
working..
-> Exception hander keyword
-> try
-> catch
-> finally
-> throw
-> throws

Exception class hierarchy


-> Exception
RunTimeException (Unchecked
Exception)
-> Error

Categories of Exception
-> Checked
-> Unchecked

User Define(Custom) Exception :

Protected access is not access in the class


Packages: similar class, and interface similar type of
interface
type of container related java element

package
Advantage
Namespace Resolution
Access Control
Package Creation
Package Usage

Input/Output (I/O)
I/O Steams
Byte Streams: Binary input taken
InputStream
FileInputStream
BufferedInputStream
OutputStream
FileInputStream

BufferedOutputStream
Character Streams: Character input
taken
Reader
FileReader
BufferedReader
InputStreamReader:
Convert character to bytes in input
Writer
FileWriter
BufferedWriter
OutputStreamWriter:
Convert character to bytes in output
Serialization(/Deserialization)

File Reading/ Writing


readNBytes: Read number of bytes. return type is bytes
array.

6 Method of file reading(InputStream methods which define)


i) .read()
ii) byte[] bytes = new byte[4]; // byte data type and bytes
variable name which is array type
fi[Link](bytes);
iii) fi[Link](bytes,1,2); // bytes means array name, 1 means
staring point, 2 means byte size such as |d|e|f|g| then
|d|h|i|g| change I and 2.
str = new String(bytes);
iv) str = new String(fi[Link](4)); // print after 4 bytes,
v) fi[Link](bytes,1,2); // same as methos iii. where,
readNBytes:- Read number of bytes
vi) str = new String(fi[Link]()); // print all the unread
bytes/ character.

For available chack then use : .available() methos use eg.-


fi[Link]();
For skip then use: .skip(byte skip (5)) use this method eg.:
fi[Link](5);

Notes:
When end of file then read() return the -1 values.
When end of file then readNBytes() return the 0 values.
Collection <> (Angular Bracket)
-> Common interface
-> add() : single add
-> addAll() : add all
-> clear() : clear all
->

Collections Framework
ArrayList
HashList
LinkedList
Queue
Set : In set not return duplicate
Map: key pair value store, it are not extends, not
contain duplicate,

Annotations:
Annotation: Used to provide metadata or
supplementary information
Built - in Annotations
User defined or Custom Annotation
Meta Annotation
Marker Annotation
Single Member Annotation + value field
concept of 'default' in annotation fields
Type Annotation
Repeatable

In single value annotation me, value rakhte ha to,


value likhna nhi hoga.
If annotation field ke value nhi dena ha to, default
value assign ho jayega.

When use the TYPE_USE annotation ko attribute, object,


parameter, and throws Exception k jagah pe use kar sakte
hai..

Wrapper

Multithreading
-> Thread
'Thread' class
Data Members
Member Methods
Constructors
Thread()

Thread(String threadName)

Thread(Runnable ref)

Thread(Runnable ref, String threadName)


Thread Creation
- Inheriting Thread Class
- Implementing Runnable
Interface
Thread States
Thread Synchronization

syntax: Way to write the code.


semantic :variable ability to change, if final variable then not
changes. Kya matlab nikalta ha use semantic kahte ha.

Thread[#1// thread number which is unique,main//


thread,5// priority,main// parent thread]

Inter Thread Communication


** object class method

Common questions

Powered by AI

Serialization in Java converts an object into a stream of bytes for file storage or network transmission, supporting persistent data storage by allowing objects to be restored to memory later. The reading of byte data from files can be conducted using several methods like 'read()', which reads a single byte, 'readNBytes()', which reads a specified number of bytes into an array, and 'readAllBytes()', which reads all remaining bytes. These methods of file reading ensure that byte data from files is efficiently managed for processes like serialization and deserialization, thus facilitating sequential processing and data storage flexibility .

Method overloading in Java occurs when multiple methods have the same name with different parameters within the same class. It is a compile-time polymorphism feature and allows a class to perform the same action in different ways. On the other hand, method overriding occurs when a subclass has a specific implementation for a method that is already defined in its superclass, allowing run-time polymorphism. While overloading adds versatility in method calls by using the same method name, overriding is used to provide specific implementations of a method, thereby enforcing specific behavior in subclasses .

Abstraction in Java focuses on exposing only the relevant functionalities while hiding the implementation details. This is primarily achieved through abstract classes and interfaces. By using abstraction, Java promotes modularity as it allows a programmer to focus on interacting with the abstract interfaces rather than the complex input-output details of the implementation. This results in a more organized code structure where changes in implementation do not affect the external interaction code, fostering easier maintenance and scalability. Moreover, abstraction supports the implementation of different behaviors using polymorphic interfaces, thereby achieving desired functionalities without changing the core logic .

The 'main' method in Java is declared as 'public static void main(String[] args)' and serves as the entry point of any Java program. It is crucial because it is the method that the Java Virtual Machine (JVM) calls to start the execution of the application. Marked as 'public', it can be accessed globally, 'static' so it can be called without creating an instance of the class, and 'void' meaning it does not return any value. The 'String[] args' allows the program to accept command-line arguments, which gives flexibility in providing inputs at runtime .

Java supports multithreading through the 'Thread' class and the 'Runnable' interface, which allow the creation and control of multiple threads executing concurrently. Threads can be created by extending the 'Thread' class or implementing the 'Runnable' interface. This enhances program design by improving performance through concurrent execution, increasing the responsiveness of programs, especially in user interfaces, and making efficient use of CPU resources. Multithreading also maximizes resource sharing by splitting a process into threads that share the same memory space, thus reducing the workload for the operating system and efficient management of large-scale applications .

Java packages provide namespace management by grouping related classes and interfaces, preventing name conflicts by ensuring that class names are unique within a package. They help define a coherent structuring of files to facilitate maintenance and provide clear access control. Packages offer access protection by defining access levels such as public, private, protected, and default, thereby controlling the scope of class and interface accessibility across different parts of a program. This results in enhanced security and modularization, encouraging the encapsulation of implementation details and the export of a clean API for external usage .

Using the 'Runnable' interface to create threads in Java is a flexible approach as it allows the class to extend another class while still being able to implement multithreading capabilities, achieving multiple inheritance. This means the thread behavior is defined within the 'run' method of the 'Runnable' interface. Meanwhile, extending the 'Thread' class binds the thread creation to a single inheritance hierarchy, providing convenience for simple applications but limiting design flexibility. Opting for 'Runnable' is generally more versatile, particularly for large applications where extending another superclass is necessary, thus adhering better to Java’s design principles .

Inheritance in Java allows one class (subclass) to inherit fields and methods from another class (superclass), promoting code reusability by enabling new classes to use existing class behaviors without altering them. This not only reduces redundancy by reusing inherited code but also simplifies maintenance as changes in the superclass reflect across subclasses automatically. Inheritance supports the DRY (Don't Repeat Yourself) principle, fostering hierarchical classification and organizational efficiency in code management. However, it should be used judiciously to avoid overly complex hierarchies and maintain a balance between inheritance and composition depending on the use case .

Exception handling in Java improves program reliability by allowing developers to manage runtime errors gracefully rather than letting a program crash. It is achieved using try-catch blocks to catch exceptions, ensuring that error conditions are addressed properly, and finally blocks to execute code regardless of exceptions. It also involves 'throw' and 'throws' clauses for handling exceptions thrown by methods. This systematic management of exceptions helps in maintaining the normal flow of the program, preventing the abrupt termination of execution and ensuring resources are freed appropriately. Efficient exception handling makes applications robust, reducing the risk of data corruption and enhancing user experience by providing meaningful error messages .

Encapsulation in Java involves wrapping data (attributes) and methods (behaviors) that operate on the data within a single class unit. This design principle helps in hiding the internal state and requiring all interaction to be performed through an object's methods, enhancing modularity and maintaining integrity by preventing external entities from accessing and altering the state directly. Encapsulation facilitates maintenance and modification of code since changes in one part of a program do not affect other parts, as long as the interface is consistent. It also allows for better data security and a more streamlined user interface .

You might also like