Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aaded an example to assist with recursion #522

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Design Patterns/SingleObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class SingleObject {

//create an object of SingleObject
private static SingleObject instance = new SingleObject();

//make the constructor private so that this class cannot be
//instantiated
private SingleObject(){}

//Get the only object available
public static SingleObject getInstance(){
return instance;
}

public void showMessage(){
System.out.println("Hello World!");
}
}
14 changes: 14 additions & 0 deletions Design Patterns/SingletonPatternDemo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class SingletonPatternDemo {
public static void main(String[] args) {

//illegal construct
//Compile Time Error: The constructor SingleObject() is not visible
//SingleObject object = new SingleObject();

//Get the only object available
SingleObject object = SingleObject.getInstance();

//show the message
object.showMessage();
}
}
19 changes: 19 additions & 0 deletions Documentation/OOPS.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,25 @@ accessible within same class and package within which its class is defined.
* `Method body:` it is enclosed between braces. The code you need to be executed to perform your intended operations.


## An exception (or exceptional event) is a problem that arises during the execution of a program. When an Exception occurs the normal flow of the program is disrupted and the program/Application terminates abnormally, which is not recommended, therefore, these exceptions are to be handled.

** An exception can occur for many different reasons. Following are some scenarios where an exception occurs.**

* A user has entered an invalid data.

* A file that needs to be opened cannot be found.

* A network connection has been lost in the middle of communications or the JVM has run out of memory.

* Some of these exceptions are caused by user error, others by programmer error, and others by physical resources that have failed in some manner.

* Based on these, we have three categories of Exceptions. You need to understand them to know how exception handling works in Java.

* Checked exceptions − A checked exception is an exception that is checked (notified) by the compiler at compilation-time, these are also called as compile time exceptions. These exceptions cannot simply be ignored, the programmer should take care of (handle) these exceptions.

* Unchecked exceptions − An unchecked exception is an exception that occurs at the time of execution. These are also called as Runtime Exceptions. These include programming bugs, such as logic errors or improper use of an API. Runtime exceptions are ignored at the time of compilation.

* Errors − These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.



20 changes: 20 additions & 0 deletions Examples/Recursion.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class HelloWorld{

public static void main(String[] args){

static int fact(int n)
{
if (n == 1)

// base condition
return 1;
else
return n*fact(n-1);
}
public static void main(String[] args) {
int result = fact(10);

System.out.println("10! = " + result);
}
}
}