├── .github
├── FUNDING.yml
└── workflows
│ └── mkdocs.yml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── clear.bat
├── clear.sh
├── mkdocs.yml
├── notes
├── AWT
│ ├── CONTROLS.md
│ ├── CheckBox
│ │ ├── CheckBoxDemo.java
│ │ └── README.md
│ ├── README.md
│ ├── button
│ │ ├── ILoveNepal.java
│ │ ├── IWantToLive.java
│ │ └── README.md
│ ├── checkBoxGroup
│ │ ├── CheckboxGroupDemo.java
│ │ └── README.md
│ ├── choice
│ │ ├── ChoiceDemo.java
│ │ └── README.md
│ ├── dialog
│ │ └── DialogDemo.java
│ ├── frame
│ │ ├── FlowLayout.java
│ │ ├── FrameDemo.java
│ │ ├── FrameDemoOne.java
│ │ └── closeAbleFrame
│ │ │ ├── FrameCloseDemo.java
│ │ │ └── README.md
│ ├── general
│ │ ├── Input.java
│ │ └── SampleApp.java
│ ├── label
│ │ ├── Alignment.java
│ │ ├── LabelDemo.java
│ │ ├── LabelDemoOne.java
│ │ └── README.md
│ ├── layout
│ │ ├── GridBagLayout
│ │ │ ├── GridBagConstraintsDemo.java
│ │ │ ├── README.md
│ │ │ └── StagesOfLife.java
│ │ ├── GridLayout
│ │ │ ├── Directions.java
│ │ │ ├── GridLayoutDemo.java
│ │ │ ├── README.md
│ │ │ └── TwelveButtons.java
│ │ ├── README.md
│ │ ├── borderLayout
│ │ │ ├── BorderDemo.java
│ │ │ ├── BorderLayoutDemo.java
│ │ │ └── README.md
│ │ ├── cardLayout
│ │ │ ├── CardLayoutDemo.java
│ │ │ └── README.md
│ │ └── flowLayout
│ │ │ ├── FlowLayoutDemo.java
│ │ │ └── README.md
│ ├── list
│ │ ├── ListDemo.java
│ │ └── README.md
│ ├── menu
│ │ └── MenuDemo.java
│ ├── scrollBar
│ │ ├── README.md
│ │ └── ScrollbarDemo.java
│ ├── textArea
│ │ ├── README.md
│ │ └── TextAreaDemo.java
│ └── textField
│ │ ├── InputInformation.java
│ │ ├── README.md
│ │ └── TextFieldDemo.java
├── JDBC
│ ├── DIFFERENCES.md
│ ├── DifferencesBetweenStatementAndPS.md
│ ├── FEATURES.md
│ ├── JDBCDriver.md
│ ├── README.md
│ ├── SQLInjection.md
│ ├── StepsToDevelopJDBCApplication.md
│ ├── TypesOfSQLCommands.md
│ ├── lib
│ │ └── mysql-connector-java-8.0.15.jar
│ └── src
│ │ └── com
│ │ └── gces
│ │ └── jdbc
│ │ ├── DataEntry.java
│ │ ├── DataEntryDemo.java
│ │ ├── DeleteData.java
│ │ ├── Election.java
│ │ ├── SalaryUpdate.java
│ │ ├── Students.java
│ │ ├── Test.java
│ │ └── UpdateManagerSalary.java
├── README.md
├── applet
│ ├── EXAMPLES.md
│ ├── HelloApplet.html
│ ├── HelloApplet.java
│ ├── README.md
│ ├── TUTORIAL.md
│ ├── displayingImage
│ │ ├── DisplayImage.java
│ │ ├── README.md
│ │ └── blue.jpg
│ ├── general
│ │ └── AvailableFonts.java
│ ├── lifeCycle
│ │ └── LifeCycle.java
│ ├── nepaliFlag
│ │ └── Flag.java
│ ├── passingParameter
│ │ ├── ParamDemo.html
│ │ ├── ParamDemo.java
│ │ └── customFontAndSize
│ │ │ └── CustomFont.java
│ └── playingAudio
│ │ ├── PlayAudio.java
│ │ ├── README.md
│ │ └── sample.wav
├── array
│ ├── README.md
│ ├── alternativeArrayDeclaration.java
│ ├── arrayAssignment.java
│ ├── arrayRepresentation01
│ │ ├── README.md
│ │ └── arrayRepresentation01.java
│ ├── arrayRepresentation02
│ │ ├── README.md
│ │ └── arrayRepresentation02.java
│ ├── arrays.java
│ ├── averageUsingArray.java
│ ├── conventional
│ │ ├── README.md
│ │ └── conventionalWay.java
│ ├── doubleTwoDimesionalArray.java
│ ├── extra.md
│ ├── matrixRepresentation
│ │ ├── README.md
│ │ └── matrixRepresentation.java
│ ├── threeDimensionalArray.java
│ ├── twoDArray.java
│ └── twoDimensionalArrayManualAllocation.java
├── assets
│ ├── fonts
│ │ ├── SailecBlack.woff
│ │ ├── SailecBlackItalic.woff
│ │ ├── SailecBold.woff
│ │ ├── SailecBoldItalic.woff
│ │ ├── SailecHairline.woff
│ │ ├── SailecHairlineItalic.woff
│ │ ├── SailecLight.woff
│ │ ├── SailecLightItalic.woff
│ │ ├── SailecMedium.woff
│ │ ├── SailecMediumItalic.woff
│ │ ├── SailecRegular.woff
│ │ ├── SailecRegularItalic.woff
│ │ ├── SailecThin.woff
│ │ └── SailecThinItalic.woff
│ ├── images
│ │ └── java.png
│ ├── javascripts
│ │ ├── config.js
│ │ └── extra.js
│ └── stylesheets
│ │ └── extra.css
├── basics
│ ├── blocksOfCode.java
│ ├── booleanDataType.java
│ ├── charDataType.java
│ ├── charIsLikeInt.java
│ ├── doubleDataType.java
│ ├── escapeSequences.java
│ ├── forLoop.java
│ ├── hello-numbers.java
│ ├── hello-world.java
│ ├── ifStatement.java
│ ├── speedOfLight.java
│ └── underScoreForReadability.java
├── controlStatements
│ ├── README.md
│ ├── examResult.java
│ ├── forEach.java
│ ├── missingBreak.java
│ ├── nonRecursive
│ │ └── Fibonacci
│ │ │ ├── Fibonacci.java
│ │ │ └── FibonacciDemo.java
│ ├── recursion
│ │ ├── Factorial
│ │ │ ├── Factorial.java
│ │ │ └── FactorialDemo.java
│ │ └── Fibonacci
│ │ │ ├── Fibonacci.java
│ │ │ └── FibonacciDemo.java
│ ├── summationOfFirstFiveElement.java
│ ├── switchStatement.java
│ └── testCases
│ │ ├── doWhile
│ │ ├── asExitControlledLoop.java
│ │ ├── blockVariableDeclaration.java
│ │ ├── finalValueCompairing.java
│ │ ├── inlineExecution.java
│ │ ├── inlinePrinting.java
│ │ ├── inlineVariableDeclaration.java
│ │ ├── unReachableStatement.java
│ │ └── valueAssignAndCompairing.java
│ │ ├── forLoop
│ │ ├── IsThatInfinite.java
│ │ ├── byDefaultTrue.java
│ │ ├── initializationAndUpdationIsPrint.java
│ │ ├── initializationIsPrint.java
│ │ ├── inlinePrinting.java
│ │ ├── inlineVariableDeclaration.java
│ │ ├── noInitializationConditionUpdation.java
│ │ ├── noInitializationConditionUpdationInlinePrint.java
│ │ ├── normalExecution.java
│ │ ├── onlyForLoop.java
│ │ └── trueCondition.java
│ │ ├── ifElse
│ │ ├── booleanVariableAssignmentAsArgument.java
│ │ ├── booleanVariableAssignmentAsArgument01.java
│ │ ├── booleanVariableAssignmentAsArgument02.java
│ │ ├── intAsArgument.java
│ │ ├── intValueCompareAsArgument.java
│ │ ├── intVariableAsArgument.java
│ │ ├── trueAsArgument.java
│ │ └── withoutBraces
│ │ │ ├── declaringVariable.java
│ │ │ ├── declaringVariableInsideBlockIfElse.java
│ │ │ ├── onlyIf.java
│ │ │ └── printMessage.java
│ │ └── while
│ │ ├── finalValueCompairing.java
│ │ ├── inlinePrinting.java
│ │ ├── inlineVariableDeclaration.java
│ │ ├── literalCompairing.java
│ │ ├── unreachableStatement.java
│ │ ├── unreachableStatementInsideFalse.java
│ │ ├── variableComparing.java
│ │ └── variableComparing01.java
├── dataStructures
│ ├── README.md
│ ├── TowerOfHanoi
│ │ ├── TOH.java
│ │ └── TOHDemo.java
│ ├── blockchain
│ │ ├── Block.java
│ │ └── Main.java
│ └── stack.java
├── events
│ ├── ActionListener
│ │ ├── ActionListenerDemo.java
│ │ └── README.md
│ ├── Adapter
│ │ ├── AdapterDemo.java
│ │ ├── CloseByWindowButton.java
│ │ └── README.md
│ ├── AdjustmentListener
│ │ └── README.md
│ ├── ComponentListener
│ │ └── README.md
│ ├── ContainerListener
│ │ └── README.md
│ ├── EVENTCLASSES.md
│ ├── EVENTLISTENERS.md
│ ├── FocusListener
│ │ └── README.md
│ ├── ItemListener
│ │ └── README.md
│ ├── KeyListener
│ │ ├── KeyListenerDemo.java
│ │ └── README.md
│ ├── MouseListener
│ │ ├── MouseListenerDemo.java
│ │ └── README.md
│ ├── MouseMotionListener
│ │ ├── MouseMotionListenerDemo.java
│ │ └── README.md
│ ├── MouseWheelListener
│ │ └── README.md
│ ├── README.md
│ ├── TextListener
│ │ ├── README.md
│ │ └── TextAreaDemo.java
│ ├── WindowFocusListener
│ │ └── README.md
│ └── WindowListener
│ │ ├── README.md
│ │ └── WindowListenerDemo.java
├── exams
│ ├── examAnswers
│ │ ├── DBAbstractClassAndInterface.md
│ │ └── programmingAnswers
│ │ │ ├── chapterFour
│ │ │ ├── Eight.java
│ │ │ └── abc.txt
│ │ │ ├── chapterOne
│ │ │ ├── Five.java
│ │ │ ├── Four.java
│ │ │ └── Two.java
│ │ │ └── chapterTwo
│ │ │ ├── Eight.java
│ │ │ ├── Five.java
│ │ │ ├── Four.java
│ │ │ ├── One.java
│ │ │ ├── Seven.java
│ │ │ ├── Six.java
│ │ │ ├── Three.java
│ │ │ └── Two.java
│ └── examQuestions
│ │ ├── ProgrammingQuestions.md
│ │ └── README.md
├── exception
│ ├── ChainedException
│ │ ├── ChainExceptionDemo.java
│ │ └── README.md
│ ├── Exception.java
│ ├── MultipleCatch.java
│ ├── NestedTry
│ │ ├── NestedTry.java
│ │ └── README.md
│ ├── README.md
│ ├── builtIn
│ │ ├── ExceptionDemo.java
│ │ ├── MyException.java
│ │ └── README.md
│ ├── finally
│ │ ├── FinallyDemo.java
│ │ ├── FinallyDemoOne.java
│ │ └── README.md
│ ├── throw
│ │ ├── ArgsArithmeticException.java
│ │ ├── README.md
│ │ ├── throwDemo.java
│ │ └── throwDemoWithMessage.java
│ └── throws
│ │ ├── DemoOne
│ │ ├── ExceptionOne.java
│ │ └── MyException.java
│ │ ├── README.md
│ │ └── ThrowsDemo.java
├── general
│ ├── ExportInJSON
│ │ ├── DecodeJSON.java
│ │ ├── ExportInJSON.java
│ │ └── JSONEncodeDemo.java
│ ├── Overriding.java
│ ├── OwnException.java
│ ├── README.md
│ ├── RunComment.java
│ ├── Stack.java
│ ├── StackDemo.java
│ ├── TargetSumByTwo.java
│ ├── internalRepresentation.java
│ ├── swapWithoutThirdVariable.java
│ └── withoutArithmeticOperators.java
├── graphics
│ ├── README.md
│ ├── barChart
│ │ └── BarChart.java
│ ├── color
│ │ ├── ColorJPanel.java
│ │ ├── README.md
│ │ ├── ShowColors.java
│ │ └── withApplet
│ │ │ └── ColorDemo.java
│ ├── control
│ │ └── README.md
│ ├── font
│ │ ├── CustomFontAndSize.java
│ │ ├── README.md
│ │ └── fontMetrics
│ │ │ ├── FontMetricsDemo.java
│ │ │ └── README.md
│ ├── geometry
│ │ ├── DrawArc.java
│ │ ├── DrawOval.java
│ │ ├── DrawRectangle.java
│ │ ├── PolyLineDemo.java
│ │ ├── PolygonDemo.java
│ │ ├── README.md
│ │ └── RoundRectangle.java
│ ├── nepaliFlag
│ │ ├── Moon.java
│ │ ├── NepaliFlag.java
│ │ └── nepal.png
│ └── smiley
│ │ ├── Amazed.java
│ │ └── Teasing.java
├── introduction
│ ├── DataTypes.md
│ ├── IDENTIFIER.md
│ ├── README.md
│ └── ReservedWord.md
├── io
│ ├── BufferedReader
│ │ ├── README.md
│ │ ├── ReadFromGCES.java
│ │ ├── ReadFromGCESReadLine.java
│ │ └── gces.txt
│ ├── BufferedWriter
│ │ ├── README.md
│ │ └── WriteOnGCES.java
│ ├── File
│ │ ├── CLA
│ │ │ ├── DisplayWithCLA.java
│ │ │ └── README.md
│ │ ├── CountsFile.java
│ │ ├── DisplayFileAndDirectories.java
│ │ ├── MyFileInsideFolder.java
│ │ ├── MyFileInsideFolderWithCondition.java
│ │ └── README.md
│ ├── FileReader
│ │ ├── FileReaderDemo.java
│ │ ├── FileReaderIntoArray.java
│ │ ├── README.md
│ │ └── myText.txt
│ ├── FileWriter
│ │ ├── FileWriterAppendDemo.java
│ │ ├── FileWriterDemo.java
│ │ └── README.md
│ ├── PrintWriter
│ │ ├── README.md
│ │ └── WriteIntoFile.java
│ ├── README.md
│ └── more-examples
│ │ ├── DisplayTextFiles.java
│ │ ├── MergeFiles.java
│ │ ├── MergeFilesAlternatively.java
│ │ ├── MergeTextFromGivenPath.java
│ │ ├── README.md
│ │ ├── abc.txt
│ │ └── xyz.txt
├── literals
│ ├── README.md
│ ├── literals.java
│ └── testForLiterals
│ │ ├── DoubleWIthD.java
│ │ ├── DoubleWithHexaDecimalLiteral.java
│ │ ├── DoubleWithOctalLiteral.java
│ │ ├── DoubleWithoutD.java
│ │ ├── FloatWithF.java
│ │ └── FloatWithoutF.java
├── networking
│ ├── ConnectionLess
│ │ ├── README.md
│ │ ├── Receiver.java
│ │ └── Sender.java
│ ├── HTTPURLConnection
│ │ ├── HttpURLConnectionDemo.java
│ │ └── README.md
│ ├── InetAddress
│ │ ├── InetAddressDemo.java
│ │ └── README.md
│ ├── README.md
│ ├── ServerToClient
│ │ ├── Client.java
│ │ ├── README.md
│ │ └── Server.java
│ ├── SocketProgramming
│ │ ├── README.md
│ │ └── TryWithResources.java
│ ├── UDPMessaging
│ │ ├── README.md
│ │ ├── UDPClient.java
│ │ └── UDPServer.java
│ ├── URL
│ │ ├── README.md
│ │ └── URLDemo.java
│ ├── URLConnection
│ │ ├── README.md
│ │ └── URLConnectionDemo.java
│ ├── chatApplication
│ │ ├── Arjun.java
│ │ ├── GCESServer.java
│ │ └── README.md
│ ├── checkInternetConnection
│ │ ├── IsInternetAvailable.java
│ │ └── README.md
│ ├── dualConnection
│ │ ├── Client.java
│ │ ├── README.md
│ │ └── Server.java
│ └── whoisImplementation
│ │ ├── README.md
│ │ └── Whois.java
├── oop
│ ├── classesObjects
│ │ ├── accessModifiers
│ │ │ ├── Movie.java
│ │ │ ├── README.md
│ │ │ └── movieDemo.java
│ │ ├── anonymous
│ │ │ ├── AnonymousClass.java
│ │ │ └── AnonymousDemo.java
│ │ ├── classesObjectsImplementation
│ │ │ ├── Animal.java
│ │ │ ├── AnimalDemo.java
│ │ │ ├── Box.java
│ │ │ ├── BoxDemo.java
│ │ │ ├── Calculate.java
│ │ │ └── CalculateDemo.java
│ │ ├── constructor
│ │ ├── final
│ │ │ ├── README.md
│ │ │ ├── Sample.java
│ │ │ └── finalTwo.java
│ │ ├── nestedInnerClass
│ │ │ ├── AnimalHumanAssignment.java
│ │ │ ├── README.md
│ │ │ ├── classAssignment.java
│ │ │ ├── classAssignment01.java
│ │ │ └── classAssignment02.java
│ │ ├── simpleClass
│ │ │ ├── AssigningObjectReferenceVariables
│ │ │ │ ├── Box.java
│ │ │ │ ├── BoxDemo.java
│ │ │ │ └── README.md
│ │ │ ├── Box.java
│ │ │ ├── BoxDemo.java
│ │ │ └── DeclareObjects.java
│ │ └── static
│ │ │ └── README.md
│ ├── inheritance
│ │ ├── AbstractClass
│ │ │ ├── AbstractClassFour
│ │ │ │ ├── AbstractDemo.java
│ │ │ │ ├── Circle.java
│ │ │ │ └── Shape.java
│ │ │ ├── AbstractClassOne
│ │ │ │ ├── AbstractAreas.java
│ │ │ │ ├── Figure.java
│ │ │ │ ├── Rectangle.java
│ │ │ │ └── Triangle.java
│ │ │ ├── AbstractClassThree
│ │ │ │ ├── AbstractDemo.java
│ │ │ │ ├── Huawei.java
│ │ │ │ ├── Iphone.java
│ │ │ │ └── Phone.java
│ │ │ ├── AbstractClassTwo
│ │ │ │ ├── AbstractDemo.java
│ │ │ │ ├── ArjunPhone.java
│ │ │ │ ├── SamirPhone.java
│ │ │ │ └── SumanPhone.java
│ │ │ └── README.md
│ │ ├── Box.java
│ │ ├── BoxDemo.java
│ │ ├── BoxWeight.java
│ │ ├── README.md
│ │ ├── derivation
│ │ │ └── OrderDerivation.java
│ │ ├── finalWithInheritance
│ │ │ └── README.md
│ │ ├── interface
│ │ │ ├── Circle.java
│ │ │ ├── Extended
│ │ │ │ └── README.md
│ │ │ ├── Graphics.java
│ │ │ ├── InterfaceDemo.java
│ │ │ ├── NestedInterface
│ │ │ │ ├── Animal.java
│ │ │ │ ├── Dog.java
│ │ │ │ ├── NestedInterfaceDemo.java
│ │ │ │ └── README.md
│ │ │ ├── README.md
│ │ │ ├── Rectangle.java
│ │ │ └── Shape.java
│ │ ├── methodOverRiding
│ │ │ ├── Animal.java
│ │ │ ├── DynamicMethodDispatch
│ │ │ │ ├── DynamicMethodDispatch.java
│ │ │ │ └── README.md
│ │ │ └── README.md
│ │ └── super
│ │ │ └── README.md
│ └── usingPackage
│ │ ├── PackageDemo.java
│ │ ├── README.md
│ │ ├── gces
│ │ └── Student.java
│ │ └── tuts
│ │ └── README.md
├── operators
│ ├── assignmentOperators.java
│ ├── basicArithmeticOperators.java
│ ├── bitwiseOperators.java
│ ├── decimalToBinary.java
│ ├── incrementDecrement.java
│ └── modulusOperator.java
├── swing
│ ├── COMPONENTS.md
│ ├── DIFFERENCES.md
│ ├── HIERARCHY.md
│ ├── JApplet
│ │ └── JAppletDemo.java
│ ├── JFrame
│ │ ├── ChangeBackGround.java
│ │ ├── JFrameDemo.java
│ │ └── JFrameDemoByAssociation.java
│ ├── JOptionPane
│ │ └── JOptionPane.java
│ ├── JTextField
│ │ └── JTextFieldDemo.java
│ ├── dialog
│ │ └── DialogDemo.java
│ ├── general
│ │ ├── Calculator.java
│ │ └── HaveFun.java
│ └── multiCasting
│ │ ├── MULTICASTING.md
│ │ └── MultiCastEvent.java
└── variables
│ ├── README.md
│ ├── classAssignment
│ ├── Person.java
│ └── PersonDemo.java
│ ├── dynamicInitializationOfVariables.java
│ ├── lifeTImeOfVariable.java
│ ├── scopeOfVariables.java
│ ├── scopeOfVariablesOne.java
│ └── typeconversion.java
└── requirements.txt
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | patreon: thearjun
4 |
--------------------------------------------------------------------------------
/.github/workflows/mkdocs.yml:
--------------------------------------------------------------------------------
1 | name: Create Java notes site with MKDOCS
2 | on:
3 | push:
4 | branches:
5 | - master
6 | jobs:
7 | deploy:
8 | runs-on: ubuntu-latest
9 | steps:
10 | - uses: actions/checkout@v2
11 | - uses: actions/setup-python@v2
12 | with:
13 | python-version: 3.x
14 | - run:
15 | pip install mkdocs mkdocs-material mkdocs-macros-plugin
16 | - run: mkdocs gh-deploy --force
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Java Notes
2 |
3 | > Run Locally on Computer
4 |
5 | ```
6 | pip install -r requirements.txt
7 | mkdocs serve
8 | ```
9 |
--------------------------------------------------------------------------------
/clear.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | DEl /S /Q *.class
--------------------------------------------------------------------------------
/clear.sh:
--------------------------------------------------------------------------------
1 | find . -name '*.class' -delete
2 | find . -name '*.json' -delete
--------------------------------------------------------------------------------
/notes/AWT/CONTROLS.md:
--------------------------------------------------------------------------------
1 | # Adding and Removing Controls ?
2 |
3 | - To include a control in a window, you must add it to the window.
4 | - To do this, you must crate an instance of the desired control and then add it to a Window by calling add (), which is defined by Container class.
5 |
6 | ### Syntax
7 | ```Component add (Component ComponentRef);```
8 |
9 | ## AWT Controls
10 |
11 | - Once a component has been added it will be automatically visible whenever its parent window is displayed.
12 |
13 | ### To remove
14 | - ```void remove(Component ComponentRef);```
15 | - ```void removeAll();```
--------------------------------------------------------------------------------
/notes/AWT/CheckBox/CheckBoxDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | public class CheckBoxDemo extends Frame {
4 | CheckBoxDemo(String title) {
5 |
6 | super(title);
7 | setSize(400, 400);
8 | setVisible(true);
9 | setLayout(new GridLayout(4,1));
10 |
11 | // b is lowercase in Checkbox.
12 |
13 | Label hobbies = new Label("Select your hobbies :");
14 | Checkbox swimming = new Checkbox("Swimming");
15 | Checkbox cycling = new Checkbox("Cycling");
16 | Checkbox writing = new Checkbox("Writing");
17 |
18 | add(hobbies);
19 | add(swimming);
20 | add(cycling);
21 | add(writing);
22 |
23 | cycling.setLabel("Check for Swimming");
24 | cycling.setState(false);
25 |
26 | System.out.println("Swimming State : "+swimming.getState());
27 | System.out.println("Swimming Label : "+swimming.getLabel());
28 | }
29 |
30 | public static void main(String[] args) {
31 | CheckBoxDemo obj = new CheckBoxDemo("Check Box Demo");
32 | }
33 | }
--------------------------------------------------------------------------------
/notes/AWT/CheckBox/README.md:
--------------------------------------------------------------------------------
1 | # Checkbox
2 | - A ```Checkbox``` is a control that is used to turn an option on or off.
3 | - It consists of a small box tha can either contain a checkmark or not.
4 | - There is a ```Label``` associated with each check box that describes what option the box represents.
5 | - Can change the state of a ```Checkbox``` by clicking on it.
6 |
7 | ## Constructors:
8 | 1. ```Checkbox() throws HeadlessException```
9 | 2. ```Checkbox(String str) throws HeadlessException```
10 | 3. ```Checkbox(String str, boolean on) throws HeadlessException```
11 | 4. ```Checkbox(String str, boolean on, CheckboxGroup cbGroup) throws HeadlessException```
12 | 5. ```Checkbox(String str, CheckboxGroup cbGroup, boolean on) throws HeadlessException```
13 |
14 |
15 | ## Methods
16 | 1. ```boolean getState();```
17 | 2. ```void setState(boolean on);```
18 | 3. ```String getLabel();```
19 | 4. ```void setLabel(String str);```
20 |
21 |
22 |
--------------------------------------------------------------------------------
/notes/AWT/button/ILoveNepal.java:
--------------------------------------------------------------------------------
1 | import java.awt.Button;
2 | import java.awt.Label;
3 | import java.applet.Applet;
4 |
5 | /* */
6 |
7 | public class ILoveNepal extends Applet {
8 | public void init() {
9 | Label question = new Label ("Do you Love Nepal ?");
10 | add(question);
11 |
12 | Button answerOne = new Button("Yes, I love.");
13 | Button answerTwo = new Button("No, I am planning to love Australia.");
14 |
15 | add(answerOne);
16 | add(answerTwo);
17 | }
18 | }
--------------------------------------------------------------------------------
/notes/AWT/button/IWantToLive.java:
--------------------------------------------------------------------------------
1 | import java.awt.Button;
2 | import java.applet.Applet;
3 | import java.awt.Label;
4 |
5 | /* */
6 |
7 | public class IWantToLive extends Applet {
8 | public void init() {
9 | Label wannaLive = new Label("Do you want to Live ? ",Label.LEFT);
10 | Button iwantToLive = new Button("Yes");
11 | Label wannaDie = new Label("Do you want to Die ? ",Label.RIGHT);
12 | Button iwantToDie = new Button("Yes");
13 |
14 | add(wannaLive);
15 | add(iwantToLive);
16 | add(wannaDie);
17 | add(iwantToDie);
18 |
19 | iwantToDie.setEnabled(false); // Disable the click
20 |
21 | }
22 | }
--------------------------------------------------------------------------------
/notes/AWT/button/README.md:
--------------------------------------------------------------------------------
1 | # Button
2 | - The most widely used control is the push button. A push button is a ```Component``` that contains a label and that generates an event when it is pressed. Push buttons are objects of type button. ```Button``` defines these two constructors:
3 |
4 | ## Constructors
5 | 1. ```public Button()```
6 | 2. ```public Button(String buttonLabel) throws headless Exception;```
7 |
8 | ## Public Methods
9 | 1. ```public String getLabel();```
10 | - Get the label of this button instance.
11 |
12 | 2. ```public void setLabel(String btnlabel);```
13 | - Set the label of this button instance.
14 |
15 | 3. ```public void setEnable(boolean enable);```
16 | - Enable or disable this Button. Disabled Button cannot be clicked.
17 |
18 |
19 |
--------------------------------------------------------------------------------
/notes/AWT/checkBoxGroup/CheckboxGroupDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | public class CheckboxGroupDemo extends Frame {
4 |
5 | Checkbox windows, linux, macOS;
6 | CheckboxGroup operatingSystem;
7 | Label message;
8 |
9 | CheckboxGroupDemo(String title) {
10 | super(title);
11 | setSize(400, 400);
12 | setLayout(new FlowLayout());
13 | setVisible(true);
14 |
15 | message = new Label("Choose your operating system :", Label.CENTER);
16 |
17 | operatingSystem = new CheckboxGroup();
18 |
19 | windows = new Checkbox("Windows", operatingSystem, true);
20 | linux = new Checkbox("Linux", operatingSystem, false);
21 | macOS = new Checkbox("MacOS", operatingSystem, false);
22 |
23 | add(message);
24 | add(windows);
25 | add(linux);
26 | add(macOS);
27 | }
28 |
29 | public static void main(String[] args) {
30 | CheckboxGroupDemo obj = new CheckboxGroupDemo("Check Box Group Demo");
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/notes/AWT/checkBoxGroup/README.md:
--------------------------------------------------------------------------------
1 | # CheckboxGroup
2 | - It is possible to create a set if mutually exclusive check boxes in which one and only one checkbox in the group can be checked at any one time.
3 | - Also known as **radio button**.
4 |
5 | ## Constructors
6 | ```CheckboxGroup();```
7 |
8 | ## Methods
9 | 1. ```Checkbox getSelectedCheckbox();```
10 | 2. ```void setSelectedCheckbox(Checkbox which);```
11 |
12 |
--------------------------------------------------------------------------------
/notes/AWT/choice/README.md:
--------------------------------------------------------------------------------
1 | # Choice
2 | > Same as Select in HTML
3 | - The ```Choice``` class is used to create a pop-up list of items from which user may choose.
4 | - **Only one item can be chosen**.
5 |
6 | ## Constructors:
7 | ```Choice();```
8 |
9 | ## Methods:
10 | 1. ```void add(String name);```
11 | 2. ```String getSelectedItem();```
12 | 3. ```int getSelectedIndex();```
13 | 4. ```int getItemCount();```
14 | 5. ```void select(String name);```
15 | 6. ```String getItem(int index);```
16 |
17 |
--------------------------------------------------------------------------------
/notes/AWT/dialog/DialogDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.awt.event.*;
3 |
4 | public class DialogDemo extends Window{
5 |
6 | Dialog d;
7 | public DialogDemo() {
8 | Frame f = new Frame();
9 | f.setVisible(true);
10 | d = new Dialog(f, "Dialog Example", true);
11 | d.setLayout(new FlowLayout());
12 | Button button = new Button("OK");
13 | button.addActionListener(new ActionListener(){
14 | public void actionPerformed(ActionEvent ae){
15 | d.setVisible(false);
16 | }
17 | });
18 | d.add(new Label("Click button to continue"));
19 | d.add(button);
20 | d.setSize(200,200);
21 | d.setVisible(true);
22 | }
23 | public static void main(String[] args) {
24 | new DialogDemo();
25 | }
26 | }
--------------------------------------------------------------------------------
/notes/AWT/frame/FlowLayout.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.Applet;
3 |
4 | public class FlowLayout extends Applet{
5 | Button buttonOne, buttonTwo, buttonThree;
6 |
7 | public void init() {
8 | buttonOne = new Button("ok");
9 | buttonTwo = new Button("Open");
10 | buttonThree = new Button("Close");
11 |
12 | setLayout(new FlowLayout());
13 | add(buttonOne);
14 | add(buttonTwo);
15 | add(buttonThree);
16 | }
17 | }
--------------------------------------------------------------------------------
/notes/AWT/frame/FrameDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | class ExtendingFrameDemo extends Frame{
4 | ExtendingFrameDemo() {
5 | Label name = new Label("Name");
6 | add(name);
7 | setVisible(true);
8 | }
9 |
10 | public static void main(String[] args) {
11 | ExtendingFrameDemo objectOne = new ExtendingFrameDemo();
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/AWT/frame/FrameDemoOne.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | class CreatingFrameDemo{
4 | CreatingFrameDemo() {
5 | Label name = new Label("Name");
6 | Frame frame = new Frame();
7 | frame.add(name);
8 | frame.setVisible(true);
9 | frame.setSize(300,300); // for size
10 | }
11 |
12 | public static void main(String[] args) {
13 | CreatingFrameDemo objectOne = new CreatingFrameDemo();
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/AWT/frame/closeAbleFrame/FrameCloseDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.awt.event.*;
3 |
4 | /* */
5 |
6 | public class FrameCloseDemo {
7 | public static void main(String[] args) {
8 | Frame frame = new Frame ("Close Operation Frame");
9 | Label label = new Label ("Testing close operation");
10 |
11 | frame.add(label);
12 | frame.setSize(400,400);
13 | frame.setVisible(true);
14 |
15 | frame.addWindowListener(new WindowAdapter(){
16 | public void windowClosing(WindowEvent we){
17 | System.exit(0);
18 | }
19 | });
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/AWT/frame/closeAbleFrame/README.md:
--------------------------------------------------------------------------------
1 | # Closeable Frame
2 |
3 | - It is possible to implement the close button of any frame orwindow in java application.
4 | - By default, the close button of the frame is not in working state.
5 | - The close button of the frame has to be set for the closing operation.
6 |
7 |
--------------------------------------------------------------------------------
/notes/AWT/label/Alignment.java:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | */
4 |
5 | import java.awt.Label;
6 | import java.applet.Applet;
7 |
8 | public class Alignment extends Applet {
9 | public void init () {
10 | Label leftAlignedLabel = new Label("Left Aligned Label");
11 | Label centerAlignedLabel = new Label("Center Aligned Label");
12 | Label rightAlignedLabel = new Label("Right Aligned Label");
13 |
14 | /* The possible alignment values are Label.LEFT, Label.RIGHT, and Label.CENTER.*/
15 |
16 | leftAlignedLabel.setAlignment(Label.LEFT);
17 | centerAlignedLabel.setAlignment(Label.CENTER);
18 | rightAlignedLabel.setAlignment(Label.RIGHT);
19 |
20 | add(leftAlignedLabel);
21 | add(centerAlignedLabel);
22 | add(rightAlignedLabel);
23 | }
24 | }
--------------------------------------------------------------------------------
/notes/AWT/label/LabelDemo.java:
--------------------------------------------------------------------------------
1 | /* Label provides meaning to the component. */
2 |
3 | import java.applet.*;
4 | import java.awt.*;
5 |
6 | /*
7 |
8 | */
9 |
10 | public class LabelDemo extends Applet{
11 |
12 | // Constructor of AWT Label Class. First three objects are created using default constructor and later setText() is evoked to set String.
13 | Label name = new Label();
14 | Label address = new Label();
15 | Label rollNo = new Label();
16 | // Let's add string here from constructor.
17 | Label grade = new Label("Grade");
18 |
19 | public void init(){
20 |
21 | // Setting the text to those labels.
22 | name.setText("Name");
23 | address.setText("Address");
24 | rollNo.setText("Roll No");
25 |
26 | // This adds to the container.
27 | add(name);
28 | add(address);
29 | add(rollNo);
30 | add(grade);
31 | }
32 | }
--------------------------------------------------------------------------------
/notes/AWT/label/LabelDemoOne.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class LabelDemoOne extends Applet
7 | {
8 |
9 | public void init()
10 | {
11 | Label name = new Label("Name : Arjun", Label.LEFT);
12 | Label address = new Label("Address : LA, California, United States",Label.CENTER);
13 | Label phoneNumber = new Label("Phone Number : +123456436",Label.CENTER);
14 | Label college = new Label("College : MIT",Label.RIGHT);
15 |
16 | add(name);
17 | add(address);
18 | add(phoneNumber);
19 | add(college);
20 |
21 | }
22 | }
--------------------------------------------------------------------------------
/notes/AWT/label/README.md:
--------------------------------------------------------------------------------
1 | # Labels
2 | - Labels are passive controls that do not support any interaction with the user i.e. no event handling.
3 | - A label is an object of type ```Label``` and it contains a String, which it displays.
4 | - Label defines the following constructors:
5 | i. ```Label() throws HeadLessException```
6 | ii. ```Label(String str) throws HeadLessException``` // The string is left justified.
7 | iii. ```Label(String str, int how) throws HeadLessException``` // label.LEFT, label.RIGHT
8 |
9 | ### 👉Methods
10 | i. ```void setText(String str);```
11 | ii. ```String getText();```
12 | iii. ```void setAlignment(int how);```
13 | iv. ```int getAlignment();```
14 |
15 | ### Example
16 |
17 | Label name = new Label("Arjun");
18 | name.setText("Another Arjun");
19 | String myNameWas = name.getText();
20 |
21 |
--------------------------------------------------------------------------------
/notes/AWT/layout/GridBagLayout/README.md:
--------------------------------------------------------------------------------
1 | # GridBag Layout
2 |
3 | - A flexible layout manager that arranges components in a grid with a variable sized cells.
4 | - The ```GridBagLayout``` class is flexible Layout manager that aligns components vertically and horizontally and the components of different size.
5 | - Each ```GridBagLayout``` object maintains a dynamic, rectangular grid of cells.
6 | - Each Component is managed by a ```GridBagLayout``` is associated with an instance of ```GridBagConstraints```.
7 | - We use to set constraints :
8 |
9 | void setConstraints(Component c, GridBagConstraints cons);
10 |
11 | ## Constructor
12 |
13 | 1.```GridBagLayout();```
--------------------------------------------------------------------------------
/notes/AWT/layout/GridLayout/Directions.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | public class Directions extends Frame {
4 | Directions(String title) {
5 | super(title);
6 |
7 | setSize(400,400);
8 | setVisible(true);
9 |
10 | /* GridLayout()
11 | GridLayout(int rows, int cols)
12 | GridLayout(int rows, int cols, int hgap, int vgap) */
13 |
14 | setLayout(new GridLayout(3,3));
15 |
16 | add(new Button("Top Left"));
17 | add(new Button("Top"));
18 | add(new Button("Top Right"));
19 | add(new Button("Left"));
20 | add(new Button("Center"));
21 | add(new Button("Right"));
22 | add(new Button("Botton Left"));
23 | add(new Button("Bottom"));
24 | add(new Button("Bottom Right"));
25 | }
26 | public static void main(String[] args) {
27 | new Directions("Grid Layout Demo");
28 | }
29 | }
--------------------------------------------------------------------------------
/notes/AWT/layout/GridLayout/GridLayoutDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | public class GridLayoutDemo extends Frame {
4 | public GridLayoutDemo(String title) {
5 | super(title);
6 | /* Sets the Grid Layout */
7 | setLayout(new GridLayout(2,3));
8 | add(new Button("Button One"));
9 | add(new Button("Button Two"));
10 | add(new Button("Button Three"));
11 | add(new Button("Button Four"));
12 | add(new Button("Button Five"));
13 | add(new Button("Button Six"));
14 | }
15 |
16 | public static void main(String[] args) {
17 | GridLayoutDemo obj = new GridLayoutDemo("Grid Layout");
18 | obj.setSize(300,300);
19 | obj.setVisible(true);
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/AWT/layout/GridLayout/README.md:
--------------------------------------------------------------------------------
1 | # Grid Layout
2 |
3 | - A container using the GridLayout scheme arranges components in rows and colums in row major order. Each component is sized to fit its respective grid cell.
4 |
5 | ## Constructors
6 |
7 | a. ```GridLayout()```
8 | b. ```GridLayout(int rows, int cols)```
9 | c. ```GridLayout(int rows, int cols, int hgap, int vgap)```
--------------------------------------------------------------------------------
/notes/AWT/layout/GridLayout/TwelveButtons.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | public class TwelveButtons extends Frame {
4 |
5 | TwelveButtons(String title) {
6 | super(title);
7 |
8 | setSize(500,500);
9 | setVisible(true);
10 | setLayout(new GridLayout(3,4));
11 |
12 | add(new Button("1"));
13 | add(new Button("2"));
14 | add(new Button("3"));
15 | add(new Button("4"));
16 | add(new Button("5"));
17 | add(new Button("6"));
18 | add(new Button("7"));
19 | add(new Button("8"));
20 | add(new Button("9"));
21 | add(new Button("10"));
22 | add(new Button("11"));
23 | add(new Button("12"));
24 | }
25 |
26 |
27 | public static void main(String[] args) {
28 | new TwelveButtons("12 Buttons");
29 | }
30 | }
--------------------------------------------------------------------------------
/notes/AWT/layout/README.md:
--------------------------------------------------------------------------------
1 | # LayoutManager
2 | - ```LayoutManager``` are provided to arrange GUI components on a container for presentation purpose.
3 | - Each ```Container``` object has a ```LayoutManager``` interface.
4 | - A layout Manager is an instance of any class that implements the ```LayoutManager``` interface
5 | - The layout manager is set by the ```setLayout()``` method.
6 | - If no call is ```setLayout()``` is made, then the default layout manager is used that is ```FlowLayout```.
7 |
8 |
9 |
10 | ## Types of LayoutManager
11 | 1. ```FlowLayout```
12 | 2. ```BorderLayout```
13 | 3. ```GridLayout```
14 | 4. ```CardLayout```
15 | 5. ```GridBagLayout```
16 |
17 | ### Two ways to create a ```Frame``` in AWT :
18 | 1. By extending ```Frame``` Class. (Inheritance)
19 | 2. By creating the object of ```Frame``` class. (Association)
--------------------------------------------------------------------------------
/notes/AWT/layout/borderLayout/BorderDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | public class BorderDemo extends Frame{
4 | public BorderDemo (String title) {
5 | /* Passing title to the parent constructor */
6 | super(title);
7 | /* Setting a new Border Layout */
8 | setLayout(new BorderLayout());
9 | /* Adding Buttons */
10 | add(new Button("North"), BorderLayout.NORTH);
11 | add(new Button("West"), BorderLayout.WEST);
12 | add(new Button("Center"), BorderLayout.CENTER);
13 | add(new Button("East"), BorderLayout.EAST);
14 | add(new Button("South"), BorderLayout.SOUTH);
15 | }
16 |
17 | public static void main(String[] args) {
18 | /* Creating a object and passing title to the constructor */
19 | BorderDemo objOne = new BorderDemo("Border Demo");
20 | /* Setting size for Frame */
21 | objOne.setSize(300,200);
22 | /* Making buttons visible */
23 | objOne.setVisible(true);
24 |
25 | }
26 | }
--------------------------------------------------------------------------------
/notes/AWT/layout/borderLayout/BorderLayoutDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | public class BorderLayoutDemo extends Frame {
4 |
5 | BorderLayoutDemo(String title){
6 | setSize(400,400);
7 | setVisible(true);
8 | setLayout(new BorderLayout());
9 |
10 | add(new Button("This is North"),BorderLayout.NORTH);
11 | add(new Button("This is West"),BorderLayout.WEST);
12 | add(new Button("This is East"),BorderLayout.EAST);
13 | add(new Button("This is South"),BorderLayout.SOUTH);
14 | add(new Button("This is Center"),BorderLayout.CENTER);
15 |
16 |
17 | }
18 |
19 | public static void main(String[] args) {
20 | new BorderLayoutDemo("Border Layout Demo");
21 | }
22 | }
--------------------------------------------------------------------------------
/notes/AWT/layout/borderLayout/README.md:
--------------------------------------------------------------------------------
1 | # Border Layout
2 |
3 | - The BorderLayout manager arranges components within specified regions of container.
4 | - Valid regions are : "North", "South", "East", "West" & "Center".
5 |
6 | ## Constructor
7 |
8 | - ```BorderLayout()```
9 | - ```BorderLayout(int hgap, int vgap)```
10 | Eg: ```add(new Button("North"), BorderLayout.WEST)```
11 | ```add("North", new Button("West") )```
--------------------------------------------------------------------------------
/notes/AWT/layout/cardLayout/README.md:
--------------------------------------------------------------------------------
1 | # Card Layout
2 |
3 | - Makes each component as large as the container and diplays only one at a time.
4 |
5 | ## Constructors
6 | 1. ```CardLayout ()```
7 | 2. ```CardLayout (int hgap, int vgap)```
8 |
9 | ## Methods
10 |
11 | 1. ```void first (Container deck)```
12 | 2. ```void last (Container deck)```
13 | 3. ```void next (Container deck)```
14 | 4. ```void previous (Container deck)```
15 | 5. ```void show (Container deck, String cardName)```
--------------------------------------------------------------------------------
/notes/AWT/layout/flowLayout/FlowLayoutDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 |
3 | public class FlowLayoutDemo extends Frame {
4 |
5 | FlowLayoutDemo(String Title) {
6 | setSize(300,400);
7 | setVisible(true);
8 | /* Default layout, though. */
9 | setLayout(new FlowLayout());
10 |
11 | add(new Label("Requirements of ID Card"));
12 | add(new Label("Name "));
13 | add(new Label("Address"));
14 | add(new Label("College "));
15 | add(new Label("Roll No "));
16 | }
17 |
18 | public static void main(String[] args) {
19 | new FlowLayoutDemo("Flow Layout Demo");
20 | }
21 |
22 | }
--------------------------------------------------------------------------------
/notes/AWT/layout/flowLayout/README.md:
--------------------------------------------------------------------------------
1 | # FlowLayout
2 | - Arranges components like words on a page - From left to right in rows and then top to bottom as each row fills up.
3 |
4 | ## Constructors
5 | 1. ```FlowLayout()```
6 | 2. ```FlowLayout(int align)```
7 | 3. ```FlowLayout(int align, int hgape, int vgape)```
8 |
9 | ## FlowLayout Alignments
10 | ```FlowLayout.LEFT, FlowLayout.RIGHT, FlowLayout.CENTER```
11 |
--------------------------------------------------------------------------------
/notes/AWT/list/README.md:
--------------------------------------------------------------------------------
1 | # List
2 | - The ``` List``` class provides a compact, multiple-choice scrolling selection list.
3 |
4 | ## Constructors
5 | 1. ``` List() throws HeadlessException```
6 | 2. ``` List(int numRows) throws HeadlessException```
7 | 3. ``` List( int numRows, boolean multipleSelect) throws HeadlessException```
8 | >numRows number of rows will be visible, if false, then only one item may be selected.
9 |
10 | ## Methods
11 | 1. ``` void add(String name);```
12 | 2. ``` void add(String name , int index);```
13 | 3. ``` String getSelectedItem()```
14 | - for single selection
15 | 5. ``` int getSelectedIndex()```
16 | 6. ``` String[] getSelectedItems()```
17 | - for multiple selection
18 | 8. ``` int[] getSelectedIndexes()```
19 | 9. ``` int getItemCount();```
20 | 10. ``` void select(int index);```
21 |
22 |
--------------------------------------------------------------------------------
/notes/AWT/scrollBar/README.md:
--------------------------------------------------------------------------------
1 | # Scrollbar
2 | - ```Scrollbar``` is used to select continuous values between a specified minimum and maximum.
3 | - May be oriented horizontally or vertically.
4 | - It contain slider box that can be dragged by the uset to a new position.
5 |
6 | # Constructors
7 | 1. ```Scrollbar() throws HeadlessException```
8 | 2. ```Scrollbar(int style) throws HeadlessException```
9 | - Style includes ```Scrollbar.VERTICAL``` and ```Scrollbar.HORIZONTAL```.
10 |
11 | 3. ```Scrollbar(int style, int thumbSize, int min, int max) throws HeadlessException```
12 |
13 | # Methods:
14 | 1. ```void setValues(int initialValue, int thumbSize, int min, int max);```
15 | 2. ```int getValue()```
16 | 3. ```void setValue(int newValue)```
17 | 4. ```int getMinimum()```
18 | 5. ```int getMaximum()```
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/notes/AWT/textField/TextFieldDemo.java:
--------------------------------------------------------------------------------
1 | import java.applet.Applet;
2 | import java.awt.TextField;
3 | import java.awt.Label;
4 |
5 | /* */
6 |
7 | public class TextFieldDemo extends Applet {
8 | public void init() {
9 | TextField name = new TextField("Enter your name",32); // Sets the text and size of column
10 | TextField address = new TextField("Enter your address"); // Sets only text
11 | TextField age = new TextField(3); // Sets only size
12 |
13 | add(name);
14 | add(address);
15 | add(age);
16 |
17 | }
18 | }
--------------------------------------------------------------------------------
/notes/JDBC/DIFFERENCES.md:
--------------------------------------------------------------------------------
1 | # Difference between ODBC and JDBC
2 |
3 | ## **ODBC**
4 | > 1992, Open Database Connectivity
5 |
6 | - Developed by Microsoft
7 | - Support any language
8 | - Only for Windows machine
9 | - Support any database
10 |
11 | ## **JDBC**
12 | > 1997, Java Database Connectivity
13 | - Support any database
14 | - Support any platform
15 | - Only for Java language
16 | - Developed by Sun Microsystems.
--------------------------------------------------------------------------------
/notes/JDBC/FEATURES.md:
--------------------------------------------------------------------------------
1 | # JDBC Features
2 |
3 | 1. Standard **API** (Same for all DBMS)
4 | 2. Database Management API
5 | 3. Most of the **JDBC** driver are developed using Java, so they are platform independent.
6 | 4. Huge vendor support for **JDBC**.
7 | 5. Perform basic **CRUD** (Create, Read, Update & Delete) operation very easily.
--------------------------------------------------------------------------------
/notes/JDBC/README.md:
--------------------------------------------------------------------------------
1 | # Java Database Connetivity (JDBC)
2 |
3 | - JDBC is a speification (Guidelines) defined by Java vendor and implemented by Database vendor.
4 | - Database vendor provided implementation is called Driver Software.
--------------------------------------------------------------------------------
/notes/JDBC/SQLInjection.md:
--------------------------------------------------------------------------------
1 | # SQL Injection
2 |
3 | - SQL Injection is a code injection technique that might destory your database.
4 | - SQL Injection usually occurs when you ask a user for input, like their username and instead of username, the user gives you an SQL statement that you will unknowingly run on your database.
5 | - SQL Injection can be prevented by using prepared statement.
--------------------------------------------------------------------------------
/notes/JDBC/StepsToDevelopJDBCApplication.md:
--------------------------------------------------------------------------------
1 | # Steps to Develop JDBC Application
2 |
3 | 
4 |
5 | 1. Load and Register driver class.
6 | ```Class.forName("Oracle.jdbc.OracleDriver");```
7 |
8 | 2. Establish Conection
9 | ```Connection con = Driver.Manager.getConnection( url , DbUsername , DbPassword ) ;```
10 | 3. Creation of statement Object
11 | ``` Statement st = con.createStatement(); ```
12 | 4. Send and Execute SQL Query
13 | ``` Result rs = st.executeQuery("Select * from employees");```
14 | 5. Process Result from ResultSet
15 |
16 | while(rs.next())
17 | {
18 | System.out.Println(rs.getInt(1));
19 | }
20 |
21 | 6. Close connection
22 | ```con.close();```
23 |
--------------------------------------------------------------------------------
/notes/JDBC/lib/mysql-connector-java-8.0.15.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theArjun/java-notes/40fc2ec5c3fc529000ffe8525904bdcadaf7058d/notes/JDBC/lib/mysql-connector-java-8.0.15.jar
--------------------------------------------------------------------------------
/notes/JDBC/src/com/gces/jdbc/DataEntry.java:
--------------------------------------------------------------------------------
1 | package com.gces.jdbc;
2 |
3 | public class DataEntry {
4 |
5 | public String name;
6 | public String address;
7 | public float salary;
8 |
9 | DataEntry(String name, String address, float salary) {
10 | this.name = name;
11 | this.address = address;
12 | this.salary = salary;
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/notes/JDBC/src/com/gces/jdbc/DeleteData.java:
--------------------------------------------------------------------------------
1 | package com.gces.jdbc;
2 | import java.sql.*;
3 |
4 | public class DeleteData {
5 | public static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
6 | public static final String JDB_URL = "jdbc:mysql://localhost:3306/gces";
7 |
8 | public static void main(String[] args) throws ClassNotFoundException, SQLException{
9 | Class.forName(JDBC_DRIVER);
10 | Connection con = DriverManager.getConnection(JDB_URL,"root","");
11 | Statement st = con.createStatement();
12 |
13 | String sql = "DELETE FROM `students` WHERE `id` < 3";
14 |
15 | int deletion = st.executeUpdate(sql);
16 | if(deletion > 0) {
17 | System.out.println("Deleted Successfully.");
18 | }
19 | else
20 | {
21 | System.out.println("Error while deleting.");
22 | }
23 | st.close();
24 | con.close();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/notes/JDBC/src/com/gces/jdbc/SalaryUpdate.java:
--------------------------------------------------------------------------------
1 | package com.gces.jdbc;
2 | import java.sql.*;
3 |
4 | public class SalaryUpdate {
5 | public static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
6 | public static final String JDB_URL = "jdbc:mysql://localhost:3306/gces";
7 |
8 | public static void main(String[] args) throws ClassNotFoundException, SQLException{
9 | String sql = "UPDATE `employee` SET `salary` = 50000 WHERE `post` = 'Manager'";
10 |
11 | Class.forName(JDBC_DRIVER);
12 | Connection con = DriverManager.getConnection(JDB_URL,"root","");
13 | Statement st = con.createStatement();
14 | int updation = st.executeUpdate(sql);
15 | if(updation > 0) {
16 | System.out.println("Updated Successfully");
17 | }
18 | else
19 | {
20 | System.out.println("Can't update.");
21 | }
22 |
23 | st.close();
24 | con.close();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/notes/JDBC/src/com/gces/jdbc/Students.java:
--------------------------------------------------------------------------------
1 | package com.gces.jdbc;
2 | import java.sql.*;
3 |
4 | public class Students {
5 |
6 | public static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
7 | public static final String JDB_URL = "jdbc:mysql://localhost:3306/gces";
8 |
9 | public static void main(String[] args) throws ClassNotFoundException, SQLException {
10 | Class.forName(JDBC_DRIVER);
11 | Connection con = DriverManager.getConnection(JDB_URL,"root","");
12 | String sql = "SELECT * FROM `students` WHERE `id` < 3";
13 | Statement st = con.createStatement();
14 | ResultSet rs = st.executeQuery(sql);
15 |
16 | while(rs.next()) {
17 | System.out.println("Name : "+ rs.getString(2));
18 | System.out.println("Address : "+ rs.getString(3));
19 | System.out.println("DOB : "+ rs.getString(4));
20 | System.out.println("Class : "+ rs.getString(5));
21 | }
22 | st.close();
23 | con.close();
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/notes/JDBC/src/com/gces/jdbc/UpdateManagerSalary.java:
--------------------------------------------------------------------------------
1 | package com.gces.jdbc;
2 |
3 | import java.sql.*;
4 |
5 | public class UpdateManagerSalary {
6 |
7 | private static final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
8 | private static final String JDB_URL = "jdbc:mysql://localhost:3306/testdb";
9 |
10 | public static void main(String[] args) {
11 |
12 | String updateQuery = "UPDATE employee SET SALARY = 50000 WHERE post LIKE '%Manager'";
13 |
14 | try {
15 |
16 | } catch (SQLException exc) {
17 | exc.printStackTrace();
18 | } catch (ClassNOtFoundException exc) {
19 |
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/notes/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | # Java Notes
5 | 
6 |
7 | > ✍ **Arjun Adhikari**, Django & Python Developer
8 |
9 | [](https://bettercodehub.com/)
10 |
11 |
12 | Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible.
13 |
14 | This note is prepared focusing the syllabus of Pokhara University with the guidance of **Lecturer Nishal Gurung**.
15 |
--------------------------------------------------------------------------------
/notes/applet/EXAMPLES.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Examples on Applet
3 | description: More examples on Applet.
4 | ---
5 |
6 | #### Passing Parameter
7 | - Demonstrate the passing of parameters in Applet File.
8 | ##### HTML File
9 | ```html
10 | {% include 'applet/passingParameter/ParamDemo.html' %}
11 | ```
12 | ##### Java File
13 | ```java
14 | {% include 'applet/passingParameter/ParamDemo.java' %}
15 | ```
16 |
17 |
18 |
19 | #### Display Available Fonts
20 | - Display the available fonts in the system.
21 | ```java
22 | {% include 'applet/general/AvailableFonts.java' %}
23 | ```
24 |
25 | #### Custom Font and Size
26 | - Demonstrating applet with custom font text and size.
27 | ```java
28 | {% include 'applet/passingParameter/customFontAndSize/CustomFont.java' %}
29 | ```
30 |
31 |
32 | #### Draw Nepali Flag
33 | - Draw the Nepali Flag using the Applet and graphics.
34 | ```java
35 | {% include 'applet/nepaliFlag/Flag.java' %}
36 | ```
37 |
--------------------------------------------------------------------------------
/notes/applet/HelloApplet.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Applet Demonstration
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/notes/applet/HelloApplet.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | public class HelloApplet extends Applet{
5 | public void paint(Graphics graphicsObject){
6 | graphicsObject.drawString("Hello Applet ! How are you ?", 10 , 20); // 10 are 20 are X-coordinates and Y-coordinates.
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/applet/displayingImage/DisplayImage.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | /*
4 |
5 | */
6 |
7 | public class DisplayImage extends Applet {
8 |
9 | public Image picture;
10 |
11 | public void init() {
12 | picture = getImage(getDocumentBase(), "blue.jpg");
13 | }
14 |
15 | public void paint(Graphics g){
16 | g.drawImage(picture,30,30,this);
17 | }
18 | }
--------------------------------------------------------------------------------
/notes/applet/displayingImage/README.md:
--------------------------------------------------------------------------------
1 | # Displying Image in Applet
2 |
3 | Java will allow the applet to load the data holding the HTML file that started the applet (theDocumentBase) and the directory from which class file was loaded (codeBase). Both documentBase and codeBase return directories as URL object respectively.
4 |
5 |
6 | ## Code
7 | - We've assumed there is an image named `blue.jpg`.
8 | ```java
9 | {% include 'applet/displayingImage/DisplayImage.java' %}
10 | ```
11 |
--------------------------------------------------------------------------------
/notes/applet/displayingImage/blue.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theArjun/java-notes/40fc2ec5c3fc529000ffe8525904bdcadaf7058d/notes/applet/displayingImage/blue.jpg
--------------------------------------------------------------------------------
/notes/applet/general/AvailableFonts.java:
--------------------------------------------------------------------------------
1 | /* This shows the available fonts in Host Computer. */
2 |
3 | /* */
4 |
5 | import java.awt.*;
6 | import java.applet.*;
7 |
8 | public class AvailableFonts extends Applet {
9 | public void paint(Graphics g) {
10 | String message = ""; // Initialize string to empty first.
11 | String fontLists[];
12 | /* I don't get the below line. */
13 | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
14 | fontLists = ge.getAvailableFontFamilyNames();
15 | for (String fontList : fontLists) {
16 | message += fontList + "\n ";
17 | g.drawString(message, 10, 20);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/notes/applet/lifeCycle/LifeCycle.java:
--------------------------------------------------------------------------------
1 | import java.applet.*;
2 | import java.awt.*;
3 |
4 | /*
5 |
8 | */
9 |
10 | public class LifeCycle extends Applet{
11 | String message = "";
12 |
13 | public void init(Graphics graphicsObject){
14 | message += "Inside Init() ";
15 | graphicsObject.drawString(message, 100, 120);
16 | }
17 |
18 | public void start() {
19 | message += "Inside Start() ";
20 | }
21 |
22 | public void paint(Graphics graphicsObject) {
23 | message += "Inside Paint() ";
24 | graphicsObject.drawString(message, 100, 120);
25 | }
26 |
27 | public void stop() {
28 | message += "Inside Stop() ";
29 | }
30 |
31 | public void destroy() {
32 | message += "Inside Destroy() ";
33 | }
34 | }
--------------------------------------------------------------------------------
/notes/applet/passingParameter/ParamDemo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Passing Parameter to Applet
5 |
6 |
7 |
8 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/notes/applet/playingAudio/README.md:
--------------------------------------------------------------------------------
1 | # Playing Audio in Applet
2 |
3 | An applet can play an audio file represented by the AudioClip interface in the java.applet package. The AudioClip interface has three methods, including :
4 | ```public void play()``` − Plays the audio clip one time, from the beginning.
5 | ```public void loop()``` − Causes the audio clip to replay continually.
6 | ```public void stop()``` − Stops playing the audio clip.
7 | To obtain an AudioClip object, you must invoke the getAudioClip() method of the Applet class. The getAudioClip() method returns immediately, whether or not the URL resolves to an actual audio file. The audio file is not downloaded until an attempt is made to play the audio clip.
8 |
9 | ## Code
10 | - We've assumed there is an audio clip named `sample.wav`.
11 | ```java
12 | {% include 'applet/playingAudio/PlayAudio.java' %}
13 | ```
14 |
--------------------------------------------------------------------------------
/notes/applet/playingAudio/sample.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theArjun/java-notes/40fc2ec5c3fc529000ffe8525904bdcadaf7058d/notes/applet/playingAudio/sample.wav
--------------------------------------------------------------------------------
/notes/array/alternativeArrayDeclaration.java:
--------------------------------------------------------------------------------
1 | class AlternativeArrayDeclaration{
2 | public static void main(String args[]){
3 | /* Array can be declared like : type_name[] variable_name; for eg: public static void main(String[] args) */
4 | int a1[] = new int[3];
5 | int[] a2 = new int[2];
6 |
7 | /* We can also declare multiple arrays at a time by this method. */
8 |
9 | int [] a3,a4,a5 = new int [3];
10 | /* which creates the three array variables of integer type */
11 | }
12 | }
--------------------------------------------------------------------------------
/notes/array/arrayAssignment.java:
--------------------------------------------------------------------------------
1 | class ArrayAssignment{
2 | public static void main(String args[]){
3 | int month[] = {1,2,3,4,5,6,7,8,9,10,11,12};
4 | for(int i=0;i<12;i++){
5 | System.out.println("Month : "+month[i]);
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/array/arrayRepresentation01/README.md:
--------------------------------------------------------------------------------
1 | # Array Representation 01
2 |
3 | This representation of array shows how the memory blocks are allocated to the array. Value is not assigned to the memory blocks, though.
4 |
5 | 
6 |
7 | #### Source Code
8 | ```java
9 | {% include 'array/arrayRepresentation01/arrayRepresentation01.java' %}
10 | ```
11 |
--------------------------------------------------------------------------------
/notes/array/arrayRepresentation01/arrayRepresentation01.java:
--------------------------------------------------------------------------------
1 | class ArrayRepresentation {
2 | public static void main(String[] args) {
3 | // First the level of the array is pre-defined, and initial indearray of the
4 | // array is mentioned in assignation.
5 | int[][][] array = new int[2][][];
6 |
7 | // First Level
8 | array[0] = new int[3][];
9 | array[1] = new int[2][];
10 |
11 | // Second Level
12 | array[0][0] = new int[1];
13 | array[0][1] = new int[2];
14 | array[0][2] = new int[3];
15 |
16 | array[1][0] = new int[2];
17 | array[1][1] = new int[2];
18 |
19 | // In this way, the memory blocks are allocated and no memory leakage happens
20 | // here.
21 | }
22 | }
--------------------------------------------------------------------------------
/notes/array/arrayRepresentation02/README.md:
--------------------------------------------------------------------------------
1 | # Array Representation 02
2 |
3 | This representation of array teaches how to allocate the memory block to the elements and assign the integer value to those memory blocks.
4 |
5 | 
6 |
7 | #### Source Code
8 | ```java
9 | {% include 'array/arrayRepresentation02/arrayRepresentation02.java' %}
10 | ```
11 |
--------------------------------------------------------------------------------
/notes/array/arrays.java:
--------------------------------------------------------------------------------
1 | class Array{
2 | public static void main(String args[]){
3 | int days[];
4 | days = new int[12];
5 | for(int i = 0; i<12;i++){
6 | days[i] = i;
7 | }
8 | for(int i = 0; i<12;i++){
9 | System.out.println("Day : "+days[i]);
10 | }
11 | System.out.println(days.getClass().getName());
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/array/averageUsingArray.java:
--------------------------------------------------------------------------------
1 | class Average{
2 | public static void main(String args[]){
3 | double marks[] = {40.6,30.5,90.3,20.8,87.5};
4 | double result=0;
5 |
6 | for(int i=0;i<5;i++){
7 | result +=marks[i];
8 | }
9 | System.out.println("Percentage = "+result/5);
10 | }
11 | }
--------------------------------------------------------------------------------
/notes/array/conventional/README.md:
--------------------------------------------------------------------------------
1 | ## Conventional Way Of Declaring Array
2 |
3 | 
4 |
5 | This method of declaring array is often referred as conventional way of declaring array.
--------------------------------------------------------------------------------
/notes/array/conventional/conventionalWay.java:
--------------------------------------------------------------------------------
1 | class ConventionalWay{
2 | public static void main(String[] args){
3 | int[][] x = new int[4][3]; // The no of pairs of brackets represents the level of array i.e. dimensions.
4 | }
5 | }
--------------------------------------------------------------------------------
/notes/array/doubleTwoDimesionalArray.java:
--------------------------------------------------------------------------------
1 | class DoubleTwoDArray{
2 | public static void main(String args[]){
3 | double nums[][]= {
4 | {0.0,1.0,2.0},
5 | {3.0,4.0,5.0},
6 | {6.0,7.0,8,0}
7 | }; /* Two declare a two dimensional array, the last braces should be ended with braces as like Class in C++ . */
8 | for(int i=0;i<3;i++){
9 | for(int j=0;j<3;j++){
10 | System.out.print(nums[i][j]+ " ");
11 | }
12 | System.out.println();
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/array/extra.md:
--------------------------------------------------------------------------------
1 | # Array Examples
2 |
3 | #### Arrays
4 | ```java
5 | {% include 'array/arrays.java' %}
6 | ```
7 |
8 | #### Alternate Array Declaration
9 | ```java
10 | {% include 'array/alternativeArrayDeclaration.java' %}
11 | ```
12 |
13 | #### Array Assignment
14 | ```java
15 | {% include 'array/arrayAssignment.java' %}
16 | ```
17 |
18 |
19 | #### Average Using Arrays
20 | ```java
21 | {% include 'array/averageUsingArray.java' %}
22 | ```
23 |
24 | #### Two Dimensional Array
25 | ```java
26 | {% include 'array/twoDArray.java' %}
27 | ```
28 |
29 | #### Double Two Dimensional Array
30 | ```java
31 | {% include 'array/doubleTwoDimesionalArray.java' %}
32 | ```
33 |
34 | #### Two Dimensional Array Manual Allocation
35 | ```java
36 | {% include 'array/twoDimensionalArrayManualAllocation.java' %}
37 | ```
38 |
39 | #### Three Dimensional Array
40 | ```java
41 | {% include 'array/threeDimensionalArray.java' %}
42 | ```
43 |
--------------------------------------------------------------------------------
/notes/array/matrixRepresentation/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: Matrix Representation of Arrays
3 | ---
4 | # Matrix Representation
5 |
6 | 
7 |
8 | This type of array declaration is represented in matrix form. Memory wastage is most probable to happen in this scenario and manually unassigned blocks of memory are automatically assigned to zero.
9 |
10 | ```java
11 | {% include 'array/matrixRepresentation/matrixRepresentation.java' %}
12 | ```
13 |
14 | ## Conventional Representation
15 | This method of declaring array is often referred as conventional way of declaring array.
16 | ```java
17 | {% include 'array/conventional/conventionalWay.java' %}
18 | ```
19 |
--------------------------------------------------------------------------------
/notes/array/matrixRepresentation/matrixRepresentation.java:
--------------------------------------------------------------------------------
1 | class MatrixRepresentation {
2 |
3 | public static void main(String[] args) {
4 | int[][] x = new int[4][4];
5 | x[0][0] = 10;
6 | x[0][1] = 12;
7 | x[0][2] = 99;
8 | x[0][3] = 89;
9 | x[1][0] = 28;
10 | x[1][1] = 67;
11 | x[1][2] = 56;
12 | x[2][0] = 80;
13 | x[2][1] = 90;
14 | x[3][0] = 90;
15 |
16 | for (int i = 0; i < 4; i++) {
17 | for (int j = 0; j < 4; j++) {
18 | System.out.println("x[" + i + "][" + j + "] = " + x[i][j]);
19 | }
20 | System.out.println();
21 | }
22 | System.out.println("The unassigned block of memory are assigned to zero.");
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/notes/array/threeDimensionalArray.java:
--------------------------------------------------------------------------------
1 | class ThreeDimensionalArray{
2 | public static void main(String args[]){
3 | int nums[][][] = new int [3][3][3];
4 | int l = 0;
5 | for(int i=0;i<3;i++){
6 | for(int j=0;j<3;j++){
7 | for(int k=0;k<3;k++){
8 | nums[i][j][k] = l;
9 | l++;
10 | }
11 | }
12 | }
13 |
14 | for(int i=0;i<3;i++){
15 | for(int j=0;j<3;j++){
16 | for(int k=0;k<3;k++){
17 | System.out.print(nums[i][j][k]+" ");
18 | }
19 | System.out.println();
20 | }
21 | System.out.println("\n");
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/notes/array/twoDArray.java:
--------------------------------------------------------------------------------
1 | class TwoDimensionalArray{
2 | public static void main(String args[]){
3 | int nums[][] = new int[4][5];
4 |
5 | int i,j,k=0;
6 | for (i=0;i<4;i++){
7 | for(j=0;j<5;j++){
8 | nums[i][j] = k;
9 | k++;
10 | }
11 | }
12 |
13 | for (i=0;i<4;i++){
14 | for(j=0;j<5;j++){
15 | System.out.print(nums[i][j]+" "); /* Print doesn't gets printed in new line , but println does. Know the difference. */
16 | }
17 | System.out.println();
18 | }
19 | System.out.println(nums.getClass().getName()); // This returns the class name for corressponding array type.
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/array/twoDimensionalArrayManualAllocation.java:
--------------------------------------------------------------------------------
1 | class TwoDArray{
2 | public static void main(String args[]){
3 | int nums[][] = new int[4][];
4 | nums[0] = new int[1];
5 | nums[1] = new int[2];
6 | nums[2] = new int[3];
7 | nums[3] = new int[4];
8 | int k = 0;
9 |
10 | for(int i=0;i<4;i++){
11 | for(int j=0;i0){
6 | if(percentage >= 80){
7 | System.out.println("Distinction\n");
8 | }
9 | else if(percentage >= 60){
10 | System.out.println("First Division\n");
11 | }
12 | else if(percentage >= 50){
13 | System.out.println("Second Division\n");
14 | }
15 | else if(percentage >= 40){
16 | System.out.println("Third Division\n");
17 | }
18 | else{
19 | System.out.println("Fail");
20 | }
21 | }else{
22 | System.out.println("Enter a valid percentage.\n");
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/notes/controlStatements/forEach.java:
--------------------------------------------------------------------------------
1 | class ForEach{
2 | public static void main(String args[]){
3 | int nums[] = {1,2,3,4,5,6,7,8,9};
4 | int sum = 0;
5 |
6 | // Now we are using the for-each statements to display the elements of array.
7 | for(int x:nums){
8 | System.out.println("Value is : "+x);
9 | sum+=x;
10 | }
11 | System.out.println("Summation : "+sum);
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/controlStatements/missingBreak.java:
--------------------------------------------------------------------------------
1 | class MissingBreak{
2 | public static void main(String[] args){
3 | for(int i=0;i<12;i++){
4 | switch(i){
5 | case 0:
6 | case 1:
7 | case 2:
8 | case 3:
9 | case 4:
10 | case 5:
11 | System.out.println("i is less than 6");
12 | break;
13 | case 6:
14 | case 7:
15 | case 8:
16 | case 9:
17 | case 10:
18 | case 11:
19 | System.out.println("i is less than 10");
20 | break;
21 | }
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/notes/controlStatements/nonRecursive/Fibonacci/FibonacciDemo.java:
--------------------------------------------------------------------------------
1 | class FibonacciDemo{
2 | public static void main(String[] args ){
3 | Fibonacci fibonacciObjectOne = new Fibonacci(1,2,8);
4 | fibonacciObjectOne.nonRecursive();
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/controlStatements/recursion/Factorial/Factorial.java:
--------------------------------------------------------------------------------
1 | public class Factorial{
2 |
3 | private int number;
4 |
5 | // Setter for number.
6 | public void setNumber(int number){
7 | this.number = number;
8 | }
9 |
10 | // Getter for number.
11 | public int getNumber(){
12 | return this.number;
13 | }
14 |
15 | // Getter for factorial number.
16 | public int getFactNumber(){
17 | return this.factorial(this.number);
18 | }
19 |
20 | // Function that calculates factorial of a number by recursion.
21 | public int factorial (int number){
22 | // Factorial of 0 is suppossed to be 1.
23 | if(number == 0){
24 | return 1;
25 | }else{
26 | // This code implements recursion.
27 | return number * factorial(number - 1);
28 | }
29 | }
30 | }
--------------------------------------------------------------------------------
/notes/controlStatements/recursion/Factorial/FactorialDemo.java:
--------------------------------------------------------------------------------
1 | class FactorialDemo{
2 | public static void main(String[] args){
3 | Factorial numberOne = new Factorial();
4 | numberOne.setNumber(5);
5 |
6 | System.out.println("Factorial of "+numberOne.getNumber()+" is "+numberOne.getFactNumber());
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/controlStatements/recursion/Fibonacci/FibonacciDemo.java:
--------------------------------------------------------------------------------
1 | class FibonacciDemo{
2 | public static void main(String[] args){
3 | // Pass parameter as how many elements you want to see :
4 | Fibonacci fibonacciObjectOne = new Fibonacci(10);
5 | fibonacciObjectOne.display();
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/summationOfFirstFiveElement.java:
--------------------------------------------------------------------------------
1 | class Summation{
2 | public static void main(String[] args){
3 | int nums[] = {1,2,3,4,5,6,7,8,9};
4 | int sum = 0;
5 |
6 | for(int x:nums){
7 | sum+=x;
8 | if(x==5){
9 | break;
10 | }
11 | }
12 | System.out.println("Summations = "+sum);
13 | }
14 | }
--------------------------------------------------------------------------------
/notes/controlStatements/switchStatement.java:
--------------------------------------------------------------------------------
1 | class SampleSwitch{
2 | public static void main(String[] args){
3 | for(int i=0;i<=6;i++){
4 | switch(i){
5 | case 0:
6 | System.out.println("i is zero.");
7 | break;
8 | case 1:
9 | System.out.println("i is one.");
10 | break;
11 | case 2:
12 | System.out.println("i is two.");
13 | break;
14 | case 3:
15 | System.out.println("i is three.");
16 | break;
17 | case 4:
18 | System.out.println("i is four.");
19 | break;
20 | default:
21 | System.out.println("i is greater than 4.");
22 | }
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/doWhile/asExitControlledLoop.java:
--------------------------------------------------------------------------------
1 | class DoWhile {
2 | public static void main(String[] args) {
3 | do {
4 | System.out.println("Hello World"); // This gets printed as do-while is exit controlled loop.
5 | } while (false);
6 | System.out.println("hello Venus"); // This gets printed as do-while condition is false.
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/doWhile/blockVariableDeclaration.java:
--------------------------------------------------------------------------------
1 | class DoWhile {
2 | public static void main(String[] args) {
3 | do {
4 | int x = 10; // Block Variable declaration is allowed.
5 | } while (true);
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/doWhile/finalValueCompairing.java:
--------------------------------------------------------------------------------
1 | class DoWhile {
2 | public static void main(String[] args) {
3 | final int a = 10, b = 20;
4 | do {
5 | System.out.println("Hello World"); // This gets printed once because of exit-controlled mechanism.
6 | } while (a > b);
7 | System.out.println("Hello Venus"); // This also gets printed once.
8 | }
9 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/doWhile/inlineExecution.java:
--------------------------------------------------------------------------------
1 | class DoWhile{
2 | public static void main(String[] args) {
3 | do;
4 | while(true);
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/doWhile/inlinePrinting.java:
--------------------------------------------------------------------------------
1 | class DoWhile {
2 | public static void main(String[] args) {
3 | do
4 | System.out.println("Hello World"); // runs infinitely
5 | while (true);
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/doWhile/inlineVariableDeclaration.java:
--------------------------------------------------------------------------------
1 | class DoWhile {
2 | public static void main(String[] args){
3 | do
4 | int x = 10; // Inline Variable declaration is not allowed.
5 | while(true);
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/doWhile/unReachableStatement.java:
--------------------------------------------------------------------------------
1 | class DoWhile {
2 | public static void main(String[] args) {
3 | do {
4 | System.out.println("Hello World");
5 | } while (true);
6 | System.out.println("Hello Venus"); // Unreachable Statement
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/doWhile/valueAssignAndCompairing.java:
--------------------------------------------------------------------------------
1 | class DoWhile {
2 | public static void main(String[] args) {
3 | int a = 10, b = 20;
4 | do {
5 | System.out.println("Hello World"); // This prints infinitely.
6 | } while (a < b); // Java assigns value at run time.
7 | System.out.println("Hello Venus"); // This is not an unreachable statement here, as Java checks the process only on compile time.
8 | }
9 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/IsThatInfinite.java:
--------------------------------------------------------------------------------
1 | class IsThatInfinite {
2 | public static void main(String[] args) {
3 | for (int i = 1; i <= 5; System.out.println("Nepal")) {
4 | i++;
5 | }
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/byDefaultTrue.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | for(int i = 0; ;i++){
4 | System.out.println("Hello World");
5 | }
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/initializationAndUpdationIsPrint.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | // int i = 0; // This statement cures the bug which wasn't discussed in class : cannot find symbol.
4 | for(System.out.println("Hello World") ; i < 3 ; System.out.println("Hello Venus")){ // Hello World gets printed once and Hello Venus gets printed thrice.
5 | i++;
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/initializationIsPrint.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | int i = 0;
4 | for(System.out.println("Hello World") ; i < 5 ; i++){ // Hello World is printed once; as it is on place of initialization statement.
5 | System.out.println("Hello Venus"); // Hello Venus is printed 5 times.
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/inlinePrinting.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | for(int i = 0;i < 5; i++)
4 | System.out.println("Hello World");
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/inlineVariableDeclaration.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | for(int i = 0;i < 5;i++)
4 | int anotherI = 5;
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/noInitializationConditionUpdation.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | for( ; ; ); // Gets executed infinitely, though output is not visible.
4 | }
5 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/noInitializationConditionUpdationInlinePrint.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | for( ; ; )
4 | System.out.println("Hello World"); // Infinite Print
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/normalExecution.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args) {
3 | for(int i = 0;i<10;i++){
4 | System.out.println("Hello World");
5 | }
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/onlyForLoop.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | for(int i = 0;i < 5; i++);
4 | }
5 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/forLoop/trueCondition.java:
--------------------------------------------------------------------------------
1 | class ForLoop{
2 | public static void main(String[] args){
3 | for(int i = 0;true; i++)
4 | System.out.println("Hello World");
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/booleanVariableAssignmentAsArgument.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | boolean x = true;
4 | if (x = false) { // This compile as if statement expects boolean value as parameter, parameter is false here.
5 | System.out.println("Hello Mercury");
6 | } else {
7 | System.out.println("Hello Venus");
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/booleanVariableAssignmentAsArgument01.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | boolean x = false;
4 | if (x = false) { // This compile as if statement expects boolean value as parameter. This also throws false.
5 | System.out.println("Hello Mercury");
6 | } else {
7 | System.out.println("Hello Venus");
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/booleanVariableAssignmentAsArgument02.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | boolean x = true;
4 | if (x = true) { // This compile as if statement expects boolean value as parameter. This throws true.
5 | System.out.println("Hello Mercury");
6 | } else {
7 | System.out.println("Hello Venus");
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/intAsArgument.java:
--------------------------------------------------------------------------------
1 | class IfTest{
2 | public static void main(String[] args){
3 | int x = 0;
4 | if(x){ // This doesn't compile as if statement expects boolean value as parameter.
5 | System.out.println("Hello Mercury");
6 | }else{
7 | System.out.println("Hello Venus");
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/intValueCompareAsArgument.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | int x = 10;
4 | if (x == 20) { // This compile as if statement expects boolean value as parameter.
5 | System.out.println("Hello Mercury");
6 | } else {
7 | System.out.println("Hello Venus");
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/intVariableAsArgument.java:
--------------------------------------------------------------------------------
1 | class IfTest{
2 | public static void main(String[] args){
3 | if(x=20){ // This doesn't compile as if statement expects boolean value as parameter.
4 | System.out.println("Hello Mercury");
5 | }else{
6 | System.out.println("Hello Venus");
7 | }
8 | }
9 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/trueAsArgument.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | boolean x = false;
4 | if (x == false) { // This compile as if statement expects boolean value as parameter. This throws true.
5 | System.out.println("Hello Mercury");
6 | } else {
7 | System.out.println("Hello Venus");
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/withoutBraces/declaringVariable.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | if(true)
4 | int x = 10; // This statment doesn't compile as we shouldn't write declarative statement inside inline statement, but can write inside block statement.
5 |
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/withoutBraces/declaringVariableInsideBlockIfElse.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | if(true){
4 | int x = 10; // This statment doesn't compile as we shouldn't write declarative statement inside inline statement, but can write inside block statement.
5 | }
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/withoutBraces/onlyIf.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | if(true); // Java denotes the end of statement either by blocks statements {} or semicolon. So, this statement gets executed.
4 | }
5 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/ifElse/withoutBraces/printMessage.java:
--------------------------------------------------------------------------------
1 | class IfTest {
2 | public static void main(String[] args) {
3 | if(true)
4 | System.out.println("Hello World"); // This statement gets executed.
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/while/finalValueCompairing.java:
--------------------------------------------------------------------------------
1 | class WhileTest {
2 | public static void main(String[] args) {
3 | final int a = 10, b = 20;
4 | while(ab){
5 | System.out.println("Hello World"); // This statement won't run as compiler assigns the boolean value of a and b in run time (not in compile-time) & found it to be false.
6 | }
7 | System.out.println("Hello Venus"); //
8 | }
9 | }
--------------------------------------------------------------------------------
/notes/controlStatements/testCases/while/variableComparing01.java:
--------------------------------------------------------------------------------
1 | class WhileTest {
2 | public static void main(String[] args) {
3 | int a = 10, b = 20;
4 | while(a blockchain = new ArrayList<>();
7 | public static void main(String[] args){
8 | Block genesisBlock = new Block(previousHash)
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/dataStructures/stack.java:
--------------------------------------------------------------------------------
1 | class Sample{
2 | public int[] itsStack = new int[];
3 | public boolean isEmpty(){
4 |
5 | }
6 |
7 | public boolean isFull(){
8 |
9 | }
10 |
11 | public boolean push(){
12 |
13 | }
14 |
15 | public boolean pop(){
16 |
17 | }
18 |
19 | public int top(){
20 |
21 | }
22 |
23 | public void display(){
24 |
25 | }
26 |
27 |
28 | }
29 |
30 | class Stack{
31 | public static void main(String[] args){
32 |
33 | }
34 | }
--------------------------------------------------------------------------------
/notes/events/ActionListener/README.md:
--------------------------------------------------------------------------------
1 | # **ActionListener**
2 | - Defines one method to receive actions events.
3 |
4 | **Methods**
5 | ``` void actionPerformed(ActionEvet ae)```
6 |
--------------------------------------------------------------------------------
/notes/events/Adapter/CloseByWindowButton.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.awt.event.*;
3 |
4 | public class CloseByWindowButton extends Frame {
5 | CloseByWindowButton(String title) {
6 | super(title);
7 |
8 | setSize(400, 400);
9 | setVisible(true);
10 | setLayout(new FlowLayout());
11 |
12 | /* Anonymous Class */
13 | addWindowListener(new WindowAdapter() {
14 | public void windowClosing(WindowEvent we) {
15 | System.exit(0);
16 | }
17 | });
18 | }
19 |
20 | public static void main(String[] args) {
21 | new CloseByWindowButton("Close Window By Exit Button");
22 | }
23 | }
--------------------------------------------------------------------------------
/notes/events/Adapter/README.md:
--------------------------------------------------------------------------------
1 | # Adapter Class
2 |
3 | - Java compiles a special feature, called an adapter class, that can simplify he creation of event handlers in certain situations.
4 | - An adapter class prvovides an empty implementation of all methods in an ```EventListener ``` interface.
5 | - It is useful when you want to receive and process only some of the events that are handled by a particular event listener interface .
6 |
7 | Commonly used ```Listener``` Interface implemented by Adapter Class :
8 |
9 |
10 | | Adapter Class | Listener Interface |
11 | | --------------|------------------- |
12 | | ```ComponentAdapter``` | ```ComponentListener``` |
13 | | ```ContainerAdapter``` | ```ContainerListener``` |
14 | | ```FocusAdapter``` | ```FocusListener``` |
15 | | ```KeyAdapter``` |``` KeyListener``` |
16 | | ```MouseMotionAdapter``` | ```MouseMotionListener, MouseListener & MouseWheelListener``` |
17 | | ```WindowAdapter``` | ```WindowListener, WindowFocusListener & WindowStateListener``` |
18 |
19 |
--------------------------------------------------------------------------------
/notes/events/AdjustmentListener/README.md:
--------------------------------------------------------------------------------
1 | # **AdjustmentListener**
2 | - Defines one methods to receive adjustment events.
3 |
4 | **Methods**
5 | 1. ```void adjustmentValueChanged(AdjustmentEvent ae)```
6 |
--------------------------------------------------------------------------------
/notes/events/ComponentListener/README.md:
--------------------------------------------------------------------------------
1 | # **ComponentListener**
2 | - Defines 4 methods to recognize when a component is hidden , moved , resized or shown.
3 |
4 | **Methods**
5 | 1. ```void componentResized(ComponentEvent ce)```
6 | 2. ```void componentMoved(ComponentEvent ce)```
7 | 3. ```void componentShown(ComponentEvent ce)```
8 | 4. ```void componentHidden(ComponentEvent ce)```
9 |
--------------------------------------------------------------------------------
/notes/events/ContainerListener/README.md:
--------------------------------------------------------------------------------
1 | # ContainerListener
2 | - Defines 2 methods to recognize when a componenet is added to or removed from a container.
3 |
4 | **Methods**
5 | 1. ```void containerAdded(ContainerEvent ce)```
6 | 2. ```void containerRemoved(ContainerEvent ce)```
--------------------------------------------------------------------------------
/notes/events/EVENTLISTENERS.md:
--------------------------------------------------------------------------------
1 | # Sources of Events
2 | 1. ```Button```,
3 | 2. ```CheckBox```,
4 | 3. ```Choice```,
5 | 4. ```List```,
6 | 5. ```Menu Item```,
7 | 6. ```Scrollbar```,
8 | 7. ```TextField```,
9 | 8. ```TextArea```,
10 | 9. ```Window```
11 |
12 | > User -> Event source -> Generates Event Objects -> Pass to EventListener(Handler) -> Handle and Return back to Source
13 |
14 |
--------------------------------------------------------------------------------
/notes/events/FocusListener/README.md:
--------------------------------------------------------------------------------
1 | # FocusListener
2 | - Defines 2 methods to recognize a component gain or loses keyboard focuses
3 |
4 | **Methods**
5 | 1. ```void focusGained(FocusEvent fe)```
6 | 2. ```void focusLost(FocusEvent fe)```
--------------------------------------------------------------------------------
/notes/events/ItemListener/README.md:
--------------------------------------------------------------------------------
1 | # ItemListener:
2 | - Defines 1 method to recognize when the state of an item changes
3 |
4 | **Methods**
5 | 1. ```void itemStateChange(ItemEvent ie)```
--------------------------------------------------------------------------------
/notes/events/KeyListener/README.md:
--------------------------------------------------------------------------------
1 | ## **KeyListener Interface**
2 | - Define 3 methods to recognize when a key is pressed, released or typed.
3 |
4 | **Methods**
5 | 1. ```void keyPressed(KeyEvent ke)```
6 | 2. ```void keyReleased(KeyEvent ke)```
7 | 3. ```void keyTyped(KeyEvent ke)```
--------------------------------------------------------------------------------
/notes/events/MouseListener/README.md:
--------------------------------------------------------------------------------
1 | ## **MouseListener**
2 |
3 | - Defines 5 methods to recognize when the mouse is clicked, enters a component, exits component, is pressed, is released.
4 |
5 | **Methods**
6 | 1. ```void mouseClicked(MouseEvent me)```
7 | 2. ```void mouseEntered(MouseEvent me)```
8 | 3. ```void mouseExited(MouseEvent me)```
9 | 4. ```void mousePressed(MouseEvent me)```
10 | 5. ```void mouseReleased(MouseEvent me)```
11 |
--------------------------------------------------------------------------------
/notes/events/MouseMotionListener/README.md:
--------------------------------------------------------------------------------
1 | # MouseMotionListener
2 | - Defines 2 methods to recognize when mouse is dragged or moved.
3 |
4 | **Methods**
5 | 1. ```void mouseDraged(MouseEvent me)```
6 | 2. ```void mouseMoved(MouseEvent me)```
7 |
--------------------------------------------------------------------------------
/notes/events/MouseWheelListener/README.md:
--------------------------------------------------------------------------------
1 | # MouseWheelListener
2 | -Defines 1 method to recognize when the mouse wheel is moved.
3 |
4 | **Methods**
5 | 1. ```void mouseWheelMoved(MouseWheelEvent mwe)```
6 |
--------------------------------------------------------------------------------
/notes/events/TextListener/README.md:
--------------------------------------------------------------------------------
1 | # TextListener
2 | - Defines 1 method to recognize when a text value changes.
3 |
4 | **Methods**
5 | 1. ```void textValueChanged(TextEvent te)```
--------------------------------------------------------------------------------
/notes/events/WindowFocusListener/README.md:
--------------------------------------------------------------------------------
1 | # WindowFocusListener
2 | - Defines 2 methods to recognize when a window gains ore loses input focus
3 |
4 | **Methods**
5 | 1. ```void windowGainedFocus(WindowEvent we)```
6 | 2. ```void windowLostFocus(WindowEvent we)```
--------------------------------------------------------------------------------
/notes/events/WindowListener/README.md:
--------------------------------------------------------------------------------
1 | # WindowListener
2 | - Defines 7 methods to recognize when a window is activated, closed, deactivated,iconified, deiconified, opened or quit.
3 |
4 | **Methods**
5 | 1. ```void windowActivated(WindowEvent we)```
6 | 2. ```void windowClosed(WindowEvent we)```
7 | 3. ```void windowClosing(WindowEvent we)```
8 | 4. ```void windowDeactivated(WindowEvent we)```
9 | 5. ```void windowIconified(WindowEvent we)```
10 | 6. ```void windowDeiconified(WindowEvent we)```
11 | 7. ```void windowOpened(WindowEvent we)```
--------------------------------------------------------------------------------
/notes/exams/examAnswers/programmingAnswers/chapterFour/Eight.java:
--------------------------------------------------------------------------------
1 | /* Write a program to read content from file abc.txt and store it in xyz.txt. */
2 |
3 | import java.io.*;
4 |
5 | class DataTransfer
6 | {
7 | public static void main(String[] args)
8 | {
9 | try
10 | {
11 | FileReader filereader = new FileReader("abc.txt");
12 | FileWriter filewriter = new FileWriter("xyz.txt");
13 |
14 | int i = filereader.read();
15 | while(i != -1)
16 | {
17 | System.out.print((char)i);
18 | filewriter.write(i); // Appends every time
19 | i = filereader.read();
20 | }
21 | filereader.close();
22 | filewriter.flush();
23 | filewriter.close();
24 | }
25 | catch(IOException err){
26 | err.printStackTrace();
27 | }
28 | }
29 | }
--------------------------------------------------------------------------------
/notes/exams/examAnswers/programmingAnswers/chapterFour/abc.txt:
--------------------------------------------------------------------------------
1 | My name is arjun adhikari.
--------------------------------------------------------------------------------
/notes/exams/examAnswers/programmingAnswers/chapterOne/Five.java:
--------------------------------------------------------------------------------
1 | class Five{
2 | public static void main(String[] args){
3 | for(int i = 1; i <= 4; i++){ // First we are running loop from 1 to 4.
4 | for(int j = 0; j < i; j++){ // Then we are running loop from 0 until i.
5 | System.out.print((j+i)%2+" "); // Sum of i and j modulus of 2 equals the alternate of 1 and 0.
6 | }
7 | System.out.println();
8 | }
9 | }
10 | }
11 |
12 | // Practiced Algorithms
13 |
14 | // System.out.print((int)(temp+Math.pow(-1,j))+" ");
15 | // (int)(+Math.pow(-1,))
16 | // System.out.print((j+1)%2+" ");
--------------------------------------------------------------------------------
/notes/exams/examAnswers/programmingAnswers/chapterOne/Four.java:
--------------------------------------------------------------------------------
1 | class Four {
2 | public static void main(String[] args) {
3 | int[] array = { 1, 2, 3, 4, 5 };
4 | int sum = sumArray(array);
5 | System.out.println("Sum : "+sum);
6 | }
7 |
8 | public static int sumArray(int[] array){
9 | int sum = 0;
10 | for(int num:array){
11 | sum += num;
12 | }
13 | return sum;
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/exams/examAnswers/programmingAnswers/chapterOne/Two.java:
--------------------------------------------------------------------------------
1 | class Two{
2 | public static void main(String[] args) {
3 | System.out.println("Hello Nepal");
4 | }
5 | }
--------------------------------------------------------------------------------
/notes/exams/examAnswers/programmingAnswers/chapterTwo/Five.java:
--------------------------------------------------------------------------------
1 | abstract class Animal{ // Define a abstract class.
2 | abstract void eat(); // Define a abstract method.
3 | }
4 |
5 | class Cat extends Animal{
6 | void eat(){ // Override it.
7 | System.out.println("Cat is eating.");
8 | }
9 | }
10 |
11 | class Cow extends Animal{
12 | void eat(){ // Override it.
13 | System.out.println("Animal is eating.");
14 | }
15 | }
16 |
17 | class Five{
18 | public static void main(String[] args){
19 | Animal referrer = new Cat(); // Create referrer object of Parent abstract class.
20 | referrer.eat();
21 | referrer = new Cow();
22 | referrer.eat();
23 | }
24 | }
--------------------------------------------------------------------------------
/notes/exams/examAnswers/programmingAnswers/chapterTwo/One.java:
--------------------------------------------------------------------------------
1 | class A{
2 | void display(){
3 | System.out.println("This is from class A");
4 | }
5 | }
6 | class B extends A{
7 | void display(){
8 | System.out.println("This is from class B");
9 | }
10 | }
11 |
12 | class Demo{
13 | public static void main(String[] args){
14 | A aObject = new A();
15 | B bObject = new B();
16 |
17 | aObject.display();
18 | bObject.display();
19 | // bObject.super.display();
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/exception/ChainedException/ChainExceptionDemo.java:
--------------------------------------------------------------------------------
1 | class ChainExceptionDemo{
2 | static void demoProcess(){
3 | NullPointerException = new NullPointerException("Top Layer");
4 | e.initCause(new ArithmeticException("cause"));
5 | throw e;
6 | }
7 | }
8 |
9 | public static void main(String[] args){
10 | try{
11 | demoProcess();
12 | }catch(NullPointerException e){
13 | System.out.println("Caught : "+e);
14 | System.out.println("Original Cause : "+e.getCause());
15 | }
16 | }
--------------------------------------------------------------------------------
/notes/exception/ChainedException/README.md:
--------------------------------------------------------------------------------
1 | # Chained Exceptions
2 | - allow to associate another exception with an exception.
3 |
4 | > To allow chained Exceptions, two constructors and two methods are added to Throwable.
5 |
6 | 1. Throwable (Throwable cause Exception)
7 | 2. Throwable (String message, Throwable cause Exception)
8 |
9 | Two methods used are:
10 |
11 | 1. Throwable getCause()
12 | 2. Throwable initCause (Throwable causeException)
--------------------------------------------------------------------------------
/notes/exception/Exception.java:
--------------------------------------------------------------------------------
1 | class Exception {
2 | public static void main(String[] args) {
3 | int d, a;
4 | try {
5 | d = 0;
6 | a = 42 / d; // This generates run-time error.
7 | System.out.println("This will not be printed.");
8 | } catch (Exception e) { // e is error; also a parameter type of Arithmetic Exception.
9 | System.out.println("Divide by zero."); // This will get executed.
10 | }
11 | System.out.println("After catch.");
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/exception/NestedTry/NestedTry.java:
--------------------------------------------------------------------------------
1 | class NestedTry{
2 | public static void main(String[] args){ // Command Line Arguments
3 | System.out.println("Args : "+args[0]);
4 | try{
5 | int a = args.length;
6 | int b = 42 / a;
7 | System.out.println("A = "+a);
8 | try{ // Nested Try Block
9 | if(a==1){
10 | a = a/(a-a);
11 | }
12 | }catch(ArrayIndexOutOfBoundsException e){
13 | System.out.println("Array index out of bounds : "+e);
14 | }
15 | }catch(ArithmeticException e){
16 | System.out.println("Divide by zero."+e);
17 | }
18 | try{
19 | args[2] = "Hari";
20 | // System.out.println(args[4]);
21 | }catch(ArrayIndexOutOfBoundsException error){
22 | System.out.println("Error : "+error);
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/notes/exception/NestedTry/README.md:
--------------------------------------------------------------------------------
1 | # Nested Try Statement
2 |
3 | - The try statement can be nested i.e , a try can be inside the block of another try.
4 | - Each time a try statement is entered, the contact of that exception is pushed in the track.
5 | - If an inner try statement doesn't have a catch handler for particular exception, the stack is unwound and the next try statement catch handler are inspected for a match. This continues until one of the catch statement succeeds or until all of the nested try statments are exhausted. If no catch statements matches then the Java Runtime System will handle the exception.
--------------------------------------------------------------------------------
/notes/exception/builtIn/ExceptionDemo.java:
--------------------------------------------------------------------------------
1 | class ExceptionDemo{
2 | static void compute(int n) throws MyException{
3 | if(n > 10){
4 | throw new MyException(n);
5 | }
6 | }
7 | public static void main(String[] args){
8 | try{
9 | compute(1);
10 | compute(20);
11 | }catch(MyException errorMessage){
12 | System.out.println("Caught : "+errorMessage.getMessage()); // Inherited Method from Throwable class
13 | }
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/exception/builtIn/MyException.java:
--------------------------------------------------------------------------------
1 | // Creating own Exception SubClasses
2 |
3 | class MyException extends Exception{
4 | private int detail;
5 | MyException(int a){
6 | this.detail = a;
7 | }
8 | public String toString(){
9 | return "MyException["+detail+"]";
10 | }
11 | // Overriding of toString() is optional and also constructor is optional.
12 | }
--------------------------------------------------------------------------------
/notes/exception/builtIn/README.md:
--------------------------------------------------------------------------------
1 | #Java's Built-in Exceptions
2 |
3 | ```java.lang```
4 |
5 | - Most general of these exceptions are subclasses of the standard type RuntimeException.
6 |
7 | 1. Checked Exception
8 | - That must be included in a method's throw list if that method can generate one of these Exception and does not handle itself.
9 |
10 | eg: ```ClassNotFOundException, IllegalAccessException```
11 |
12 | 2. Unchecked Exception
13 | - These exceptio need not be included in any method's throw list.
14 | - Compiler doesn't check to see if a method handles or throw these exception.
15 | eg: ```ArithmeticException, ArrayIndexOutofBoundsException```
--------------------------------------------------------------------------------
/notes/exception/finally/FinallyDemo.java:
--------------------------------------------------------------------------------
1 | class FinallyDemo{
2 | static void methodOne(){
3 | try{
4 | System.out.println("This is inside method one.");
5 | throw new ArithmeticException();
6 | }finally{
7 | System.out.println("This gets printed everytime.");
8 | }
9 | }
10 | static void methodTwo(){
11 | try{
12 | System.out.println("This is inside method two.");
13 | }finally{
14 | try{
15 | System.out.println("This is inside nested try statement.");
16 | throw new RuntimeException();
17 | }catch(RuntimeException errorMessage){
18 | System.out.println("Error : "+errorMessage.getMessage());
19 | }finally{
20 | System.out.println("Inside Finally block of Nested Try");
21 | }
22 | }
23 | }
24 | public static void main(String[] args){
25 | // methodOne();
26 | methodTwo();
27 | }
28 | }
--------------------------------------------------------------------------------
/notes/exception/finally/FinallyDemoOne.java:
--------------------------------------------------------------------------------
1 | class FinallyDemo{
2 | static void finallyOne(){
3 | int b = 0;
4 | int a;
5 | try{
6 | System.out.println("Inside try.");
7 | a = 2 / b;
8 | return;
9 | }catch(ArithmeticException errorMessage){
10 | System.out.println("Inside catch.");
11 | }finally{
12 | System.out.println("Good Bye");
13 | }
14 | }
15 | public static void main(String[] args){
16 | finallyOne();
17 | }
18 | }
--------------------------------------------------------------------------------
/notes/exception/finally/README.md:
--------------------------------------------------------------------------------
1 | # Finally
2 |
3 | When exceptions are thrown, execution in a method takes a rather abrupt, nonlinear path that alters the normal flow through the method. Depending upon how the method is coded, it is even possible for an exception to cause the method to return prematurely. This could be a problem in some methods.
4 |
5 | The ```finally``` keyword is designed to address this kind of problems. ```finally``` creates a block of code that will be executed after a ```try catch``` block has completed and before the code following the ```try catch``` block. The ```finally``` block will be executed whether or not an exception is thrown.
6 |
7 | If an exception is thrown the ```finally``` block will execute even if no catch statement matches the exception. This can be useful for closing file handles and freeing up any other resources. ```finally``` block is optional.
8 |
9 | > Note
10 |
11 | Each try statments requires at least one catch or finally clause.
--------------------------------------------------------------------------------
/notes/exception/throw/ArgsArithmeticException.java:
--------------------------------------------------------------------------------
1 | class ArgsException{
2 | public static void main(String[] args){
3 | try{
4 | int lengthOfArgs = args.length;
5 | if(lengthOfArgs < 2){
6 | throw new ArithmeticException("Args is less than two.");
7 | }else if(lengthOfArgs > 2){
8 | throw new ArrayIndexOutOfBoundsException("More than Two args.");
9 | }
10 | System.out.println("Two arguments.");
11 | }catch(ArithmeticException errorMessage){
12 | System.out.println("Error Message : "+errorMessage.getMessage());
13 | }catch(ArrayIndexOutOfBoundsException errorMessage){
14 | System.out.println("Error Message : "+errorMessage.getMessage());
15 | }
16 | System.out.println("The program ended successfully.");
17 | }
18 | }
--------------------------------------------------------------------------------
/notes/exception/throw/throwDemo.java:
--------------------------------------------------------------------------------
1 | class ThrowDemo{
2 | public static void main(String[] args){
3 | System.out.println("Example of throw keyword : ");
4 | throw new ArithmeticException(); // Yo chahi hamile generate gareko runtime exception
5 | // int numberOne = 2/0; // Yo chahi java runtime environment le generate gareko runtime exception
6 | // System.out.println(""+numberOne);
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/exception/throw/throwDemoWithMessage.java:
--------------------------------------------------------------------------------
1 | class ThrowDemo{
2 | public static void main(String[] args){
3 | try{
4 | throw new ArithmeticException("bhag gareko sunya le");
5 | }
6 | catch(ArithmeticException errorMessage){
7 | System.out.println("Error : "+errorMessage);
8 | System.out.println("Message : "+errorMessage.getMessage());
9 | }
10 | System.out.println("Happy Ending");
11 | }
12 | }
--------------------------------------------------------------------------------
/notes/exception/throws/DemoOne/ExceptionOne.java:
--------------------------------------------------------------------------------
1 | class ExceptionOne {
2 | static void validAge(int age) throws MyException { // We need to declare the exception; that the method may throw.
3 | if (age < 18) {
4 | throw new MyException("You should be 18+ to cast vote.");
5 | } else {
6 | System.out.println("You can vote.");
7 | }
8 | }
9 |
10 | public static void main(String[] args) {
11 | // If we don't catch the exception : error: unreported exception MyException;
12 | // must be caught or declared to be thrown.
13 | // So we are calling the function under try catch block.
14 |
15 | try {
16 | validAge(19); // During call of the method, programmer must use try catch mechanism.
17 | } catch (MyException error) {
18 | error.printStackTrace();
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/exception/throws/DemoOne/MyException.java:
--------------------------------------------------------------------------------
1 | class MyException extends Exception // This inherits the class Exception.
2 | {
3 | MyException(String message) {
4 | super(message); // This calls the constructor of class Exception.
5 | }
6 | }
7 |
--------------------------------------------------------------------------------
/notes/exception/throws/README.md:
--------------------------------------------------------------------------------
1 | # Throws
2 |
3 | - If a method is capable of causing an exception that it doesn't handle, it must specify this behaviour so that colors of the method can guard themself against that exception you do this by including a throws clause in the method declaration.
4 |
5 | - A throw clause lists the type of exception that a method might throw. This is necessary for all exception, except those of type Error and or runtime Exception or any of their subclasses. All other exception that a method can throw must be declared in throw clause. If they are not, a compile time error will occur.
6 |
7 | ## General Form :
8 |
9 | type methodName (parameter list) throws exceptionList{ / Exception 1, Exception 2 ... etc.
10 | // code goes here
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/notes/exception/throws/ThrowsDemo.java:
--------------------------------------------------------------------------------
1 | class ThrowsDemo {
2 | static void throwOne() throws IllegalAccessException {
3 | System.out.println("Inside throw : ");
4 | // throw new ArithmeticException();
5 | // try{
6 | throw new IllegalAccessException();
7 | // }catch(IllegalAccessException errorMessage){
8 | // System.out.println("Error : "+errorMessage.getMessage());
9 | // }
10 | }
11 |
12 | public static void main(String[] args) {
13 | try {
14 | throwOne();
15 | } catch (IllegalAccessException errorMessage) {
16 | System.out.println("Error : " + errorMessage.getMessage());
17 | }
18 | }
19 | }
20 |
21 | // Step 1: Throw new ArithmeticException without handler
22 | // Step 2: Throw new IllegalAccessException; needs handler
23 | // Step 3: Throw new IllegalAccessException with try catch
24 | // Step 4: IllegalAccessException with throws; with handler on main() method
--------------------------------------------------------------------------------
/notes/general/ExportInJSON/ExportInJSON.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import org.json.simple.JSONObject;
3 |
4 | class ExportInJSON{
5 |
6 | // FileNotFoundException may arise.
7 | public static void main(String[] args) throws FileNotFoundException{
8 | JSONObject objectOne = new JSONObject();
9 |
10 | // Key and values are passed in put() method
11 | objectOne.put("name", "arjun");
12 | objectOne.put("rollno", new Integer(6));
13 | objectOne.put("percentage", new Double(70.6));
14 | objectOne.put("isGraduated", new Boolean(false));
15 |
16 | // Content of objectOne is converted into String.
17 | String jsonContent = objectOne.toString();
18 | // String content is written into .json file.
19 | PrintWriter pw = new PrintWriter("exportedJSON.json");
20 | pw.write(jsonContent);
21 | pw.flush();
22 | pw.close();
23 | }
24 | }
--------------------------------------------------------------------------------
/notes/general/ExportInJSON/JSONEncodeDemo.java:
--------------------------------------------------------------------------------
1 | // ClassPath is set for this class.
2 | import org.json.simple.JSONObject;
3 |
4 | class JSONEncodeDemo {
5 | public static void main(String[] args) {
6 | // Creating a object of JSONObject Class.
7 | JSONObject objectOne = new JSONObject();
8 |
9 | // Key and values are passed in put() method
10 | objectOne.put("name", "arjun");
11 | objectOne.put("rollno", new Integer(6));
12 | objectOne.put("percentage", new Double(70.6));
13 | objectOne.put("isGraduated", new Boolean(false));
14 |
15 | System.out.println(objectOne);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/notes/general/Overriding.java:
--------------------------------------------------------------------------------
1 | // Can static and private function be overrided ?
2 |
3 | class Animal {
4 | static void eat() {
5 | System.out.println("Eating.");
6 | }
7 |
8 | private void move() {
9 | System.out.println("Moving.");
10 | }
11 | }
12 |
13 | class Human extends Animal {
14 | void eat() { // error: eat() in Human cannot override eat() in Animal; overridden method is static.
15 | System.out.println("Human Eating.");
16 | }
17 |
18 | void move() { // move() method is not inherited from Animal class, so for Human, it's not inherited and doesn't seem like overriding.
19 | System.out.println("Human Moving.");
20 | }
21 | }
22 |
23 | class Override {
24 | public static void main(String[] args) {
25 | Human h = new Human();
26 | Animal a = new Animal();
27 |
28 | h.move();
29 | h.eat();
30 | }
31 | }
--------------------------------------------------------------------------------
/notes/general/OwnException.java:
--------------------------------------------------------------------------------
1 | // Create your own Exception.
2 |
3 | class MyException extends Exception { // Inherits the partially unchecked exception class Exception.
4 | MyException(String msg) { // Parameterized constructor for MyException.
5 | super(msg); // Calls the constructor of Exception class; super class.
6 | }
7 | }
8 |
9 | class ExceptionDemo {
10 | static void isValid(int age) throws MyException { // Denotes this code may contain Exception; declaring exception here.
11 | if(age < 18){
12 | throw new MyException("Age is less than 18.");
13 | }else{
14 | System.out.println("Cool, age is greater than 18.");
15 | }
16 | }
17 |
18 | public static void main(String[] args){
19 | try{
20 | isValid(17); // Age is 17; which is less than 18 and should exception.
21 | }catch(MyException error){
22 | error.printStackTrace();
23 | }
24 | }
25 | }
--------------------------------------------------------------------------------
/notes/general/README.md:
--------------------------------------------------------------------------------
1 | # General Java Questions
2 |
3 | 1. Write a program that accepts a number and checks if it equal to the sum of any two numbers in array divided by two. If it doesn't contains such numbers, it should print message to user "**No such numbers found in array**".
4 | > Link to the answer : [Click here](https://github.com/theArjun/Java/blob/819af575612ed1f492d49b2dc4a92bbd95b532ae/general/TargetSumByTwo.java)
--------------------------------------------------------------------------------
/notes/general/RunComment.java:
--------------------------------------------------------------------------------
1 | class RunComment{
2 | public static void main(String[] args){
3 | // This is comment below but gets executed.
4 | // \u000d System.out.println("This is comment."); // The reason for this is that the Java compiler parses the unicode character "\\u000d" as a new line
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/general/swapWithoutThirdVariable.java:
--------------------------------------------------------------------------------
1 | class Swap{
2 | int x;
3 | int y;
4 | // Sets values to the properties
5 | Swap(int val1, int val2){
6 | x=val1;
7 | y=val2;
8 | }
9 | public void printValues(){
10 | System.out.println("X : "+x);
11 | System.out.println("Y : "+y);
12 | }
13 | /* Swaps the values without
14 | third variable */
15 | public void swapValues(){
16 | x=x+y;
17 | y=x-y;
18 | x=x-y;
19 | }
20 | }
21 | class SwapWithoutThirdVariable{
22 | public static void main(String[] args){
23 | Swap exampleOne = new Swap(3,4);
24 | exampleOne.printValues();
25 | exampleOne.swapValues();
26 | exampleOne.printValues();
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/notes/graphics/barChart/BarChart.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class BarChart extends Applet {
7 |
8 | public void paint(Graphics g){
9 | g.setColor(Color.BLACK);
10 | g.drawLine(100,0,100,600);
11 | g.drawLine(0,500,600,500);
12 |
13 | g.setColor(Color.RED);
14 | g.drawRect(200,200,50,300);
15 | g.fillRect(200,200,50,300);
16 | g.setColor(Color.BLUE);
17 | g.drawRect(300,300,50,200);
18 | g.fillRect(300,300,50,200);
19 |
20 | setForeground(Color.BLACK);
21 | g.drawString("Boys",200,520);
22 | g.drawString("Girls",300,520);
23 | g.drawString("51", 210, 180);
24 | g.drawString("38", 310, 280);
25 |
26 | g.drawString("fig : Total Number of Students Appearing in Java Examination", 150, 570);
27 | }
28 | }
--------------------------------------------------------------------------------
/notes/graphics/color/ColorJPanel.java:
--------------------------------------------------------------------------------
1 | import java.awt.Color;
2 | import java.awt.Graphics;
3 | import javax.swing.JPanel;
4 |
5 | public class ColorJPanel extends JPanel {
6 | public void paintComponent(Graphics g) {
7 | super.paintComponent(g);
8 | this.setBackground(Color.WHITE);
9 |
10 | /* Sets new drawing color using integers */
11 | g.setColor(new Color(255,0,0));
12 | g.fillRect(15,50,200,200);
13 | g.drawString("Current RGB : "+g.getColor(), 130, 40);
14 | }
15 |
16 | public static void main(String[] args) {
17 | new ColorJPanel();
18 | }
19 | }
--------------------------------------------------------------------------------
/notes/graphics/color/README.md:
--------------------------------------------------------------------------------
1 | # Color Control
2 |
3 | > Color constants and their RGB values
4 |
5 | | Constant | RGB Value|
6 | |--------|---------|
7 | | ```public static final Color RED``` | 255,0,0 |
8 | | ```public static final Color GREEN``` | 0,255,0 |
9 | | ```public static final Color BLUE``` | 0,0,255 |
10 | | ```public static final Color ORANGE``` | 255,200,0 |
11 | | ```public static final Color PINK``` | 255,75,175 |
12 | | ```public static final Color CYAN``` | 0,255,255 |
13 | | ```public static final Color MAGNETA``` | 255,0,255 |
14 | | ```public static final Color YELLOW``` | 255,255,0 |
15 | | ```public static final Color BLACK``` | 0,0,0 |
16 | | ```public static final Color WHITE``` | 255,255,255 |
17 | | ```public static final Color GRAY``` | 128,128,128 |
18 | | ```public static final Color LIGHT_GRAY``` | 192,192,192 |
19 | | ```public static final Color DARK_GRAY``` | 64,64,64 |
--------------------------------------------------------------------------------
/notes/graphics/color/ShowColors.java:
--------------------------------------------------------------------------------
1 | import javax.swing.JFrame;
2 |
3 | public class ShowColors {
4 | public static void main(String[] args) {
5 | JFrame frame = new JFrame("Using Colors");
6 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
7 |
8 | ColorJPanel colorJPanel = new ColorJPanel();
9 | frame.add(colorJPanel);
10 | frame.setSize(400,180);
11 | frame.setVisible(true);
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/graphics/color/withApplet/ColorDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.Applet;
3 |
4 | /* */
5 |
6 | public class ColorDemo extends Applet {
7 | public void paint(Graphics g) {
8 | g.setColor(new Color(255, 0, 0));
9 | g.fillRect(60, 60, 40, 40);
10 | g.drawString("Hello World", 40, 40);
11 | g.setColor(new Color(0, 255, 0));
12 | g.fillRect(90, 60, 40, 40);
13 | g.drawString("GCES", 40, 80);
14 |
15 | }
16 | }
--------------------------------------------------------------------------------
/notes/graphics/font/CustomFontAndSize.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class CustomFontAndSize extends Applet {
7 | public void paint(Graphics g) {
8 | Font myFont = new Font("serif",Font.BOLD+Font.ITALIC,18);
9 | g.setFont(myFont);
10 | g.drawString("Hello GCES",20,50);
11 | }
12 | }
--------------------------------------------------------------------------------
/notes/graphics/font/README.md:
--------------------------------------------------------------------------------
1 | # Manipulating Fonts
2 |
3 | ## Constants
4 |
5 | ```public static final int PLAIN```
6 | ```public static final int BOLD```
7 | ```public static final int ITALIC```
8 |
9 | ## Graphics methods for manipulating fonts
10 |
11 | - ```public Font getText()```
12 | - ```public void setFont(Font f)```
13 |
14 | ## Constructors
15 | - ```public Font(String name, int style, int size)```
16 |
17 | ## Methods
18 | - ```public int getStyle()```
19 | - ```public int getSize()```
20 | - ```public String getName()```
21 | - ```public String getFamily()```
22 | - ```public boolean isPlain()```
23 | - ```public boolean isBold()```
24 | - ```public boolean isItalic()```
--------------------------------------------------------------------------------
/notes/graphics/font/fontMetrics/FontMetricsDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.Applet;
3 |
4 | /* */
5 |
6 | public class FontMetricsDemo extends Applet {
7 | public void paint(Graphics g) {
8 | Font myFont = new Font("serif", Font.BOLD + Font.ITALIC, 18); // Italic ra Bold duitai banauana ko lagi
9 | g.setFont(myFont);
10 | g.drawString("Hello GCES", 20, 50);
11 |
12 | FontMetrics fm;
13 | fm = getFontMetrics(myFont); // Yo chahi graphics context ko properties
14 |
15 | g.drawString("Ascent Value : " + fm.getAscent(), 20, 80);
16 | g.drawString("Descent Value : " + fm.getDescent(), 20, 100);
17 | g.drawString("Leading Value : " + fm.getLeading(), 20, 120);
18 | g.drawString("Height Value : " + fm.getHeight(), 20, 140);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/notes/graphics/font/fontMetrics/README.md:
--------------------------------------------------------------------------------
1 | # Font Metrics
2 | > Important for Exam
3 |
4 | 
5 |
6 | ## Methods
7 | - ```public int getAscent()```
8 | - ```public int getDescent()```
9 | - ```public int getLeading()```
10 | - ```public int getHeight()```
11 |
12 | ## Graphics Methods for getting a Font's Font Metrics
13 | - ```public FontMetrics getFontMetrics()```
14 | - ```public FontMetrics getFontMetrics(Font f)```
--------------------------------------------------------------------------------
/notes/graphics/geometry/DrawArc.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class DrawArc extends Applet {
7 |
8 | public void paint(Graphics g) {
9 | g.setColor(Color.BLACK);
10 | g.drawArc(10, 10, 100, 100, 10, 170);
11 | g.fillArc(10, 10, 100, 100, 10, -170);
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/graphics/geometry/DrawOval.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class DrawOval extends Applet {
7 |
8 | public void paint(Graphics g) {
9 | g.setColor(Color.GREEN);
10 | g.fillOval(10, 10, 40, 40);
11 | }
12 | }
--------------------------------------------------------------------------------
/notes/graphics/geometry/DrawRectangle.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class DrawRectangle extends Applet {
7 |
8 | public void paint(Graphics g) {
9 | g.setColor(Color.GREEN);
10 | g.fillRect(10, 10, 40, 40);
11 | }
12 | }
--------------------------------------------------------------------------------
/notes/graphics/geometry/PolyLineDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class PolyLineDemo extends Applet {
7 | public void paint(Graphics g){
8 | g.setColor(Color.RED);
9 |
10 | int[] xCo = {10,20,30};
11 | int[] yCo = {100,150,120};
12 |
13 | g.drawPolyLine(xCo, yCo, 3);
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/graphics/geometry/PolygonDemo.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class PolygonDemo extends Applet {
7 | public void paint(Graphics g) {
8 |
9 | g.setColor(Color.RED);
10 |
11 | int[] xPoints = { 100, 130, 145, 160, 190, 160, 145, 130 };
12 | int[] yPoints = { 100, 85, 55, 85,100, 115, 145, 115 };
13 |
14 | Polygon p = new Polygon(xPoints, yPoints, 8);
15 | g.fillPolygon(p);
16 | }
17 | }
--------------------------------------------------------------------------------
/notes/graphics/geometry/RoundRectangle.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class RoundRectangle extends Applet {
7 |
8 | public void paint(Graphics g) {
9 | g.setColor(Color.GREEN);
10 | g.fillRoundRect(10, 10, 40, 40 ,5, 5);
11 | }
12 | }
--------------------------------------------------------------------------------
/notes/graphics/nepaliFlag/Moon.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 |
4 | /* */
5 |
6 | public class Moon extends Applet {
7 |
8 | public static final int ABSCISSA = 100, ORDINATE = 200;
9 |
10 | public void paint(Graphics moon) {
11 |
12 | int[] borderX = {0,};
13 |
14 | setBackground(Color.RED);
15 | Color NEPALIFLAG = new Color(221, 12, 39);
16 | moon.setColor(Color.WHITE);
17 | moon.fillArc(ABSCISSA, ORDINATE, 200, 200, 0, -180);
18 | moon.setColor(Color.RED);
19 | moon.fillArc(ABSCISSA, ORDINATE, 200, 170, 0, -180);
20 |
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/notes/graphics/nepaliFlag/NepaliFlag.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import java.applet.*;
3 | /*
4 |
5 | */
6 |
7 | public class NepaliFlag extends Applet {
8 |
9 | public Image picture;
10 |
11 | public void init() {
12 | picture = getImage(getDocumentBase(), "nepal.png");
13 | }
14 |
15 | public void paint(Graphics flag){
16 | setBackground(Color.WHITE);
17 | flag.drawImage(picture,0,0,this);
18 | showStatus("बिर नेपाली को झन्डा ");
19 | }
20 | }
--------------------------------------------------------------------------------
/notes/graphics/nepaliFlag/nepal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/theArjun/java-notes/40fc2ec5c3fc529000ffe8525904bdcadaf7058d/notes/graphics/nepaliFlag/nepal.png
--------------------------------------------------------------------------------
/notes/introduction/DataTypes.md:
--------------------------------------------------------------------------------
1 | # Data Types
2 |
3 | Java is strongly-typed language.
4 |
5 | ```java
6 | int x = 10.5; ❌
7 | boolean b = 0; ❌
8 | ```
9 |
10 | > Java doesn't support 1/0 as boolean data like C/C++ .
11 |
12 | - Every variable and expression has a type.
13 | - Every type is strictly defined.
14 | - Every assignment should be checked by compile type compatibility.
15 |
16 | ### Note :
17 |
18 | ```java
19 | if(1){ // Needs true / false.
20 | //doesn't run
21 | }
22 | ```
23 |
24 | > No operator overloading, multiple inheritance are supported in Java.
25 |
26 | ### Syntax:
27 |
28 | ```java
29 | data_type identifier = literal ;
30 | ```
31 |
32 | 
33 |
34 | > ADT - derived from Primitive Data Type and performs action.
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/notes/io/BufferedReader/ReadFromGCES.java:
--------------------------------------------------------------------------------
1 | import java.io.FileReader;
2 | import java.io.IOException;
3 | import java.io.BufferedReader;
4 |
5 | class GCES {
6 | public static void main(String[] args) {
7 | try {
8 | BufferedReader br = new BufferedReader(new FileReader("gces.txt"));
9 | int i = br.read(); // Reads the character and stores in integer value - Unicode
10 | while (i != -1) { // Denotes no character
11 | System.out.print((char) i); // Type hinting
12 | i = br.read(); // Iteratively reads the character one by one until loop terminates.
13 | }
14 | br.close();
15 | } catch (IOException error) {
16 | error.printStackTrace();
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/notes/io/BufferedReader/ReadFromGCESReadLine.java:
--------------------------------------------------------------------------------
1 | import java.io.FileReader;
2 | import java.io.IOException;
3 | import java.io.BufferedReader;
4 |
5 | class GCES {
6 | public static void main(String[] args) {
7 | try {
8 | BufferedReader br = new BufferedReader(new FileReader("gces.txt"));
9 | String line = br.readLine();
10 | while (line != null) { // Denotes no character
11 | bw.write(line);
12 | bw.newLine();
13 | line = br.readLine(); // Iteratively reads the line one by one until loop terminates.
14 | }
15 | br.close();
16 | } catch (IOException error) {
17 | error.printStackTrace();
18 | }
19 | }
20 | }
21 |
22 | // System.out.print(line+"\n"); // For only printing lines in console
--------------------------------------------------------------------------------
/notes/io/BufferedReader/gces.txt:
--------------------------------------------------------------------------------
1 | gces
2 | 2019
3 | Happy New Year
--------------------------------------------------------------------------------
/notes/io/BufferedWriter/WriteOnGCES.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 |
3 | class GCES {
4 | public static void main(String[] args) {
5 | try {
6 | BufferedWriter bw = new BufferedWriter(new FileWriter("gces.txt"));
7 | bw.write("gces");
8 | bw.newLine();
9 | bw.write("2019");
10 | bw.newLine();
11 | bw.write("Happy New Year");
12 | bw.flush();
13 | bw.close();
14 | } catch (IOException error) {
15 | error.printStackTrace();
16 | }
17 |
18 | }
19 | }
--------------------------------------------------------------------------------
/notes/io/File/DisplayFileAndDirectories.java:
--------------------------------------------------------------------------------
1 | import java.io.File;
2 |
3 | class DisplayAll{
4 | public static void main(String[] args){
5 | try{
6 | File fileObjectOne = new File("C:\\users\\arjun\\Desktop\\");
7 |
8 | File[] thisDirectory = fileObjectOne.listFiles();
9 | System.out.println("\nYou're in : "+fileObjectOne.getAbsolutePath()+"\n");
10 | for(File thisDir:thisDirectory){
11 | if(thisDir.isFile() || thisDir.isDirectory()){
12 | System.out.println(">> "+thisDir.getName());
13 | }
14 | }
15 | }catch(Exception error){
16 | error.printStackTrace();
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/notes/io/FileReader/FileReaderDemo.java:
--------------------------------------------------------------------------------
1 | import java.io.FileReader;
2 | import java.io.IOException;
3 |
4 |
5 | class FileReaderDemo{
6 |
7 | // Method : int read()
8 | public static void main(String[] args){
9 | try{
10 | FileReader fr = new FileReader("myText.txt");
11 | int i = fr.read();
12 | while(i != -1){ // Denotes no character
13 | System.out.print((char)i); // Type-hinting
14 | i = fr.read();
15 | }
16 | fr.close();
17 | }catch(IOException error){
18 | error.printStackTrace();
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/io/FileReader/FileReaderIntoArray.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 |
3 | class FileReaderDemo{
4 | public static void main(String[] args){
5 | try{
6 | // Method : int read(char[] ch)
7 | File f = new File("myText.txt");
8 | // Dynamically allocating the size of the array according to the text length inside file.
9 | char[] ch = new char[(int)f.length()];
10 | FileReader fr = new FileReader(f);
11 | fr.read(ch);
12 | // Assigns each character into another character variable.
13 | for(char ch1:ch){
14 | System.out.print(ch1);
15 | }
16 | fr.close();
17 | }catch(IOException error){
18 | error.printStackTrace();
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/io/FileReader/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: FileReader
3 | description: Brief info about FileReader Class and examples.
4 | ---
5 |
6 | - to read characters data or text data.
7 | - Here, we can read character by character by character; not line by line.
8 |
9 | ## Constructors
10 |
11 | 1. ```FileReader fr = new FileReader(String fileName);```
12 | 2. ```FileReader fr = new FileReader(File f);```
13 |
14 | **If no file is available, this will throw exception.**
15 |
16 | ## Methods
17 | 1. ```int read ()```
18 | - Unicode value of character.
19 | 2. ```int read (char[] ch)```
20 | - no of characters copied from file into array.
21 | 3. ```void close()```
22 |
23 | ## Examples
24 | #### Text File
25 | ```
26 | {% include 'io/FileReader/myText.txt' %}
27 | ```
28 |
29 | #### Read File By Looping
30 | - Demo of a FileReader class.
31 | ```java
32 | {% include 'io/FileReader/FileReaderDemo.java' %}
33 | ```
34 |
35 | #### Read File With Character Array
36 | - Demo of a FileReader class using a array.
37 | ```java
38 | {% include 'io/FileReader/FileReaderIntoArray.java' %}
39 | ```
40 |
--------------------------------------------------------------------------------
/notes/io/FileReader/myText.txt:
--------------------------------------------------------------------------------
1 | Hello my name is Arjun.
--------------------------------------------------------------------------------
/notes/io/FileWriter/FileWriterAppendDemo.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 |
3 | class FileWriterAppendDemo{
4 | public static void main(String[] args){
5 | try{
6 | // Appends
7 | FileWriter fw = new FileWriter("abc.txt",true);
8 |
9 | fw.write("\n Arjun");
10 | fw.flush();
11 | fw.close();
12 | }catch(IOException error ){
13 | error.printStackTrace();
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/notes/io/FileWriter/FileWriterDemo.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 |
3 | class FileWriterDemo {
4 | public static void main(String[] args) {
5 | try {
6 | FileWriter fw = new FileWriter("abc.txt");
7 | fw.write(100);
8 | fw.write("abc \n Software");
9 | // Paragraph Break
10 | fw.write('\n');
11 | // Character Array
12 | char[] ch = { 'a', 'b', 'c' };
13 | // Writing character array
14 | fw.write(ch);
15 | fw.write('\n');
16 | fw.flush();
17 | fw.close();
18 | } catch (IOException error) {
19 | error.printStackTrace();
20 | }
21 | }
22 | }
--------------------------------------------------------------------------------
/notes/io/PrintWriter/README.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: PrintWriter
3 | description: Brief info about PrintWriter Class and examples.
4 | ---
5 | > Solves problems of FileWriter and BufferedWriter
6 |
7 | ## Constructors :
8 |
9 | 1. ```PrintWriter bw = new PrintWriter(String fname);```
10 | 2. ```PrintWriter bw = new PrintWriter(File f);```
11 | 3. ```PrintWriter bw = new PrintWriter(Writer w);```
12 |
13 | ## Methods
14 |
15 | 1. ```write (int ch)```
16 | 2. ```write(char[] ch)```
17 | 3. ```write(String s)```
18 | 4. ```flush()```
19 | 5. ```close()```
20 | 6. ```print(char ch)...print(int i)...print(boolean b)...print(String s)```
21 | 7. ```println(char ch)...println(int i)...println(boolean b)...println(String s)```
22 |
23 | ## Examples
24 | #### Write On File
25 | - Write some text on file named "abc.txt".
26 | ```java
27 | {% include 'io/PrintWriter/WriteIntoFile.java' %}
28 | ```
29 |
--------------------------------------------------------------------------------
/notes/io/PrintWriter/WriteIntoFile.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 |
3 | class Sample {
4 | public static void main(String[] args) {
5 | try {
6 | PrintWriter pw = new PrintWriter("abc.txt");
7 | pw.print('d'); // Writes character
8 | pw.print(100 + "\n"); // Writes integer
9 | pw.print(true + "\n"); // Writes boolean
10 | pw.print('c' + "\n"); // Writes Character
11 | pw.print("gces" + "\n"); // Writes string
12 | pw.flush();
13 | pw.close();
14 | } catch (IOException error) {
15 | error.printStackTrace();
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/notes/io/README.md:
--------------------------------------------------------------------------------
1 | # Java io Package
2 |
3 | > io refers to input / output.
4 |
5 | Provides for system input and output through data streams, serialization and the file system. Unless otherwise noted, passing a null argument to a constructor or method in any class or interface in this package will cause a NullPointerException to be thrown.
6 |
7 | ## Classes :
8 |
9 | 1. File
10 | 2. FileWriter
11 | 3. FileReader
12 | 4. BufferedWriter
13 | 5. BufferedReader
14 | 6. PrintWriter
15 |
--------------------------------------------------------------------------------
/notes/io/more-examples/DisplayTextFiles.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 |
3 | class DisplayTextFiles {
4 | public static void main(String[] args) throws IOException {
5 | String path = "C:/users/arjun/Desktop";
6 | File[] filesFromPath = (new File(path)).listFiles();
7 | for (File fileFromPath : filesFromPath) {
8 |
9 | if (fileFromPath.getName().endsWith(".txt")) { // First getName() will return the file name into string and endsWith() checks the file extension like REGEX.
10 | System.out.println(fileFromPath.getName()); // Prints all txt files in Desktop.
11 | }
12 | }
13 | }
14 | }
--------------------------------------------------------------------------------
/notes/io/more-examples/abc.txt:
--------------------------------------------------------------------------------
1 | First line from File one
2 | Second Line from File one
--------------------------------------------------------------------------------
/notes/io/more-examples/xyz.txt:
--------------------------------------------------------------------------------
1 | First line from File two
2 | Second Line from File Two
--------------------------------------------------------------------------------
/notes/literals/testForLiterals/DoubleWIthD.java:
--------------------------------------------------------------------------------
1 | class DoubleOne{
2 | public static void main(String[] args){
3 | double f = 123.45656d;
4 | System.out.println("Value of f is :"+f);
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/literals/testForLiterals/DoubleWithHexaDecimalLiteral.java:
--------------------------------------------------------------------------------
1 | class DoubleThree{
2 | public static void main(String[] args){
3 | double f = 0x123.56;
4 | System.out.println("Value of f is :"+f);
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/literals/testForLiterals/DoubleWithOctalLiteral.java:
--------------------------------------------------------------------------------
1 | class DoubleTwo{
2 | public static void main(String[] args){
3 | double f = 0123.56;
4 | System.out.println("Value of f is :"+f);
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/literals/testForLiterals/DoubleWithoutD.java:
--------------------------------------------------------------------------------
1 | class Double{
2 | public static void main(String[] args){
3 | double f = 123.456;
4 | System.out.println("Value of f is :"+f);
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/literals/testForLiterals/FloatWithF.java:
--------------------------------------------------------------------------------
1 | class FloatOne{
2 | public static void main(String[] args){
3 | float f = 123.4f;
4 | System.out.println("Value of f is :"+f);
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/literals/testForLiterals/FloatWithoutF.java:
--------------------------------------------------------------------------------
1 | class Float{
2 | public static void main(String[] args){
3 | float f = 123.456;
4 | System.out.println("Value of f is :"+f);
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/networking/ConnectionLess/Receiver.java:
--------------------------------------------------------------------------------
1 | import java.io.IOException;
2 | import java.net.*;
3 |
4 | public class Receiver {
5 | public static void main(String[] args) throws IOException{
6 |
7 | DatagramSocket ds = new DatagramSocket(6666);
8 |
9 | byte[] buf = new byte[1024];
10 |
11 | DatagramPacket dp = new DatagramPacket(buf, 1024);
12 | ds.receive(dp);
13 |
14 | String str = new String(dp.getData(), 0, dp.getLength());
15 | System.out.println(str);
16 | ds.close();
17 | }
18 | }
--------------------------------------------------------------------------------
/notes/networking/ConnectionLess/Sender.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import java.net.*;
3 |
4 | public class Sender {
5 | public static void main(String[] args) throws Exception{
6 | DatagramSocket ds = new DatagramSocket(6666);
7 | String str = "Welcome Java";
8 | InetAddress ip = InetAddress.getByName("127.0.0.1");
9 |
10 | DatagramPacket dp = new DatagramPacket(str.getBytes(), str.length(),ip, 3000);
11 |
12 | ds.send(dp);
13 | ds.close();
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/networking/HTTPURLConnection/README.md:
--------------------------------------------------------------------------------
1 | # HTTP URL Connection
2 |
3 | ## Implementation
4 | ```java
5 | {% include 'networking/HTTPURLConnection/HttpURLConnectionDemo.java' %}
6 | ```
7 |
--------------------------------------------------------------------------------
/notes/networking/InetAddress/README.md:
--------------------------------------------------------------------------------
1 | # InetAddress Class
2 | - InetAddress represents an IP address.
3 | - ```java.net.InetAddress``` class provides methods to get the IP of any hostname(eg : facebook.com);
4 |
5 | ## Methods
6 | 1. ```public static InetAddress getByName(String host) throws UnknownHostException```
7 | 2. ```public static InetAddress getLocalHost() throws UnknownHostException```
8 | 3. ```public static InetAddress getHostName() throws UnknownHostException```
9 | - Rturns hostname of IP Address.
10 | 4. ```public static InetAddress getHostAddress() throws UnknownHostException```
11 | 5. ```String toString()```
12 | - Converts IP Address to a String
13 |
14 | ## Implementation
15 | ```java
16 | {% include 'networking/InetAddress/InetAddressDemo.java' %}
17 | ```
18 |
19 |
--------------------------------------------------------------------------------
/notes/networking/ServerToClient/Client.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import java.net.*;
3 |
4 | class Client {
5 | public static void main(String[] args) throws IOException{
6 |
7 | Socket s = new Socket ("localhost",6666);
8 |
9 | DataInputStream dis = new DataInputStream(s.getInputStream());
10 |
11 | // Typehinting the UTF message into string.
12 | String message = (String)dis.readUTF();
13 |
14 | System.out.println("Message from Server : " + message);
15 | s.close();
16 | }
17 | }
--------------------------------------------------------------------------------
/notes/networking/ServerToClient/README.md:
--------------------------------------------------------------------------------
1 | # Server to Client Connection
2 |
3 | This example demonstrates the messaging from server to the client.
4 |
5 | ## Client Side Implementation
6 | ```java
7 | {% include 'networking/ServerToClient/Client.java' %}
8 | ```
9 |
10 |
11 | ## Server Side Implementation
12 | ```java
13 | {% include 'networking/ServerToClient/Server.java' %}
14 | ```
15 |
--------------------------------------------------------------------------------
/notes/networking/ServerToClient/Server.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import java.net.*;
3 |
4 | class Server {
5 | public static void main(String[] args) throws IOException{
6 |
7 | // Step 1: First, server should instatiate ServerSocket object.
8 | ServerSocket ss = new ServerSocket(6666);
9 |
10 | // Step 2 : Then, Server object envokes accept() method of ServerSocket class. This waits for client until client creates Socket object.
11 | Socket s = ss.accept();
12 |
13 | // This gets the message sent by the client.
14 | DataOutputStream dout = new DataOutputStream(s.getOutputStream());
15 |
16 | dout.writeUTF("Hello Client !");
17 | dout.flush();
18 | dout.close();
19 | ss.close();
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/networking/UDPMessaging/README.md:
--------------------------------------------------------------------------------
1 | # UDP Messaging
2 |
3 | ## Client Side Implementation
4 | ```java
5 | {% include 'networking/UDPMessaging/UDPClient.java' %}
6 | ```
7 |
8 |
9 | ## Server Side Implementation
10 | ```java
11 | {% include 'networking/UDPMessaging/UDPServer.java' %}
12 | ```
13 |
--------------------------------------------------------------------------------
/notes/networking/UDPMessaging/UDPClient.java:
--------------------------------------------------------------------------------
1 | import java.net.*;
2 |
3 | public class UDPClient {
4 |
5 | private static final int port = 9999;
6 |
7 | public static void main(String[] args) throws Exception {
8 |
9 | // In client, port number isn't necessary in DatagramSocket.
10 | DatagramSocket ds = new DatagramSocket();
11 |
12 | String msg = "Hello Server !";
13 |
14 | // String is needed to be converted to bytes array.
15 | byte[] msgByteArray = msg.getBytes();
16 |
17 | // As I'm testing on my own system, I am referring to localhost.
18 | InetAddress address = InetAddress.getLocalHost();
19 |
20 | // At sender side, DatagramPacket accepts four parameters while sending :
21 | // i. byte array of message
22 | // ii. length of byte array
23 | // iii. IP address
24 | // iv. Port number
25 | DatagramPacket dp = new DatagramPacket(msgByteArray, msgByteArray.length, address, port);
26 | ds.send(dp);
27 |
28 | ds.close();
29 | }
30 | }
--------------------------------------------------------------------------------
/notes/networking/URL/README.md:
--------------------------------------------------------------------------------
1 | # URL Class
2 |
3 | ```http://abc.com:8080/test.php```
4 |
5 | ## Constructors
6 |
7 | 1. ```public URl (String protocol, String host, int port, String file)```
8 | 2. ```public URl (String protocol, String host, String file)```
9 | 3. ```public URl (URL Contex String url)```
10 | 4. ```public URl (String url)```
11 |
12 |
13 | ## Methods
14 |
15 | 1. ```public String getProtocol()```
16 | 1. ```public String getHost()```
17 | 1. ```public String getPort()```
18 | 1. ```public String getFile()```
19 | 1. ```public String getQuery()``` // ?name = "GCES"
20 |
21 |
22 |
23 | ## Implementation
24 | ```java
25 | {% include 'networking/URL/URLDemo.java' %}
26 | ```
27 |
--------------------------------------------------------------------------------
/notes/networking/URL/URLDemo.java:
--------------------------------------------------------------------------------
1 | import java.net.*;
2 |
3 | class URLDemo {
4 |
5 | public static void main(String[] args) throws MalformedURLException {
6 |
7 | URL obj = new URL("http://www.thearjun.tech:80/index.htm");
8 | System.out.println("Protocol : " + obj.getProtocol());
9 | System.out.println("Hostname : " + obj.getHost());
10 | System.out.println("Port : " + obj.getPort());
11 | System.out.println("File Hosted : " + obj.getFile());
12 | System.out.println("External Form : " + obj.toExternalForm());
13 | }
14 | }
--------------------------------------------------------------------------------
/notes/networking/URLConnection/README.md:
--------------------------------------------------------------------------------
1 | # URL Connection
2 |
3 | ## Implementation
4 | ```java
5 | {% include 'networking/URLConnection/URLConnectionDemo.java' %}
6 | ```
7 |
--------------------------------------------------------------------------------
/notes/networking/chatApplication/Arjun.java:
--------------------------------------------------------------------------------
1 | import java.net.*;
2 | import java.io.*;
3 |
4 | class Arjun {
5 | public static void main(String[] args) throws IOException{
6 | /* Let's use port 6666 for example. */
7 | Socket s = new Socket("192.168.0.122",6666);
8 |
9 | DataOutputStream dout = new DataOutputStream(s.getOutputStream());
10 |
11 | // Writes the message in UTF Format.
12 | dout.writeUTF("Hello, my Name is Arjun. Can I know information about my attendance status ?");
13 | dout.flush();
14 | dout.close();
15 | s.close();
16 | }
17 | }
--------------------------------------------------------------------------------
/notes/networking/chatApplication/GCESServer.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import java.net.*;
3 |
4 | class GCESServer {
5 | public static void main(String[] args) throws IOException {
6 |
7 | // Step 1: First, server should instatiate ServerSocket object.
8 | ServerSocket ss = new ServerSocket(6666);
9 |
10 | // Step 2 : Then, Server object envokes accept() method of ServerSocket class.
11 | // This waits for client until client creates Socket object.
12 | Socket s = ss.accept();
13 |
14 | // This gets the message sent by the client.
15 | DataInputStream dis = new DataInputStream(s.getInputStream());
16 |
17 | // Typehinting the UTF message into string.
18 | String message = (String) dis.readUTF();
19 |
20 | System.out.println("Message from client : " + message);
21 | ss.close();
22 | }
23 | }
--------------------------------------------------------------------------------
/notes/networking/chatApplication/README.md:
--------------------------------------------------------------------------------
1 | # Client to Server Messaging
2 |
3 | This example demonstrates the messaging from client to the server.
4 |
5 | ## Client Side Implmentation
6 | ```java
7 | {% include 'networking/chatApplication/Arjun.java' %}
8 | ```
9 |
10 | ## Server Side Implementation
11 | ```java
12 | {% include 'networking/chatApplication/GCESServer.java' %}
13 | ```
14 |
--------------------------------------------------------------------------------
/notes/networking/checkInternetConnection/IsInternetAvailable.java:
--------------------------------------------------------------------------------
1 | /* This program checks whether your device is connected to Internet or not. */
2 |
3 | import java.net.InetSocketAddress;
4 | import java.net.Socket;
5 |
6 | /**
7 | * @author arjun
8 | */
9 | public class IsInternetAvailable {
10 | public static void main(String[] args) {
11 | Socket sock = new Socket() ;
12 | InetSocketAddress address = new InetSocketAddress("www.thearjun.tech", 80);
13 | try{
14 | sock.connect(address, 3000);
15 | System.out.println("Active Internet Connection");
16 | sock.close();
17 | }
18 | catch(Exception exc) {
19 | System.out.println("No Internet Connection");
20 | }
21 |
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/notes/networking/checkInternetConnection/README.md:
--------------------------------------------------------------------------------
1 | # Check Internet Connection
2 |
3 | ## Implementation
4 | ```java
5 | {% include 'networking/checkInternetConnection/IsInternetAvailable.java' %}
6 | ```
7 |
--------------------------------------------------------------------------------
/notes/networking/dualConnection/Client.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import java.net.*;
3 | import java.util.Scanner;
4 |
5 | class Client {
6 | public static void main(String[] args) throws IOException{
7 |
8 | Socket s = new Socket ("localhost",6666);
9 |
10 | System.out.println("Enter a number : ");
11 | Scanner sc = new Scanner(System.in);
12 | int num = sc.nextInt();
13 |
14 | DataOutputStream dout = new DataOutputStream(s.getOutputStream());
15 |
16 | dout.writeUTF("" + num);
17 |
18 | DataInputStream dis = new DataInputStream(s.getInputStream());
19 |
20 | // Typehinting the UTF message into string.
21 | String message = (String)dis.readUTF();
22 |
23 | System.out.println("Square : " + message);
24 | s.close();
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/notes/networking/dualConnection/README.md:
--------------------------------------------------------------------------------
1 | # Dual Connection
2 |
3 | This example demonstrates the dual connection between the client and the server.
4 | The client sends a number as a payload to the server and server returns the square of that number.
5 |
6 |
7 | ## Client Side Implementation
8 | ```java
9 | {% include 'networking/dualConnection/Server.java' %}
10 | ```
11 |
12 | ## Server Side Implementation
13 | ```java
14 | {% include 'networking/dualConnection/Server.java' %}
15 | ```
16 |
--------------------------------------------------------------------------------
/notes/networking/dualConnection/Server.java:
--------------------------------------------------------------------------------
1 | import java.io.*;
2 | import java.net.*;
3 |
4 | class Server {
5 | public static void main(String[] args) throws IOException{
6 |
7 | // Step 1: First, server should instatiate ServerSocket object.
8 | ServerSocket ss = new ServerSocket(6666);
9 |
10 | // Step 2 : Then, Server object envokes accept() method of ServerSocket class. This waits for client until client creates Socket object.
11 | Socket s = ss.accept();
12 |
13 | DataInputStream dis = new DataInputStream(s.getInputStream());
14 |
15 | // Typehinting the UTF message into string.
16 | String message = (String)dis.readUTF();
17 |
18 | int num = Integer.valueOf(message);
19 |
20 |
21 | int snum = num * num;
22 |
23 |
24 | // This gets the message sent by the client.
25 | DataOutputStream dout = new DataOutputStream(s.getOutputStream());
26 |
27 | dout.writeUTF("" + snum);
28 | dout.flush();
29 | dout.close();
30 | ss.close();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/notes/networking/whoisImplementation/README.md:
--------------------------------------------------------------------------------
1 | # WHOIS Implementation
2 |
3 | ## Implementation
4 | ```java
5 | {% include 'networking/whoisImplementation/Whois.java' %}
6 | ```
7 |
--------------------------------------------------------------------------------
/notes/networking/whoisImplementation/Whois.java:
--------------------------------------------------------------------------------
1 | import java.net.*;
2 | import java.io.*;
3 |
4 | class Whois {
5 | public static void main(String args[]) throws Exception {
6 | int c;
7 |
8 | // Create a socket connected to internic.net, port 43.
9 | Socket s = new Socket("whois.internic.net", 43);
10 |
11 | // Obtain input and output streams.
12 | InputStream in = s.getInputStream();
13 | OutputStream out = s.getOutputStream();
14 |
15 | // Construct a request string.
16 | String str = (args.length == 0 ? "MHProfessional.com" : args[0]) + "\n";
17 |
18 | // Convert to bytes.
19 | byte buf[] = str.getBytes();
20 |
21 | // Send request.
22 | out.write(buf);
23 |
24 | // Read and display response.
25 | while ((c = in.read()) != -1) {
26 | System.out.print((char) c);
27 | }
28 | s.close();
29 | }
30 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/accessModifiers/Movie.java:
--------------------------------------------------------------------------------
1 | class Movie{
2 | public String name, producer;
3 |
4 | void setName(String name){
5 | this.name = name;
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/accessModifiers/README.md:
--------------------------------------------------------------------------------
1 | # Access Modifiers/ Control
2 |
3 | - Encapsulation provides anoter important attribute: access Control
4 |
5 | 
6 |
7 | - Following tables summarizes what Java constructs each Java access control can be applied.
8 |
9 | 
10 |
11 | The given table can be visualized as :
12 |
13 |
14 | 
15 |
--------------------------------------------------------------------------------
/notes/oop/classesObjects/accessModifiers/movieDemo.java:
--------------------------------------------------------------------------------
1 | class MovieDemo{
2 | public static void main(String[] args){
3 | Movie movieObjectOne = new Movie();
4 | movieObjectOne.name = "500 Days of Summer";
5 | movieObjectOne.producer = "Ashish Romantic";
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/anonymous/AnonymousClass.java:
--------------------------------------------------------------------------------
1 | class AnonymousClass {
2 | void printInfo() {
3 | System.out.println("My name is Unnamed.");
4 | }
5 | }
6 |
7 |
--------------------------------------------------------------------------------
/notes/oop/classesObjects/anonymous/AnonymousDemo.java:
--------------------------------------------------------------------------------
1 | class AnonymousDemo{
2 | public static void main(String[] args) {
3 | AnonymousClass objectOne = new AnonymousClass() {
4 | void printInfo () {
5 | System.out.println("My name is Arjun Adhikari.");
6 | }
7 | }; // Semicolon is needed here.
8 |
9 | objectOne.printInfo();
10 | }
11 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/classesObjectsImplementation/Animal.java:
--------------------------------------------------------------------------------
1 | class Animal{
2 | int numberOfLegs;
3 | String color;
4 |
5 | Animal(){
6 | numberOfLegs = 4;
7 | color = "Unspecified";
8 | }
9 |
10 | Animal(int legs, String col){
11 | numberOfLegs = legs;
12 | color = col;
13 | }
14 |
15 | // void eat(String)
16 |
17 | void display(){
18 | System.out.println("Legs = "+this.numberOfLegs); // This refers to this object.
19 | System.out.println("Color = "+ this.color);
20 | }
21 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/classesObjectsImplementation/AnimalDemo.java:
--------------------------------------------------------------------------------
1 | class AnimalDemo{0
2 | public static void main(String[] args){
3 | Animal animalOne = new Animal();
4 | Animal animalTwo = new Animal(3,"Pink");
5 | Animal animalThree = new Animal();
6 |
7 | animalOne.display();
8 | animalTwo.display();
9 |
10 | }
11 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/classesObjectsImplementation/Box.java:
--------------------------------------------------------------------------------
1 | class Box{
2 | double height, width, length;
3 |
4 | // Box(){
5 | // height = 0.0;
6 | // width = 0.0;
7 | // }
8 |
9 | // Box(double h, double w){
10 | // height = h;
11 | // width = w;
12 | // }
13 |
14 | void volume(){
15 | System.out.println("Volume = "+height * width * length);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/notes/oop/classesObjects/classesObjectsImplementation/BoxDemo.java:
--------------------------------------------------------------------------------
1 | class BoxDemo{
2 | public static void main(String[] args){
3 | Box boxOne = new Box();
4 | Box boxTwo = new Box();
5 | Box boxThree = new Box();
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/classesObjectsImplementation/Calculate.java:
--------------------------------------------------------------------------------
1 | class Calculate
2 | {
3 | int num1, num2;
4 |
5 | Calculate(int number1, int number2)
6 | {
7 | num1 = number1;
8 | num2 = number2;
9 | }
10 |
11 | boolean equalTo(Calculate obj)
12 | {
13 | if (obj.num1 == num1 && obj.num2 == num2)
14 | {
15 | return true;
16 | }
17 | else
18 | {
19 | return false;
20 | }
21 | }
22 |
23 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/classesObjectsImplementation/CalculateDemo.java:
--------------------------------------------------------------------------------
1 | class CalculateDemo
2 | {
3 | public static void main(String[] args)
4 | {
5 | //object as parameter
6 | Calculate obj1 = new Calculate(100,22);
7 | Calculate obj2 = new Calculate(100,22);
8 | Calculate obj3 = new Calculate(22,100);
9 | System.out.println("obj1 == obj2 :"+obj1.equalTo(obj2));
10 | System.out.println("obj1 == obj3 :"+obj1.equalTo(obj3));
11 |
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/constructor/Box.java:
--------------------------------------------------------------------------------
1 | class Box
2 | {
3 | double height, width, length;
4 | //default constructor
5 | Box()
6 | {
7 | height = 1.0;
8 | width = 2.0;
9 | length = 3.0;
10 | }
11 | //parameterized constructor
12 | Box(double height, double width, double length)
13 | {
14 | this.height = height;
15 | this.width = width;
16 | this.length = length;
17 | }
18 | Box(double height)
19 | {
20 |
21 | }
22 | // void initiateVariable()
23 | // {
24 | // height = 1.0;
25 | // width = 2.0;
26 | // length = 3.0;
27 | // }
28 |
29 | void volume()
30 | {
31 | System.out.println(height*width*length);
32 | }
33 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/constructor/BoxDemo.java:
--------------------------------------------------------------------------------
1 | class BoxDemo
2 | {
3 | public static void main(String[] args)
4 | {
5 | Box box1 = new Box(2,2,2);
6 | Box box2 = new Box();
7 | // box1.initiateVariable();
8 | box1.volume();
9 | box2.volume();
10 | }
11 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/constructor/README.md:
--------------------------------------------------------------------------------
1 | # Constructor
2 |
3 | 
4 |
5 | - A constructor initializes an object immediately upon creation.
6 | - Constuctor has same name as the class it resides and it syntactically similar to a method.
7 | - No return type no void. This is because the implicit return type of a class constructor is the class type itself.
8 | - If not constructor provided, java itself create default constructor and assin default value to the variable.
--------------------------------------------------------------------------------
/notes/oop/classesObjects/final/README.md:
--------------------------------------------------------------------------------
1 | # Final
2 |
3 | - A field can be declared as final. Doing so prevents its contents from being modified making it essentially a constant.
4 | - Must initialize a final field when it is declared.
5 | - You ca do this in one of two ways :
6 | 1. You can give it a value whn it is declared.
7 |
8 | public class Sample{
9 | final int h = 8;
10 | }
11 |
12 | 2. You can assign it a value within a constructor.
13 |
14 | public class Sample{
15 | final int h;
16 | Sample(){
17 | h = 8;
18 | }
19 | }
20 |
21 | 3. You can't do like this :
22 |
23 | final int a;
24 | a = 8;
--------------------------------------------------------------------------------
/notes/oop/classesObjects/final/Sample.java:
--------------------------------------------------------------------------------
1 | public class Sample{
2 | final int h = 8;
3 | }
4 |
5 | class Final{
6 | public static void main(String[] args){
7 | Sample sampleObject;
8 | System.out.println("H = "+sampleObject.h);
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/final/finalTwo.java:
--------------------------------------------------------------------------------
1 | class Sample{
2 | final int h;
3 | Sample(){
4 | h = 8;
5 | }
6 | }
7 |
8 | class Final{
9 | public static void main(String[] args){
10 | Sample sampleObject = new Sample();
11 | System.out.println("H = "+sampleObject.h);
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/nestedInnerClass/README.md:
--------------------------------------------------------------------------------
1 | # Nested and Inner Class
2 |
3 | It is possible to define a class within another class, such classes are knoen as nested classes.
4 | The scope of a nested class is bounded by the scopoe of its enclosing class.
5 |
6 | class A{ // Enclosing class
7 | class B{ // Inner Class
8 | // Can Access All
9 | }
10 | }
11 |
12 | It is important to realize that an instance of inner class can be created only in the context of outer class.
--------------------------------------------------------------------------------
/notes/oop/classesObjects/nestedInnerClass/classAssignment.java:
--------------------------------------------------------------------------------
1 | class Outer{
2 | int outerX = 100;
3 | int outerY = 200;
4 |
5 | void test(){
6 | Inner innerObject = new Inner();
7 | innerObject.display();
8 | }
9 |
10 | void testM(){
11 | System.out.println(outerY);
12 | }
13 |
14 | class Inner{
15 | void display(){
16 | System.out.println("OuterX = "+outerX);
17 | testM();
18 | }
19 | }
20 | }
21 |
22 | class InnerClassDemo{
23 | public static void main(String[] args){
24 | Outer outerObject = new Outer();
25 | outerObject.test();
26 | }
27 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/nestedInnerClass/classAssignment01.java:
--------------------------------------------------------------------------------
1 | class Outer{
2 | int outerX = 100;
3 | int outerY = 200;
4 |
5 | void test(){
6 | Inner innerObject = new Inner();
7 | innerObject.display();
8 | }
9 |
10 | void testM(){
11 | System.out.println(outerY);
12 | }
13 |
14 | class Inner{
15 | void display(){
16 | System.out.println("OuterX = "+outerX);
17 | testM();
18 | }
19 | }
20 | }
21 |
22 | class InnerClassDemo{
23 | public static void main(String[] args){
24 | Inner innerObjectOne = new Inner();
25 | innerObjectOne.test();
26 | }
27 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/nestedInnerClass/classAssignment02.java:
--------------------------------------------------------------------------------
1 | class Outer{
2 | int outerX = 100;
3 | void test(){
4 | Inner innerObject = new Inner();
5 | innerObject.display();
6 | }
7 |
8 | class Inner{
9 | int y = 10;
10 | void display(){
11 | System.out.println("Display : outerX = "+outerX);
12 | }
13 | }
14 |
15 | void showY(){
16 | System.out.println(y); // Error Y is not shown here.
17 | }
18 | }
19 |
20 | class InnerClassDemo{
21 | public static void main (String[] args){
22 | Outer outerObect = new Outer();
23 | outerObect.test();
24 |
25 | Inner fakeInnerObject = new Inner(); // X
26 | }
27 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/simpleClass/AssigningObjectReferenceVariables/Box.java:
--------------------------------------------------------------------------------
1 | class Box{
2 | double width;
3 | double height;
4 | double length;
5 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/simpleClass/AssigningObjectReferenceVariables/BoxDemo.java:
--------------------------------------------------------------------------------
1 | class BoxDemo{
2 | public static void main(String[] args){
3 | Box myBox = new Box();
4 | Box myBoxReferrer = myBox;
5 |
6 | // Explanation in README
7 |
8 | myBoxReferrer = null; // Here, myBox has been set to null, but myBoxReferrer still points to original object.
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/simpleClass/AssigningObjectReferenceVariables/README.md:
--------------------------------------------------------------------------------
1 | # Assigning Object Reference Objects
2 |
3 | We might think that myBoxReferrer is being assigned a reference to a copy of the object referred to by myBox. That is, we might think that myBox and myBoxReferrer to a separate and distinct objects, However this would be wrong. Instead after this fragment executes myBox and myBoxReferrer will both refer to the same object. The assignment of myBox and myBoxReferrer did not allocate any memory or copy any part of the original object. It simply makes myBoxReferrer refer to the same object as does myBox, Thus, any changes made to the object through myBoxReferrer will affect the object to which myBox is referring, since they are the same object.
--------------------------------------------------------------------------------
/notes/oop/classesObjects/simpleClass/Box.java:
--------------------------------------------------------------------------------
1 | class Box{
2 | double width;
3 | double height;
4 | double length;
5 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/simpleClass/BoxDemo.java:
--------------------------------------------------------------------------------
1 | class BoxDemo{
2 | public static void main(String[] args){
3 | Box myBox = new Box();
4 | // Box myBoxOne;
5 | // myBoxOne = new Box(); // We can declare and assign the objects this way, too.
6 | double volume;
7 |
8 | myBox.width = 10;
9 | myBox.height = 20;
10 | myBox.length = 30;
11 |
12 | volume = myBox.width*myBox.height*myBox.length;
13 | System.out.println("Volume = "+volume);
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/simpleClass/DeclareObjects.java:
--------------------------------------------------------------------------------
1 | class BoxDemoTwo{
2 | public static void main(String[] args){
3 | Box myBox;
4 | myBox = new Box(); // This will invoke the default constructor made by JVM.
5 |
6 | myBox.width = 10;
7 | myBox.height = 20;
8 | myBox.length = 30;
9 |
10 | double volume = myBox.width*myBox.height*myBox.length;
11 | System.out.println("Volume = "+volume);
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/oop/classesObjects/static/README.md:
--------------------------------------------------------------------------------
1 | # Static
2 |
3 | - When a member is declared static, it ca be accessed before any objects of its class are created and without reference to any object.
4 | - Can declare on both methods and variables to be static.
5 | - Instance variable declared as static are essentially global variable.
6 | - When objects of its class are declaredm no copy of static vaiable is made.
7 | - All instances of the class share the class static variable.
8 | - Syntax to retrieve class variable and method :
9 | ``` ClassName.variable;
10 | ClassName.method();```
11 |
12 | - Methods declared as static have several restrictions:
13 | 1. Thery can onlny directly call other static methods.
14 | 2. They can only directly access static data.
15 | 3. They cannot refer to this or super in anyway.
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassFour/AbstractDemo.java:
--------------------------------------------------------------------------------
1 | class AbstractDemo{
2 | public static void main(String[] args){
3 | Shape shapeObjectOne; // = new Shape(); // Abstract class cannot instantiate any object. This is just a variable, not an object.
4 | // shapeObjectOne.paint(); // Yo garna paidaina
5 |
6 | Circle circleObjectOne = new Circle(); // Circle is not abstract and does not override abstract method draw() in Shape.
7 | circleObjectOne.draw();
8 |
9 | }
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassFour/Circle.java:
--------------------------------------------------------------------------------
1 | class Circle extends Shape{
2 | void draw(){
3 | System.out.println("I am drawing.");
4 | }
5 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassFour/Shape.java:
--------------------------------------------------------------------------------
1 | abstract class Shape{ // To make abstract method, we must make abstract class too.
2 | double radius, length, height, breadth;
3 | void paint(){
4 | System.out.println("I am painting.");
5 | }
6 | abstract void draw(); // This must be overridden.
7 | }
8 |
9 |
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassOne/AbstractAreas.java:
--------------------------------------------------------------------------------
1 | class AbstractAreas{
2 | public static void main(String[] args){
3 | Figure figureObjectOne = new Rectangle(10,10); // Illegal now
4 | Rectangle rectangleObjectOne = new Rectangle(5,9);
5 |
6 | Figure figureReference; // This is OK; no object is created.
7 | figureReference = rectangleObjectOne;
8 | System.out.println("Area is : "+figureReference.area());
9 |
10 | Triangle triangleObjectOne = new Triangle(5,4);
11 | figureReference = triangleObjectOne;
12 | System.out.println("Area is : "+figureReference.area());
13 | }
14 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassOne/Figure.java:
--------------------------------------------------------------------------------
1 | abstract class Figure{ // This is abstract class.
2 | double dimensionOne;
3 | double dimensionTwo;
4 |
5 | Figure(double dimensionOne, double dimensionTwo){
6 | this.dimensionOne = dimensionOne;
7 | this.dimensionTwo = dimensionTwo;
8 | }
9 | abstract double area(); // This is abstract method.
10 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassOne/Rectangle.java:
--------------------------------------------------------------------------------
1 | class Rectangle extends Figure{
2 | Rectangle(double dimensionOne, double dimensionTwo){
3 | super(dimensionOne, dimensionTwo); // This calls the constructor of super class.
4 | }
5 | // override area for rectangle
6 | double area(){
7 | System.out.println("Inside Area for Rectangle : ");
8 | return dimensionOne*dimensionTwo;
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassOne/Triangle.java:
--------------------------------------------------------------------------------
1 | class Triangle extends Figure{
2 | Triangle(double dimensionOne, double dimensionTwo){
3 | super(dimensionOne,dimensionTwo);
4 | }
5 | // Override area for Right Triangle
6 | double area(){
7 | System.out.println("Inside area for Triangle : ");
8 | return dimensionOne * dimensionTwo/2;
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassThree/AbstractDemo.java:
--------------------------------------------------------------------------------
1 | class AbstractDemo{
2 | public static void main(String[] args){
3 | // Creating objects of various Phones.
4 | Iphone iPhoneObject = new Iphone();
5 | Huawei huaweiObject = new Huawei();
6 |
7 | // Calls static show function which displays the configuration irrespective of their types; Abstract superclass is used.
8 | show(iPhoneObject);
9 | show(huaweiObject);
10 | }
11 |
12 | public static void show(Phone object){
13 | object.showConfig();
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassThree/Huawei.java:
--------------------------------------------------------------------------------
1 | class Huawei extends Phone{
2 | // Method that displays the configuratio of Huawei Phone.
3 | public void showConfig(){
4 | System.out.println("Good Battery Life, Android Kitkat");
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassThree/Iphone.java:
--------------------------------------------------------------------------------
1 | class Iphone extends Phone{
2 | // Method that displays the configuration of Iphone.
3 | public void showConfig(){
4 | System.out.println("Better Display, IOS 10");
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassThree/Phone.java:
--------------------------------------------------------------------------------
1 | // Class contains abstract methods, so class is abstract.
2 | abstract class Phone{
3 | // Defining abstract class for showing configuration of various phones.
4 | public abstract void showConfig();
5 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassTwo/AbstractDemo.java:
--------------------------------------------------------------------------------
1 | class AbstractDemo{
2 | public static void main(String[] args){
3 | ArjunPhone arjunVariable; // ArjunPhone is abstract. So, no object can't be instantiated from the class; though variable can be created.
4 | // Same applies for SamirPhone
5 |
6 | // But, Suman Phone is concrete class, so it can instantiate object.
7 | SumanPhone sumanObject = new SumanPhone();
8 | System.out.println("\nThis is from Suman Object : ");
9 | sumanObject.call();
10 | sumanObject.dance();
11 | sumanObject.move();
12 |
13 | // Using Dynamic Method Dispatch, we can assign the variable of abstract super class to the object of concrete sub class.
14 | arjunVariable = new SumanPhone();
15 | System.out.println("\nThis is from Arjun Variable : ");
16 | arjunVariable.call();
17 | arjunVariable.dance();
18 | arjunVariable.move();
19 | }
20 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassTwo/ArjunPhone.java:
--------------------------------------------------------------------------------
1 | // Since the methods are abstract, the class is also abstract.
2 | abstract class ArjunPhone{
3 | // Implemented calling feature.
4 | public void call(){
5 | System.out.println("Calling ...");
6 | }
7 | // Planning to develop dancing, moving feature.
8 | // As body can't be implemented the abstract keyword is used before function definition.
9 | abstract public void dance();
10 | abstract public void move();
11 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassTwo/SamirPhone.java:
--------------------------------------------------------------------------------
1 | // Samir was also unable to extend dancing feature, so this class becomes abstract.
2 | abstract class SamirPhone extends ArjunPhone{
3 | // Later, Samir decides to extend the feature proposed by Arjun.
4 | public void move(){
5 | System.out.println("Moving...");
6 | }
7 | // Samir was also unable to implement the dancing feature.
8 | // As any class inherited from abstract class fails to implement all the abstract methods, the class also becomes abstract and can't instantiate any method.
9 |
10 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/AbstractClass/AbstractClassTwo/SumanPhone.java:
--------------------------------------------------------------------------------
1 | class SumanPhone extends SamirPhone{
2 | public void dance(){
3 | System.out.println("Dancing...");
4 | }
5 | // Now this class fulfills to implement all the methods inherited from the abstract class, this class is no more abstract and called as CONCRETE CLASS.
6 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/Box.java:
--------------------------------------------------------------------------------
1 | class Box{
2 | double width;
3 | double height;
4 | double depth;
5 |
6 | Box(Box object){ // This constructor is called copy constructor.
7 | this.width = object.width;
8 | this.height = object.height;
9 | this.depth = object.depth;
10 | }
11 |
12 | Box(double width, double height, double depth){ // This constructor is called parameterized constructor.
13 | this.width = width;
14 | this.height = height;
15 | this.depth = depth;
16 | }
17 |
18 | Box(){ // This constructor is called default constuctor.
19 |
20 | }
21 |
22 | Box(double length){ // This gets envoked assuming box is a cube.
23 | this.width = this.height = this.depth = length;
24 | }
25 |
26 | double volume(){
27 | return width * height * depth;
28 | }
29 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/BoxDemo.java:
--------------------------------------------------------------------------------
1 | class BoxDemo{
2 | public static void main(String[] args){
3 | BoxWeight boxWeightOne = new BoxWeight(10,20,15,32);
4 | BoxWeight boxWeightTwo = new BoxWeight(2,3,4,5);
5 |
6 | double volume;
7 | volume = boxWeightOne.volume();
8 | System.out.println("Volume of Box Weight One is "+ volume);
9 | System.out.println("Weight of Box Weight One is "+ boxWeightOne.weight);
10 | volume = boxWeightTwo.volume();
11 | System.out.println("Volume of Box Weight Two is "+ volume);
12 | System.out.println("Weight of Box Weight Two is "+ boxWeightTwo.weight);
13 | }
14 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/BoxWeight.java:
--------------------------------------------------------------------------------
1 | class BoxWeight extends Box{
2 | double weight;
3 |
4 | BoxWeight (double width, double height, double depth, double weight){
5 | this.width = width;
6 | this.height = height;
7 | this.depth = depth;
8 | this.weight = weight;
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/README.md:
--------------------------------------------------------------------------------
1 | # Inheritance
2 |
3 | Super Class --> Sub Class --> Includes all of the member of its superclass.
4 |
5 | - uses 'extends' keyword.
6 | - Being a superclass for a subclass doesnot mean that the superclass cannot be send by itself.
7 | - Further, a class can be a super class for another subclass.
8 |
9 | General Form :
10 |
11 | class SubClassName extends SuperClassName{
12 | // codes goes here
13 | }
14 |
15 | - Java doesn't support multiple inheritance.
16 | - Subclass cannot access private members of the superclass.
--------------------------------------------------------------------------------
/notes/oop/inheritance/derivation/OrderDerivation.java:
--------------------------------------------------------------------------------
1 | class A{
2 | A(){
3 | System.out.println("Inside A"); // This gets envoked first.
4 | }
5 | }
6 |
7 | class B extends A{
8 | B(){
9 | System.out.println("Inside B"); // This gets envoked after superclass.
10 | }
11 | }
12 |
13 | class C extends B{
14 | C(){
15 | System.out.println("Inside C"); // This gets envoked at last.
16 | }
17 | }
18 |
19 | class OrderDerivation{
20 | public static void main(String[] args){
21 | C cObject = new C();
22 | }
23 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/finalWithInheritance/README.md:
--------------------------------------------------------------------------------
1 | # Final with Inheritance
2 |
3 | 1. as constant
4 | 2. Final to prevent overriding inheritance
5 |
6 | class A{
7 | final void mOne(){
8 | //code goes here.
9 | }
10 | }
11 | class B extends A{
12 | void m1(){ // Illegal ; overriding is prohibited.
13 |
14 | }
15 | }
16 |
17 | 3. To prevent inheritance
18 |
19 | final class A{
20 | // code goes here
21 | }
22 | class B extends A{ // Error
23 | // code goes here
24 | }
25 |
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/Circle.java:
--------------------------------------------------------------------------------
1 | class Circle implements Shape{
2 | // Implementing the draw method from Shape
3 | public void draw(){
4 | System.out.println("Inside draw of Circle");
5 | }
6 | // Implementing the default area method from Shape; not mandatory
7 | public void area(){
8 | System.out.println("Inside area of Circle.");
9 | }
10 |
11 | // Now we are creating the method that prints the perimeter inherited from the abstract method.
12 | public void printPerimeter(){
13 | System.out.println("Perimeter of Circle : "+perimeter*5);
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/Graphics.java:
--------------------------------------------------------------------------------
1 | interface Graphics{
2 | void draw();
3 |
4 | default void pencil(){
5 | System.out.println("This is pencil method from Graphics.");
6 | }
7 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/InterfaceDemo.java:
--------------------------------------------------------------------------------
1 | class InterfaceDemo{
2 | public static void main(String[] args){
3 | // First we are creating the referrer variable of Abstract class and assigning it to the object of Circle Class.
4 | Shape shapeReferrer = new Circle();
5 | // Then, we are envoking the draw method from the Circle.
6 | shapeReferrer.draw();
7 | shapeReferrer.area();
8 |
9 | // Abstract class can only call the method defined in it.
10 | // shapeReferrer.printPerimeter(); // Illegal
11 |
12 | // This will envoke the printPerimeter() function and hence prints the perimeter.
13 | Circle circleObjectOne = new Circle();
14 | circleObjectOne.printPerimeter();
15 |
16 | // Same applies for new object of Rectangle.
17 | shapeReferrer = new Rectangle();
18 | shapeReferrer.draw();
19 | shapeReferrer.area();
20 |
21 | Rectangle rectangleObjectOne = new Rectangle();
22 | rectangleObjectOne.printPerimeter();
23 |
24 | }
25 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/NestedInterface/Animal.java:
--------------------------------------------------------------------------------
1 | class Animal{
2 | // Creating the interface inside class; nested interface.
3 | interface Activity{
4 | public default void move(){
5 | System.out.println("Animal is moving.");
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/NestedInterface/Dog.java:
--------------------------------------------------------------------------------
1 | // To get access to Nested Interface : we write OuterClassName.NestedClasName
2 | class Dog implements Animal.Activity{
3 | public void move(){
4 | System.out.println("Dog is moving.");
5 | }
6 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/NestedInterface/NestedInterfaceDemo.java:
--------------------------------------------------------------------------------
1 | class NestedInterfaceDemo{
2 | public static void main(String[] args){
3 | Dog dogObject = new Dog();
4 | dogObject.move();
5 |
6 | // This is how, we refer to subclass object from nested interface referrer variable.
7 | Animal.Activity nestedReferrerOne = new Dog();
8 | nestedReferrerOne.move();
9 |
10 | // To be questioned here; called Anonymous Class
11 | // Animal.Activity nestedReferrerTwo = new Animal.Activity() {};
12 | }
13 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/NestedInterface/README.md:
--------------------------------------------------------------------------------
1 | # Nested Interface
2 |
3 | **We can declare an interface in another interface or class. Such an interface is termed as a nested interface.**
4 |
5 | Following are the rules governing a nested interface.
6 |
7 | 1. A nested interface declared within an interface must be public.
8 | 2. A nested interface declared within a class can have any access modifier.
9 | 3. A nested interface is by default static.
10 |
11 | Such interface can be declared a member of class or another interface such as interface is called a member interface. It can be declared as public, protected or private.
12 |
13 | interface OuterInterface{
14 | interface InnerInterface{
15 | // code goes here.
16 | }
17 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/Rectangle.java:
--------------------------------------------------------------------------------
1 | class Rectangle implements Shape{
2 | // Implementing the draw method from Shape
3 | public void draw(){
4 | System.out.println("Inside Draw of Rectangle");
5 | }
6 | // Implementing the default area method from Shape; not mandatory
7 | public void area(){
8 | System.out.println("Inside area of Rectangle");
9 | }
10 | // Now we are creating the method that prints the perimeter inherited from the Shape Class.
11 | public void printPerimeter(){
12 | System.out.println("Perimeter of Rectangle: "+perimeter);
13 | }
14 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/interface/Shape.java:
--------------------------------------------------------------------------------
1 | // First we are creating a interface named Shape.
2 | interface Shape{
3 | void draw();
4 | // Now we are implementing the default keyword for methods.
5 | // Using the default keyword, we can have body inside the method in abstract classes.
6 | default void area(){
7 | System.out.println("Area from Shape");
8 | }
9 | // Now we are implementing the final/static keyword in order to declare the variable.
10 | final int perimeter = 1;
11 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/methodOverRiding/Animal.java:
--------------------------------------------------------------------------------
1 | class Animal{
2 | public void eat(){
3 | System.out.println("Animal eats grass.");
4 | }
5 | }
6 | class Human extends Animal{
7 | public void eat(){
8 | // System.out.println("Human eats rice.");
9 | super.eat(); // vitra kehi lekhna paidaina
10 | }
11 | }
12 | class Inherit{
13 | public static void main(String[] args){
14 | Animal animalObject = new Animal();
15 | Human humanObject = new Human();
16 |
17 | animalObject.eat();
18 | humanObject.eat();
19 | }
20 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/methodOverRiding/DynamicMethodDispatch/DynamicMethodDispatch.java:
--------------------------------------------------------------------------------
1 | class A{
2 | void callMe(){
3 | System.out.println("Inside A");
4 | }
5 | }
6 |
7 | class B extends A{
8 | void callMe(){
9 | System.out.println("Inside B");
10 | }
11 | }
12 |
13 | class C extends A{
14 | void callMe(){
15 | System.out.println("Inside C");
16 | }
17 | }
18 |
19 | class Dispatch{
20 | public static void main(String[] args){
21 | A aObject = new A();
22 | B bObject = new B();
23 | C cObject = new C();
24 |
25 | A referrer; // reference of type A refers to A
26 | referrer = aObject;
27 | referrer.callMe();
28 |
29 | referrer = bObject;
30 | referrer.callMe();
31 |
32 | referrer = cObject;
33 | referrer.callMe();
34 |
35 | B anotherReferrer;
36 | // anotherReferrer = aObject; // This won't compile. Incompatible type
37 | }
38 | }
--------------------------------------------------------------------------------
/notes/oop/inheritance/methodOverRiding/DynamicMethodDispatch/README.md:
--------------------------------------------------------------------------------
1 | # Dynamic Method Dispatch
2 | ## How Java implements run-time polymorphism ?
3 |
4 | 
5 |
6 | - Overiding method allow Java to support run-time polymorphism.
7 | - Dynamic method dispatch is the mechanism by which a call to an overridden method is resolved at run time, rather than compile time.
8 | - The type of the ovject being referred to that determine which version of an overridden method will be executed.
--------------------------------------------------------------------------------
/notes/oop/inheritance/methodOverRiding/README.md:
--------------------------------------------------------------------------------
1 | # Method Overriding
2 |
3 | - In a class hierarchy, when a method in a subclass has the same name and the type signature as a method in its superclass, then the method in the subclass is said to override the method in the superclass.
4 | - When an overridden method is called from within its subclass, it will always reger to the version of that method defined by the subclass.
5 | - The version of the method defined by the superclass will be hidden.
6 | - If we need to invoke version of superclass, we must use super inside the subclass.
--------------------------------------------------------------------------------
/notes/oop/inheritance/super/README.md:
--------------------------------------------------------------------------------
1 | # Super
2 |
3 | Using ```super()``` :
4 |
5 | - Whenever a sub class needs to refer to its immediate superclass, it can do so by use of the keyword ```super```.
6 | - ```super()``` has two general forms :
7 | 1. The first calls the super class constructor.
8 | 2. It is used to access a member of the super class that has been hidden by member of a subclass.
9 |
10 | - ```super()``` must always be the first statement executed inside a subclass constructor.
11 |
12 | When constructor are executed in inheritance?
13 | - Order of Derivation
--------------------------------------------------------------------------------
/notes/oop/usingPackage/PackageDemo.java:
--------------------------------------------------------------------------------
1 | import gces.Student;
2 |
3 | class PackageDemo{
4 | public static void main(String[] args){
5 | Student studentObjectOne = new Student("Bishal",10);
6 | Student studentObjectTwo = new Student("Nishal",20);
7 |
8 | studentObjectOne.display();
9 | studentObjectTwo.display();
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/notes/oop/usingPackage/gces/Student.java:
--------------------------------------------------------------------------------
1 | package gces ;
2 | public class Student{
3 | String name;
4 | int rollNo;
5 |
6 | public Student(String name, int rollNo){
7 | this.name = name;
8 | this.rollNo = rollNo;
9 | }
10 |
11 | public void display(){
12 | System.out.println("The details of student is :");
13 | System.out.println("Name = "+name);
14 | System.out.println("Roll No = "+rollNo);
15 | }
16 | }
--------------------------------------------------------------------------------
/notes/oop/usingPackage/tuts/README.md:
--------------------------------------------------------------------------------
1 | # How to set CLASSPATH ?
2 |
3 | > For Windows:
4 |
5 | Follow the picture below :
6 |
7 | 
8 |
9 | > For MacOS/Linux :
10 |
11 | ```export CLASSPATH = /home/arjun/Desktop/workspace/Java/oop/packages```
12 |
13 | ## Checking the CLASSPATH variable
14 |
15 | > For Windows:
16 |
17 | ```echo %CLASSPATH%```
18 |
19 | > For LINUX / MacOS:
20 |
21 | ```echo $CLASSPATH```
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/notes/operators/assignmentOperators.java:
--------------------------------------------------------------------------------
1 | class Assignment{
2 | public static void main(String[] args){
3 | int a = 1;
4 | int b = 2;
5 | int c = 3;
6 |
7 | a+=5;
8 | b*=4;
9 | c+=a*b;
10 | int d=c%6;
11 |
12 | System.out.println("a = "+a);
13 | System.out.println("b = "+b);
14 | System.out.println("c = "+c);
15 | System.out.println("d = "+d);
16 | }
17 | }
--------------------------------------------------------------------------------
/notes/operators/basicArithmeticOperators.java:
--------------------------------------------------------------------------------
1 | class Basic{
2 | public static void main(String[] args){
3 |
4 | // Arithmetic operations using integers
5 |
6 | int a = 1+1;
7 | int b = a*3;
8 | int c = b/4;
9 | int d = c-a;
10 | int e = -d;
11 |
12 | System.out.println("a = "+a);
13 | System.out.println("b = "+b);
14 | System.out.println("c = "+c);
15 | System.out.println("d = "+d);
16 | System.out.println("e = "+e);
17 |
18 | // Arithmetic operations using doubles
19 |
20 | double da = 1+1;
21 | double db = da*3;
22 | double dc = db/4;
23 | double dd = dc-da;
24 | double de = -dd;
25 |
26 | System.out.println("da = "+da);
27 | System.out.println("db = "+db);
28 | System.out.println("dc = "+dc);
29 | System.out.println("dd = "+dd);
30 | System.out.println("de = "+de);
31 |
32 | }
33 | }
--------------------------------------------------------------------------------
/notes/operators/bitwiseOperators.java:
--------------------------------------------------------------------------------
1 | class Bitwise{
2 | public static void main(String[] args){
3 | int a = 10;
4 | int b = 42;
5 |
6 | // Bitwise NOT operator ~
7 | System.out.println("Bitwise NOT operator a ~ b = "+~a);
8 |
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/operators/decimalToBinary.java:
--------------------------------------------------------------------------------
1 | class DecToBin{
2 | public static void main(String[] args){
3 | int dec = 35;
4 | int bin=0,rem=0;
5 | while(dec!=0){
6 | rem=dec%2;
7 | bin=(bin*10)+rem;
8 | dec=dec/2;
9 | }
10 | System.out.println("In Binary = "+bin);
11 | }
12 | }
--------------------------------------------------------------------------------
/notes/operators/incrementDecrement.java:
--------------------------------------------------------------------------------
1 | class IncDec{
2 | public static void main(String[] args) {
3 | int a = 1;
4 | int b = 2;
5 | int c;
6 | int d;
7 | c = ++b;
8 | d = a++;
9 | System.out.println("a = "+a);
10 | System.out.println("b = "+b);
11 | System.out.println("c = "+c);
12 | System.out.println("d = "+d);
13 | }
14 | }
--------------------------------------------------------------------------------
/notes/operators/modulusOperator.java:
--------------------------------------------------------------------------------
1 | class Modulus{
2 | public static void main(String[] args){
3 | int x = 42;
4 | double y = 42.25;
5 |
6 | System.out.println("X mod 10 = "+x%10);
7 | System.out.println("Y mod 10 = "+y%10);
8 | }
9 | }
--------------------------------------------------------------------------------
/notes/swing/COMPONENTS.md:
--------------------------------------------------------------------------------
1 | # Class Name For Swing Components
2 |
3 | 1. ```JApplet```
4 | 2. ```JColorChooser```
5 | 3. ```JDialog```
6 | 4. ```JFrame```
7 | 5. ```JLayeredPane```
8 | 6. ```JButton```
9 | 7. ```JComboBox```
10 | 8. ```JEditorPane```
11 | 9. ```JInternalFrame```
12 | 10. ```JList```
13 | 11. ```JCheckBox```
14 | 13. ```JFileChooser```
15 | 14. ```JLable```
16 | 15. ```JMenu```
17 | 16. ```JCheckBoxMenuItem```
18 | 17. ```JDesktopPanel```
19 | 18. ```JFormattedTextField```
20 | 19. ```Jlayer```
21 | 20. ```JMenuBar```
--------------------------------------------------------------------------------
/notes/swing/DIFFERENCES.md:
--------------------------------------------------------------------------------
1 | # Differences Between AWT & Swing
2 |
3 | |SN| AWT | Swing |
4 | |--|-----|-------|
5 | |1.| Stands for Abstract Window Toolkit | Also known as JFC (Java Foundation Class) |
6 | |2.| AWT components are called heavyweight components. | Swings are called light weight component because swing components sits on the top of AWT components and do the work. |
7 | |3.| Require ```java.awt``` package | require ```javax.swing``` package |
8 | |4.| AWT components are platform dependent.| Swing components are made in purely java and they are platform independent. |
9 | | 5. | Less Component | More component and rich functionality. |
10 | | 6. | Pseudo Code here | Pseudo Code here |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/notes/swing/HIERARCHY.md:
--------------------------------------------------------------------------------
1 | # Hierarchy of Swing Components
2 |
3 | 
--------------------------------------------------------------------------------
/notes/swing/JFrame/JFrameDemo.java:
--------------------------------------------------------------------------------
1 | import javax.swing.*;
2 |
3 | class JFrameDemo extends JFrame {
4 | JFrameDemo(String title){
5 | super(title);
6 | setSize(300,300);
7 | setVisible(true);
8 | setLayout(new FlowLayout());
9 |
10 | JLabel label = new JLabel ("This is label");
11 | JButton button = new JButton("Click here");
12 | add(label);
13 | add(button);
14 | }
15 |
16 | public static void main(String[] args) {
17 | new JFrameDemo("JFrame Demo");
18 | }
19 | }
--------------------------------------------------------------------------------
/notes/swing/JFrame/JFrameDemoByAssociation.java:
--------------------------------------------------------------------------------
1 | import javax.swing.*;
2 | import java.awt.event.*;
3 | import javax.swing.event.*;
4 | import java.awt.*;
5 |
6 | class JFrameDemoByAssociation {
7 | JFrame j;
8 |
9 | JFrameDemoByAssociation() {
10 | j = new JFrame();
11 |
12 | j.setSize(300, 300);
13 | j.setVisible(true);
14 | j.setLayout(new FlowLayout());
15 |
16 | JLabel label = new JLabel("This is label");
17 | j.add(label);
18 |
19 | j.addWindowListener(new WindowAdapter(){
20 | public void windowClosing(WindowEvent we) {
21 | System.exit(0);
22 | }
23 | });
24 | }
25 |
26 | public static void main(String[] args) {
27 | new JFrameDemoByAssociation();
28 | }
29 | }
--------------------------------------------------------------------------------
/notes/swing/JOptionPane/JOptionPane.java:
--------------------------------------------------------------------------------
1 | import javax.swing.JOptionPane;
2 |
3 | class Sum{
4 | public static void main(String[] args){
5 | // showInputDialog is method to input the string data,
6 | // thus it is converted into Integer.
7 | int firstNo = Integer.parseInt(JOptionPane.showInputDialog("Enter first number :"));
8 | int secondNo = Integer.parseInt(JOptionPane.showInputDialog("Enter second number :"));
9 | int sum = firstNo + secondNo;
10 | // Accepts 4 parameters; First -> where to position it, Second -> What to print,
11 | // Third -> Title Bar, Fourth -> Icon/Message to be placed.
12 | JOptionPane.showMessageDialog(null,"The sum is "+sum, "Arjun's Calculator", JOptionPane.PLAIN_MESSAGE);
13 | }
14 | }
--------------------------------------------------------------------------------
/notes/swing/JTextField/JTextFieldDemo.java:
--------------------------------------------------------------------------------
1 | import javax.swing.*;
2 | import java.awt.*;
3 |
4 | public class JTextFieldDemo extends JFrame {
5 |
6 | JTextField jOne;
7 |
8 | JTextFieldDemo(String title) {
9 | super(title);
10 |
11 | setSize(400, 400);
12 | setVisible(true);
13 | setLayout(new FlowLayout());
14 |
15 | jOne = new JTextField("This is default");
16 | add(jOne);
17 | }
18 |
19 | public static void main(String[] args) {
20 | new JTextFieldDemo("JTextField Demo ");
21 | }
22 | }
--------------------------------------------------------------------------------
/notes/swing/dialog/DialogDemo.java:
--------------------------------------------------------------------------------
1 | import javax.swing.JOptionPane;
2 |
3 | public class DialogDemo {
4 | DialogDemo () {
5 | JOptionPane.showMessageDialog(null, "Message Box", "This is sample message", JOptionPane.INFORMATION_MESSAGE);
6 | }
7 | public static void main(String[] args) {
8 | new DialogDemo();
9 | }
10 | }
--------------------------------------------------------------------------------
/notes/swing/general/HaveFun.java:
--------------------------------------------------------------------------------
1 | import java.awt.*;
2 | import javax.swing.*;
3 | import java.awt.event.*;
4 | import javax.swing.event.*;
5 |
6 | public class HaveFun extends JFrame{
7 | JButton button;
8 | JTextField text;
9 |
10 | public HaveFun(String title) {
11 | super(title);
12 |
13 | button = new JButton("Have Fun");
14 | text = new JTextField("Enter text here", 30);
15 |
16 | setSize(400,400);
17 | setVisible(true);
18 | setLayout(new FlowLayout());
19 |
20 | add(text);
21 | add(button);
22 |
23 | button.addActionListener(new ActionListener(){
24 | public void actionPerformed(ActionEvent ae){
25 | text.setText(text.getText().toUpperCase());
26 | text.setBackground(Color.RED);
27 | text.setForeground(Color.WHITE);
28 | }
29 | });
30 | }
31 |
32 | public static void main(String[] args) {
33 | new HaveFun("Have Fun ");
34 | }
35 | }
--------------------------------------------------------------------------------
/notes/swing/multiCasting/MULTICASTING.md:
--------------------------------------------------------------------------------
1 | # Multicasting
2 |
3 | - Several event sources can react to the same event listener and vice versa.
4 | - AWT event sources support a multicast model for listeners.
5 | - This means that the same event can be sent to more than one listener object.
6 |
--------------------------------------------------------------------------------
/notes/variables/classAssignment/Person.java:
--------------------------------------------------------------------------------
1 | class Person{
2 | static int countNo;
3 |
4 | void enterRoom(){
5 | countNo++;
6 | }
7 |
8 | int count(){
9 | return countNo;
10 | }
11 | }
--------------------------------------------------------------------------------
/notes/variables/classAssignment/PersonDemo.java:
--------------------------------------------------------------------------------
1 | class PersonDemo{
2 | public static void main(String[] args){
3 | Person personObjectOne = new Person();
4 | Person personObjectTwo = new Person();
5 |
6 | personObjectOne.enterRoom();
7 | personObjectOne.enterRoom();
8 |
9 | personObjectTwo.enterRoom();
10 | personObjectTwo.enterRoom();
11 |
12 | // System.out.println("Total count = "+personObjectOne.countNo);
13 | System.out.println("Total count = "+Person.countNo); // This method is preferred though.
14 | }
15 | }
--------------------------------------------------------------------------------
/notes/variables/dynamicInitializationOfVariables.java:
--------------------------------------------------------------------------------
1 | class DynamicInitialization{
2 | public static void main(Static args[]){
3 | double a = 3.0,b=4.0;
4 |
5 | // c is dynamically initialized. It means that it is initialized at the run time.
6 |
7 | double c = Math.sqrt(a*a+b*b);
8 | System.out.println("Hypotenuse is : "+c);
9 |
10 | }
11 | }
--------------------------------------------------------------------------------
/notes/variables/lifeTImeOfVariable.java:
--------------------------------------------------------------------------------
1 | class LifeTime{
2 | public static void main(String args[]){
3 | int x;
4 |
5 | for(x=0;x<3;x++){
6 | int y=100; /* Y is initialized every time the loop runs. */
7 | System.out.println("Value of Y is :"+y);
8 | y=-1;
9 | {
10 | /* I created a new scope here to show a compile-time error. */
11 | int y;
12 | }
13 | System.out.println("Value of Y now is :"+y);
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/notes/variables/scopeOfVariables.java:
--------------------------------------------------------------------------------
1 | class Scope{
2 | public static void main(String args[]){
3 | int x;
4 | x=10;
5 | if(x==10){
6 | int y = 20;
7 | System.out.println("The value of x : "+x+" and y : "+y);
8 | x=y*2;
9 |
10 | }
11 | // y=30; // Y is not known here.
12 |
13 | /* X is still here. */
14 | System.out.println("Value of x: "+x);
15 | }
16 | }
--------------------------------------------------------------------------------
/notes/variables/scopeOfVariablesOne.java:
--------------------------------------------------------------------------------
1 | class Scope{
2 | public static void main(String[] args){
3 | if(true){
4 | int i ; // For local variable, JVM won't provide default value sp we must provide value explicitly before using it.
5 | System.out.println(i); // error: variable i might not have been initialized
6 | }else{
7 | // System.out.println(i); //error: cannot find symbol
8 | System.out.println("Hello Eveyone");
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/notes/variables/typeconversion.java:
--------------------------------------------------------------------------------
1 | class TypeConversion{
2 | public static void main(String args[]){
3 | int x;
4 | short z=30;
5 | double y=20.5;
6 | /* This is how implicit type conversion takes place. */
7 | x=z;
8 | System.out.println("Value of float Z : "+z+" is converted to int X : "+x);
9 |
10 | /* This is how explicit type conversion takes place. */
11 | x=(short) y;
12 | System.out.println("Value of float Y : "+y+" is converted to int X : "+x);
13 |
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | mkdocs==1.1.2
2 | mkdocs-macros-plugin==0.5.5
3 | mkdocs-material==7.1.0
4 | mkdocs-material-extensions==1.0.1
5 | pymdown-extensions==8.1.1
6 |
--------------------------------------------------------------------------------