Skip to content

Instantly share code, notes, and snippets.

View theArjun's full-sized avatar

Arjun Adhikari theArjun

View GitHub Profile
@theArjun
theArjun / Test.java
Created February 13, 2019 11:18
Implementation of SELECT Query using JDBC
package com.gces.jdbc;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Test {
@theArjun
theArjun / AUDIO.md
Last active January 28, 2019 17:17
Playing Audio in Applet

Playing Audio in Applet

28th January 2019 , 🖋 Arjun Adhikari

An applet can play an audio file represented by the AudioClip interface in the java.applet package. The AudioClip interface has three methods, including :
public void play() − Plays the audio clip one time, from the beginning.
public void loop() − Causes the audio clip to replay continually.
public void stop() − Stops playing the audio clip.
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.

@theArjun
theArjun / ABOUT.md
Last active February 20, 2019 12:41
Nepali Flag using AWT Graphics in Applet

Nepali Flag

26th January 2019, Arjun Adhikari

This program is written on Java using AWT grapics in Applet. It mayn't resemble with the actual Nepali Flag and I'm sorry for this. I truly respect the effort of artists to develop this flag and I feel honored to be the citizen of this country NEPAL.

Output

Nepali Flag

@theArjun
theArjun / PassingParameterToAppletUsingAppletViewer.java
Last active January 24, 2019 16:25
Passing Parameter to Applet using AppletViewer
import java.applet.*;
import java.awt.*;
// Following HTML chunk will pass parameter to Applet. This is comment for Java Compiler but not for appletviewer, so altering the attribute of parameter never compell to recompile again.
/*/
<applet code = "ParamDemo" height = "500" width = "500">
<param name = "fontName" value = "Comic Sans MS">
<param name = "fontSize" value = "40">
<param name = "leadingfontName" value = "14.80">
@theArjun
theArjun / HelloApplet.html
Created January 23, 2019 16:18
Applet Implementation in Java
<html>
<head>
<title>Applet Demonstration</title>
</head>
<body>
<applet code="HelloApplet.class" height="400" width="400"></applet>
</body>
@theArjun
theArjun / MergeTextFiles.java
Created January 18, 2019 11:29
Merges all Text Files into one Text File from given Path
import java.io.*;
class MergeTextFiles {
public static void main(String[] args) throws IOException {
BufferedReader br; // Declaring a variable of BufferedReader data type so that it can be used inside loop to read every .txt files listed there.
String path = "C:/users/arjun/Desktop/"; // This is pre-specified path, you can change it.
PrintWriter pw = new PrintWriter(path + "mergedText.txt");
String line; // This will get the lines on text files.
String location;
File[] filesFromPath = (new File(path)).listFiles();
@theArjun
theArjun / Alternatively.java
Created January 18, 2019 10:32
Merge Two Text Files Sequentially and Alternatively
// This merges the two text files named "abc.txt" and "xyz.txt" alternatively.
// This question was asked later in Java Class 18 January, 2019.
import java.io.*;
class MergeFiles{
public static void main(String[] args)throws IOException{
try{
PrintWriter pw = new PrintWriter(new File("finalText.txt"));
BufferedReader brOne = new BufferedReader(new FileReader("abc.txt"));
@theArjun
theArjun / Triangle.java
Last active January 18, 2019 08:06
Prints Triangle using Java
class Five{
public static void main(String[] args){
for(int i = 1; i <= 4; i++){ // First we are running loop from 1 to 4.
for(int j = 0; j < i; j++){ // Then we are running loop from 0 until i.
System.out.print((j+i)%2+" "); // Sum of i and j modulus of 2 equals the alternate of 1 and 0.
}
System.out.println();
}
}
}
@theArjun
theArjun / OwnException.java
Created January 16, 2019 12:59
Creating your own Exception in Java
// Create your own Exception.
class MyException extends Exception { // Inherits the partially unchecked exception class Exception.
MyException(String msg) { // Parameterized constructor for MyException.
super(msg); // Calls the constructor of Exception class; super class.
}
}
class ExceptionDemo {
static void isValid(int age) throws MyException { // Denotes this code may contain Exception; declaring exception here.
@theArjun
theArjun / Override.java
Created January 16, 2019 12:51
Can static and private function be overrided ?
// Can static and private function be overrided ?
class Animal {
static void eat() {
System.out.println("Eating.");
}
private void move() {
System.out.println("Moving.");
}