0% found this document useful (0 votes)
7 views5 pages

Java Notes 2

The document outlines key programming concepts including control structures such as selection and repetition, arrays, methods, and object-oriented programming principles. It also covers Java libraries, built-in methods for string manipulation, and advanced topics like exception handling and multithreading. Each section provides definitions and examples of various programming constructs and techniques.

Uploaded by

White Devil
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)
7 views5 pages

Java Notes 2

The document outlines key programming concepts including control structures such as selection and repetition, arrays, methods, and object-oriented programming principles. It also covers Java libraries, built-in methods for string manipulation, and advanced topics like exception handling and multithreading. Each section provides definitions and examples of various programming constructs and techniques.

Uploaded by

White Devil
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

Control Structures

• Selection Structure/Conditional Statement: Directs program


flow based on a condition.

o If-else Statement: Executes one block of code if a


condition is true, and another if false.

o Switch Statement: Allows for multiple branches of


execution based on the value of an expression
(e.g., int, String, enum).

o Break Statement: Used to terminate the execution of a


loop or a switch statement.

• Repetition Structure/Looping statement: Executes a block of


code repeatedly until a condition is met.

o Looping/Iterations: The process of repeating a set of


statements.

o While loop Statement: An entry-controlled loop that


repeats a block of code as long as a condition is true.

o Do while Loop Statement: An exit-controlled loop; the


code block is executed at least once, then the condition is
checked.

o For loop statement: A compact looping structure used


when the number of iterations is known in advance.

o Entry Control Loop: Condition is checked before the loop


body executes (e.g., for, while).

o Exit control loop: Condition is checked after the loop


body executes (e.g., do-while).
o Infinite Loop: A loop that runs indefinitely because its
termination condition is never met.

Arrays

• Array: A data structure that stores a fixed-size sequential


collection of elements of the same type.

o Definition, declaration, initialization, data


access: Fundamental operations involving creating and
using arrays.

Methods (Functions)

• User defined method: A block of code that performs a specific


task, created by the programmer.

• Static method: A method that belongs to the class rather than


an instance of the class.

• Calling Method & called method: The process of one method


invoking another.

• Void Return Type: Indicates that a method does not return any
value after execution.

Object-Oriented Programming (OOP)

• OOP: A programming paradigm based on the concept of


"objects," which can contain data and methods.

• Class & Object: A class is a blueprint or template, while


an object is an instance of a class.
• Data member & Method member: Variables (data members)
and functions (method members) that define the state and
behavior of an object.

• Class Design: The process of structuring classes to model real-


world problems effectively.

• Constructor: A special method used to initialize objects. It is


called when an object of a class is created.

• Access modifiers: Keywords (e.g., public, private, protected)


that set the accessibility level for classes, fields, methods, and
constructors [0.1.54 - implicitly general knowledge].

• Getter and Setter method: Methods used to retrieve (get) and


modify (set) the values of private data members.

Java Libraries and Built-in Methods

• Java Libraries: Collections of pre-written classes and methods


that can be used in programs.

• Scanner Class: Used to get user input from the console.

• ParseInt(), ParseDouble(), ParseFloat(): Static methods in


wrapper classes (Integer, Double, Float) used to convert a
String to a primitive numeric type.

• Sort(): Method used to sort an array.

• Binary Search(): Method for efficiently finding an element in a


sorted array.

• String/Character Methods:

o charAt(): Returns the character at a specific index.


o concat(): Appends one string to the end of another.

o contains(): Checks if a string contains a specified sequence


of characters.

o endsWith(): Checks if a string ends with a specified suffix.

o equals(): Compares two strings for equality (case-


sensitive).

o equalsIgnoreCase(): Compares two strings, ignoring case


considerations.

o indexOf(): Returns the index within a string of the first


occurrence of a specified character or substring.

o isEmpty(): Checks if a string is empty.

o length(): Returns the length of a string.

o replace(): Replaces occurrences of a specified character or


substring.

o toLowerCase(): Converts all characters in a string to


lowercase.

o toUpperCase(): Converts all characters in a string to


uppercase.

Advanced Topics

• Exception Handling: A mechanism to manage runtime errors


and maintain normal program flow.

o Try...Catch block: The try block encloses code that might


throw an exception, and the catch block handles the
exception if one occurs.
o Finally block: A block of code that is always executed
after the try block and any catch blocks, regardless of
whether an exception was thrown or caught [0.1.10 -
general knowledge, not in snippets].

• Assertions: Statements used to test assumptions about the


program's state.

• Threads: A thread is a single sequence of instructions within a


program; multithreading allows concurrent execution.

o Threads by extending the Thread Class: One way to


create a thread in Java.

o Threads by implementing the Runnable interface: A


more flexible way to create a thread.

o Set Priority of Thread Class(): Method to set the priority


of a thread.

o Sleep() of Thread class: Method to pause the current


thread for a specified amount of time.

o Wait() Class of Thread Class: Method that causes the


current thread to wait until another thread notifies it
(usually used in inter-thread communication).

You might also like