Learning Steps

Do We Always require a Main method in java

No, not exactly. Main method does gives an entry point for our program to run, but we can still have a Java program without a main method. Say for example, Java Servlet and Web Application file does not have main method. It operates based on request-response and different doXXX()(doget(), doPost() , etc) Http abstract methods. We can also make use of static initalization block as follows.

public class JavaAppWithoutMain {
static {
	 System.out.println("Hello World\n");
	 System.exit(0);
} 
}

NOTE: This compiles fine, but gives the following when executed.

C:\Program Files\Java\jdk1.8.0_121\bin>java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
C:\Program Files\Java\jdk1.8.0_121\bin>javac C:\Users\SouravG\Desktop\JavaAppWithoutMain.java
C:\Program Files\Java\jdk1.8.0_121\bin>java C:\Users\SouravG\Desktop\JavaAppWithoutMain
Error: Could not find or load main class C:\Users\SouravG\Desktop\JavaAppWithoutMain
C:\Program Files\Java\jdk1.8.0_121\bin>

 

 

java programs ...
______________________________________________________________________
import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 boolean check = false;
 do{
 System.out.println("Enter seconds");
 int i = input.nextInt();
 if(i>100000 || i<0){
 System.out.println(" Wrong Input, try again");
 }
 else{
 check = true;
 System.out.println("minutes entered " + i);
 int minutes = i/60;
 int hours = minutes/60;
 int day = hours/24;
 int year = day/12;
 int onlySeconds = i%60;
 int onlyMinutes = minutes%60;
 int onlyHours = hours%60;
 int onlyDay = day/24;
 int onlyYear = year/365;

System.out.println("year : "+onlyYear
 + "\nday : "+onlyDay
 +"\nhours : " + onlyHours
 + "\nminutes " +onlyMinutes
 + "\nseconds " + onlySeconds);

}
 }while(check == false);
 }
}

________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);

boolean check = false;
 do{
 System.out.println("Enter");
 int i = input.nextInt();
 check = false;
 if(i>7 || i<0){
 System.out.println("if you are confused type quit else anything else");
 String a = input.nextLine();
 if(a.equalsIgnoreCase("quit")){
 check = true;
 }
 else{
 check = false;
 }
 }
 else{
 switch (i){
 case 1:
 System.out.println("Sunday");
 break;
 case 2:
 System.out.println("Monday");
 break;
 case 3:
 System.out.println("Tuesday");
 break;
 case 4:
 System.out.println("Wednesday");
 break;
 case 5:
 System.out.println("Thursday");
 break;
 case 6:
 System.out.println("Friday");
 break;
 case 7:
 System.out.println("Saturday");
 break;
 }
 }
 }while(check!=true);
 }
}
________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);

double a,b;
 a = input.nextDouble();
 b = input.nextDouble();

a = a *1000;
 b = b *1000;

int x = (int)(a);
 int y = (int)(b);

if(x == y){
 System.out.println("yes, same upto 3 digits after decimal");
 }
 else{
 System.out.println("No, atleast not simmilar upto 3 decimal placrs");
 }
 }
}

________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 int sum = 0;
 Scanner input = new Scanner(System.in);

System.out.println("Enter valiue of n");
 int n = input.nextInt();
 boolean quit =false;
 if(n>9999 || n<0){
 System.out.println("Value not permitted, Retry or Quit");
 String enter =input.nextLine();
 if(enter.equalsIgnoreCase("quit")){
 quit = true;
 }
 else{
 quit = false;
 }
 }
 else {
 sum = SumN(n);
 }
 System.out.println("Sum = " + sum);
 }

public static int SumN(int n){
 if(n==1){
 return 1;
 }
 else{
 return (n+ SumN(n-1));
 }
 }
}

________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 int sum = 0;
 Scanner input = new Scanner(System.in);

System.out.println("Enter Year");
 int year = input.nextInt();
 System.out.println("Enter Month Number");
 int monthNumber = input.nextInt();

findYear(year,monthNumber);
 }
 public static void findYear(int year, int month){
 boolean leapYear =false;
 if(year%400 == 0 ||year%100 == 0 || year%4==0){
 System.out.println(year + " is a leap year");
 leapYear =true;
 }
 findMonth(month,leapYear);
 }
 public static void findMonth(int month,boolean leapYear){
 switch (month){
 case 1:
 System.out.println("Month Name : January");
 System.out.println("Numer of days : 31");
 break;
 case 2:
 System.out.println("Month Name : February");
 if(leapYear == true){
 System.out.println("Number of days : 29");
 }else{
 System.out.println("Number of days : 28");
 }
 break;
 case 3:
 System.out.println("Month Name : March");
 System.out.println("Numer of days : 31");
 break;
 case 4:
 System.out.println("Month Name : April");
 System.out.println("Numer of days : 30");
 break;
 case 5:
 System.out.println("Month Name : May");
 System.out.println("Numer of days : 31");
 break;
 case 6:
 System.out.println("Month Name : June");
 System.out.println("Numer of days : 30");
 break;
 case 7:
 System.out.println("Month Name : July");
 System.out.println("Numer of days : 31");
 break;
 case 8:
 System.out.println("Month Name : August");
 System.out.println("Numer of days : 31");
 break;
 case 9:
 System.out.println("Month Name : September");
 System.out.println("Numer of days : 30");
 break;
 case 10:
 System.out.println("Month Name : October");
 System.out.println("Numer of days : 31");
 break;
 case 11:
 System.out.println("Month Name : November");
 System.out.println("Numer of days : 30");
 break;
 case 12:
 System.out.println("Month Name : December");
 System.out.println("Numer of days : 31");
 break;
 }
 }
}
________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 int sum = 0;
 System.out.println("Enter the number");
 Scanner input = new Scanner(System.in);

int num = input.nextInt();

cube(num);
 }

public static void cube(int num){
 int count = 1;
 for(count =1;count <=num;count++){
 System.out.println("Cube of "+ count +" is " + (int)Math.pow(count,3));
 }
 }
}
________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 int sum = 0;
 System.out.println("Enter the number");
 Scanner input = new Scanner(System.in);
 int num = input.nextInt();

for (int i =1;i<=num;i++){
 for (int j=1; j<i+1; j++){
 System.out.print(j + " ");
 }
 System.out.println("");
 }
 }
}
________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 int sum = 0;
 System.out.println("Enter the number");
 Scanner input = new Scanner(System.in);
 int num = input.nextInt();

for (int i =1;i<=num;i++){
 for (int j=1; j<i+1; j++){
 System.out.print(i + " ");
 }
 System.out.println("");
 }
 }
}

________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 int sum = 0, k=1;
 System.out.println("Enter the number");
 Scanner input = new Scanner(System.in);
 int num = input.nextInt();

for (int i =1;i<=num;i++){
 for (int j=1; j<i; j++){
 System.out.print(k++ +" " );
 }
 System.out.println("");
 }
 }
}

________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args) {
 int sum = 0;
 System.out.println("Enter the number");
 Scanner input = new Scanner(System.in);
 int i,j,r;
 r = input.nextInt();

for(i=0;i<=r;i++)
 {
 for(j=1;j<=r-i;j++)
 System.out.print(" ");
 for(j=1;j<=2*i-1;j++)
 System.out.print("*");
 System.out.print("\n");
 }

for(i=r-1;i>=1;i--)
 {
 for(j=1;j<=r-i;j++)
 System.out.print(" ");
 for(j=1;j<=2*i-1;j++)
 System.out.print("*");
 System.out.print("\n");
 }
 }
}

________________________________________
import java.util.Scanner;
import java.util.Arrays;
public class JavaLearn {

public static void main(String[] args) {
 int[] intArr = {21,22,1,222,3,11};
 int i;
 int n = 6;
 for(int j=0;j<n;j++){
 for(i=0;i<n;i++){
 int temp = 0;
 if(intArr[i + 1] > intArr[i]){
 intArr[i]=intArr[i];
 intArr[i+1]=intArr[i+1];
 }
 else{
 temp = intArr[i];
 intArr[i] = intArr[i+1];
 intArr[i+1]=temp;
 }
 }
 }
 System.out.println(intArr.toString());
 }
}
________________________________________
import java.util.Scanner;
import java.util.Arrays;
public class JavaLearn {

public static void main(String[] args) {
 int[] intArr = {2,4,12,8,2};
 int sum =0;
 for(int i=0;i<intArr.length;i++){
 sum += intArr[i];
 }

System.out.println("Sum : "+sum);
 }
}

________________________________________

import java.util.Scanner;
import java.util.Arrays;
public class JavaLearn {

public static void main(String[] args) {
 int[] intArr = new int[5];
 Scanner input = new Scanner(System.in);
 for(int x=0;x<intArr.length;x++){
 intArr[x] = input.nextInt();
 }

System.out.println("Enter Number to search");
 int num = input.nextInt();
 int[] contains = new int[2];
 contains = findNum(num,intArr);

if(contains[0] == 1){
 System.out.println("Yes "+ num + " is present in the list");
 System.out.println(num + " is present at position " + contains[1]+1);
 }
 else{
 System.out.println(" No " +num+ " its not present in the list");
 }

}

public static int[] findNum(int n,int[] arr){
 int[] find = new int[2];
 find[0] = -1;
 find[1] = -1;
 for(int x=0;x<arr.length;x++){
 if(n==arr[x]){
 find[0] = 1;
 find[1] = x;
 }
 }
 return find;
 }
}

________________________________________

import com.sun.deploy.util.ArrayUtil;

import java.util.Scanner;
import java.util.Arrays;
public class JavaLearn {

public static void main(String[] args) {
 int[] intArr = {212,34,5,6,67,8889,954,437,954,112,412};
 Scanner input = new Scanner(System.in);

System.out.println("Array before BubbleSort");
 printArr(intArr);

System.out.println("Array after bubbleSort");
 bubblesort(intArr);

}

static void printArr(int[] newArr){
 for (int x:newArr){
 System.out.print( " "+x);
 }
 System.out.println(" ");
 }

static void bubblesort(int[] newArr){

for (int j=0;j<newArr.length;j++){
 int temp;
 for(int x=0;x<newArr.length-1;x++){
 if(newArr[x+1] > newArr[x]){
 temp = newArr[x];
 newArr[x] = newArr[x+1];
 newArr[x+1] = temp;
 }
 else{
 newArr[x] = newArr[x];
 }
 }
 }

printArr(newArr);
 }
}

________________________________________

import com.sun.deploy.util.ArrayUtil;

import java.util.Scanner;
import java.util.Arrays;
public class JavaLearn {

public static void main(String[] args) {
 int[] intArr = {212,34,5,6,67,8889,954,437,954,112,412};
 Scanner input = new Scanner(System.in);

System.out.println("Array before BubbleSort");
 printArr(intArr);

System.out.println("Array after bubbleSort");
 bubblesort(intArr);

}

static void printArr(int[] newArr){
 for (int x:newArr){
 System.out.print( " "+x);
 }
 System.out.println(" ");
 }

static void bubblesort(int[] newArr){

for (int j=0;j<newArr.length;j++){
 int temp;
 for(int x=0;x<newArr.length-1;x++){
 if(newArr[x+1] > newArr[x]){
 temp = newArr[x];
 newArr[x] = newArr[x+1];
 newArr[x+1] = temp;
 }
 else{
 newArr[x] = newArr[x];
 }
 }
 }

printArr(newArr);
 }
}

________________________________________

import com.sun.deploy.util.ArrayUtil;

import java.util.Scanner;
import java.util.Arrays;
public class JavaLearn {

public static void main(String[] args) {
 int[] intArr = {12,43,65,24,64,24,677,95,11,12,677,88,64};
 Scanner input = new Scanner(System.in);

for(int x=0;x<intArr.length;x++){
 for (int y=1;y<intArr.length; y++){
 if (intArr[x] == intArr[y] && x != y){
 System.out.println(intArr[y] + " is present at position "+ (x+1));
 }
 }
 }
 }
}
________________________________________

import com.sun.deploy.util.ArrayUtil;

import java.util.Scanner;
import java.util.Arrays;
public class JavaLearn {

public static void main(String[] args) {
 int[] intArr1 = {12,43,65,24,64,24,677,95,11,12,677,88,64};
 int[] intArr2 = {1,3,6,4,64,4,67,5,11,2,6,8,4};
 Scanner input = new Scanner(System.in);

for(int x=0;x<intArr1.length;x++){
 for (int y=0;y<intArr2.length;y++){
 if (intArr1[x] == intArr2[y]){
 System.out.println(intArr1[x]);
 }
 }
 }

}
}
________________________________________

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class JavaLearn {
 public static void main(String[] args)
 {
 Scanner input = new Scanner(System.in);
 ArrayList<String> arrayList = new ArrayList<>();
 String inputData;
 String quit;
 boolean isQuit = false;
 do{
 System.out.println("Enter : ");
 isQuit =false;
 inputData = input.nextLine();

if(inputData.equalsIgnoreCase("quit")||inputData.equalsIgnoreCase("exit")){
 System.out.println(" Are you sure you want to quit ... yes/no: ");
 quit = input.nextLine();
 if (quit.equalsIgnoreCase("yes")||quit.equalsIgnoreCase("y")||quit.equalsIgnoreCase("")){
 isQuit =true;
 }
 else{
 arrayList.add(inputData);
 }
 }
 else{
 arrayList.add(inputData);
 }
 }while(isQuit!=true);

String[] arr = new String[arrayList.size()];

arrayList.toArray(arr);

System.out.println(" So this is your final list ");
 for (String p:arr){
 System.out.println(p);
 }
 }
}

________________________________________

import java.util.Scanner;
public class JavaLearn {
 public static void main(String[] args)
 {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter Word1 : ");
 String inputString1 = input.nextLine();
 System.out.println("Enter Word2 : ");
 String inputString2 = input.nextLine();

int stringCompare = inputString1.compareTo(inputString2);

if(stringCompare > 0) {
 System.out.println(inputString1+ "is Greater than "+inputString2);
 }
 else if(stringCompare == 0) {
 System.out.println(inputString1+ " is equal to "+inputString2);

}else{
 System.out.println(inputString1+ " is less than "+inputString2);
 }




}
}
________________________________________

import java.util.Scanner;
public class JavaLearn {
 public static void main(String[] args)
 {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter Word1 : ");
 String inputString1 = input.nextLine();
 System.out.println("Enter Word2 : ");
 String inputString2 = input.nextLine();

boolean isContain = false;

isContain = inputString1.contains(inputString2);

if (isContain==true){
 System.out.println("yes");
 }
 else{
 System.out.println("no");
 }

}
}
________________________________________

import java.util.Calendar;

public class JavaLearn {

public static void main(String[] args) {
 Calendar c = Calendar.getInstance();
 System.out.println("Current Date and Time :");
 System.out.format("%tB %te, %tY%n", c, c, c);
 System.out.format("%tl:%tM %tp%n", c, c, c);
 }
}

________________________________________

import java.util.Scanner;
public class JavaLearn {
 public static void main(String[] args)
 {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter String : ");
 String word = input.nextLine();
 int strLength = word.length();
 char[] charArr = new char[strLength];

for (int k=0;k<strLength;k++){
 charArr[k] = word.charAt(k);
 }

for (int k=0;k<strLength;k++){
 System.out.println((k+1) + " letter is " + charArr[k]);
 }
 }
}

________________________________________
import java.util.Scanner;
public class JavaLearn {
 public static void main(String[] args)
 {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter String : ");
 String word = input.nextLine();

int hashCode = word.hashCode();

System.out.println("hash code is "+hashCode);
 }
}
________________________________________

import java.util.Scanner;
public class JavaLearn {

public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 System.out.println(" Enter Word: ");
 String word = input.nextLine();

int countWords = 0;
 String[] c = word.split("\\s");

for (String p:c){
 System.out.println(p);

countWords++;
 }
 System.out.println("No. Of words : "+countWords);
 }
}

________________________________________

import java.util.Scanner;
public class JavaLearn {
 public static void main(String[] args)
 {
 Scanner input = new Scanner(System.in);
 boolean isSpecialChar =false;
 boolean isUpperChar = false;
 boolean isLowerChar = false;
 boolean isNumber = false;
 System.out.println("Enter String, Must contain 1 capital, 1 small, 1 special chararcter and 1 number : ");
 String password = input.nextLine();
 char[] charArr = new char[password.length()];
 int[] intArr = new int[password.length()];
 for(int x=0;x<password.length();x++){
 charArr[x] = password.charAt(x);
 intArr[x] = (int)charArr[x];
 }
 
 
 for(int x=0;x<intArr.length;x++){

if((intArr[x] >=33 && intArr[x] <=47) || (intArr[x] >=58 && intArr[x] <=64) || (intArr[x] >=91 && intArr[x] <=96)){
 isSpecialChar = true;
 }
 if(intArr[x] >=48 || intArr[x] <=57){
 isNumber =true;
 }
 if(intArr[x] >=65 || intArr[x] <=90){
 isUpperChar = true;
 }
 if(intArr[x] >=97 || intArr[x] <=122){
 isLowerChar = true;
 }
 }

if(isLowerChar == true && isUpperChar == true && isNumber == true && isSpecialChar == true){
 System.out.println(" Perfect, you have entered correctly");
 }
 else if(isLowerChar == false){
 System.out.println("Enter a lowercase");
 }
 }
}
________________________________________

import java.util.Scanner;
import java.util.Random;
public class JavaLearn {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 int n = input.nextInt();
 findMatrix(n);
 }
 static void findMatrix(int n){
 Random rand = new Random();

for(int y =0;y<n;y++){
 for(int x=0;x<n;x++){
 System.out.print( " " + rand.nextInt(2));
 }
 System.out.println("");
 }
 }
}
________________________________________

import java.util.Scanner;
import java.util.Random;
public class JavaLearn {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter Sentence");
 String sentence = input.nextLine();
 char[] vowels = {'a','e','i','o','u'};
 for(int x=0;x<vowels.length;x++){
 for (int y=0;y<sentence.length();y++){
 if(sentence.toLowerCase().charAt(y) == vowels[x]){
 System.out.println(vowels[x] +" is present at " + (y+1) + " position");
 }
 }
 }
 }
}

________________________________________

import java.util.Scanner;
import java.util.Random;
public class JavaLearn {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter Number");
 int num = input.nextInt();
 calculate(num);
 }
 private static void calculate(int n){
 int sum = 0;
 while(n>0){
 sum += n%10;
 n=n/10;
 }
 System.out.println("Sum = "+ sum);

}
}
________________________________________

import java.util.Scanner;
import java.util.Random;
public class JavaLearn {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter Number");
 int num = input.nextInt();
 uglyNum(num);
 }
 static void uglyNum(int n){
 if(n%2==0 || n%3==0 || n%5==0){
 System.out.println("Yes it is a an Ugly Number");
 }
 else{
 System.out.println("No");
 }
 }
}

________________________________________

//Java Exercises: Get list of all file/directory names

import java.io.File;
import java.util.Date;

public class JavaLearn {
 public static void main(String a[])
 {
 File file = new File("Coupy paste you path directory here");
 String[] fileList = file.list();
 for(String name:fileList){
 System.out.println(name);
 }
 }
} 
________________________________________

//Java Exercises: Get specific files by extensions from a specified folder

import java.io.File;
import java.io.FilenameFilter;
public class JavaLearn {
 public static void main(String a[]){
 File file = new File("D:\\MOVIES_SWANANAJAN_DA");
 String[] list = file.list(new FilenameFilter() {
 @Override
 public boolean accept(File dir, String name) {
 if(name.toLowerCase().endsWith(".mkv")){
 return true;
 } else {
 return false;
 }
 }
 });
 for(String f:list){
 System.out.println(f);
 }
 }
} 
________________________________________

//Java Exercises: Check if a file or directory specified by pathname exists or not

import java.io.File;
public class JavaLearn {
 public static void main(String[] args) {
 // Create a File object
 File my_file_dir = new File("D:\\Downloaded files transport\\12 Powerful VIRUS codes which you can make in NOTEPAD!.mp4");
 if (my_file_dir.exists())
 {
 System.out.println("The directory or file exists.\n");
 }
 else
 {
 System.out.println("The directory or file does not exist.\n");
 }
 }
}

________________________________________

//Java Exercises: Check if a file or directory has read and write permission

import java.io.File;
public class JavaLearn {
 public static void main(String[] args) {
 // Create a File object
 File my_file_dir = new File("D:\\Downloaded files transport\\15700764_617161611819536_566239361499136000_n.mp4");
 if (my_file_dir.canWrite())
 {
 System.out.println(my_file_dir.getAbsolutePath() + " can write.\n");
 }
 else
 {
 System.out.println(my_file_dir.getAbsolutePath() + " cannot write.\n");
 }
 if (my_file_dir.canRead())
 {
 System.out.println(my_file_dir.getAbsolutePath() + " can read.\n");
 }
 else
 {
 System.out.println(my_file_dir.getAbsolutePath() + " cannot read.\n");
 }
 }
}

________________________________________

//Java Exercises: Check if given pathname is a directory or a file

import java.io.File;
public class JavaLearn {
 public static void main(String[] args) {
 // Create a File object 
 File my_file_dir = new File("D:\\Downloaded files transport");
 if (my_file_dir.isDirectory())
 {
 System.out.println(my_file_dir.getAbsolutePath() + " is a directory.\n");
 }
 else
 {
 System.out.println(my_file_dir.getAbsolutePath() + " is not a directory.\n");
 }
 if (my_file_dir.isFile())
 {
 System.out.println(my_file_dir.getAbsolutePath() + " is a file.\n");
 }
 else
 {
 System.out.println(my_file_dir.getAbsolutePath() + " is a file.\n");
 }
 }
}

________________________________________

//Java Exercises: Check when was the file last modified

import java.io.File;
import java.util.Date;

public class JavaLearn {
 public static void main(String[] args) {
 File file = new File("D:\\Downloaded files transport\\18297897_413629645689739_4423533452628852736_n.mp4");
 Date date = new Date(file.lastModified());
 System.out.println("\nThe file was last modified on: " + date + "\n");
 }
}

________________________________________

//Java Exercises: Get file size in bytes, kb, mb

import java.io.File;

public class JavaLearn {

public static void main(String[] args)
 {
 File file = new File("D:\\Downloaded files transport\\16081546_1532799190083181_3857151657129279488_n.mp4");
 if(file.exists())
 {
 System.out.println(filesize_in_Bytes(file));
 System.out.println(filesize_in_kiloBytes(file));
 System.out.println(filesize_in_megaBytes(file));
 }
 else
 System.out.println("File doesn't exist");

}

private static String filesize_in_megaBytes(File file) {
 return (double) file.length()/(1024*1024)+" mb";
 }

private static String filesize_in_kiloBytes(File file) {
 return (double) file.length()/1024+" kb";
 }

private static String filesize_in_Bytes(File file) {
 return file.length()+" bytes";
 }
}

________________________________________

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

// Reading contents from a file into byte array. 
public class JavaLearn {
 public static void main(String a[]){
 String file_name = "D:\\Downloaded files transport\\credentials.csv";
 InputStream fins = null;
 try {
 fins = new FileInputStream(file_name);
 byte file_content[] = new byte[2*1024];
 int read_count = 0;
 while((read_count = fins.read(file_content)) > 0){
 System.out.println(new String(file_content, 0, read_count-1));
 }
 } catch (FileNotFoundException e) {
 e.printStackTrace();
 } catch (IOException e) {
 e.printStackTrace();
 } finally {
 try{
 if(fins != null) fins.close();
 } catch(Exception ex){

}
 }
 }
}

________________________________________

//Java Exercises: Read a file content line by line

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class JavaLearn {

public static void main(String a[]){
 BufferedReader br = null;
 String strLine = "";
 try {
 br = new BufferedReader( new FileReader("D:\\Downloaded files transport\\transactions.txt"));
 while( (strLine = br.readLine()) != null){
 System.out.println(strLine);
 }
 br.close();
 } catch (FileNotFoundException e) {
 System.err.println("File not found");
 } catch (IOException e) {
 System.err.println("Unable to read the file.");
 }
 }
}
________________________________________

//Java Exercises: Read a plain text file

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.FileReader;

public class JavaLearn {

public static void main(String a[]){
 StringBuilder sb = new StringBuilder();
 String strLine = "";
 try {
 BufferedReader br = new BufferedReader(new FileReader("D:\\Downloaded files transport\\transactions.txt"));
 while (strLine != null)
 {
 sb.append(strLine);
 sb.append(System.lineSeparator());
 strLine = br.readLine();
 System.out.println(strLine);
 }
 br.close();
 } catch (FileNotFoundException e) {
 System.err.println("File not found");
 } catch (IOException e) {
 System.err.println("Unable to read the file.");
 }
 }
}

________________________________________

//Java Exercises: Read a file line by line and store it into a variable

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileReader;

public class JavaLearn {

public static void main(String a[]){
 StringBuilder sb = new StringBuilder();
 String strLine = "";
 String str_data = "";
 try {
 BufferedReader br = new BufferedReader(new FileReader("D:\\Downloaded files transport\\transactions.txt"));
 while (strLine != null)
 {
 if (strLine == null)
 break;
 str_data += strLine;
 strLine = br.readLine();
 }
 System.out.println(str_data);
 br.close();
 } catch (FileNotFoundException e) {
 System.err.println("File not found");
 } catch (IOException e) {
 System.err.println("Unable to read the file.");
 }
 }
}

________________________________________

//Java Exercises: Write and read a plain text file

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;

public class JavaLearn {
 public static void main(String a[]){
 StringBuilder sb = new StringBuilder();
 String strLine = "";
 try
 {
 String filename= "D:\\Downloaded files transport\\transactions.txt";
 FileWriter fw = new FileWriter(filename,false);
 //appends the string to the file
 fw.write("Python Exercises\n");
 fw.close();
 BufferedReader br = new BufferedReader(new FileReader("D:\\Downloaded files transport\\transactions.txt"));
 //read the file content
 while (strLine != null)
 {
 sb.append(strLine);
 sb.append(System.lineSeparator());
 strLine = br.readLine();
 System.out.println(strLine);
 }
 br.close();
 }
 catch(IOException ioe)
 {
 System.err.println("IOException: " + ioe.getMessage());
 }
 }
}

________________________________________

//Java Exercises: Read first 3 lines from a file

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.LineNumberReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileInputStream;

public class JavaLearn {

public static void main(String a[]){
 BufferedReader br = null;
 String strLine = "";
 try {
 LineNumberReader reader = new LineNumberReader(new InputStreamReader(new FileInputStream("D:\\Downloaded files transport\\transactions.txt"), "UTF-8"));
 while (((strLine = reader.readLine()) != null) && reader.getLineNumber() <= 3){
 System.out.println(strLine);
 }
 reader.close();
 } catch (FileNotFoundException e) {
 System.err.println("File not found");
 } catch (IOException e) {
 System.err.println("Unable to read the file.");
 }
 }
}

________________________________________

//Java Exercises: Append text to an existing file

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.FileWriter;

public class JavaLearn {
 public static void main(String a[]){
 StringBuilder sb = new StringBuilder();
 String strLine = "";
 try
 {
 String filename= "D:\\Downloaded files transport\\transactions.txt";
 FileWriter fw = new FileWriter(filename,true);
 //appends the string to the file

fw.write("\nJava Exercises point 1\n");
 fw.write("Java Exercises point 2\n");
 fw.close();
 BufferedReader br = new BufferedReader(new FileReader("D:\\Downloaded files transport\\transactions.txt"));
 //read the file content
 while (strLine != null)
 {
 sb.append(strLine);
 sb.append(System.lineSeparator());
 strLine = br.readLine();
 System.out.println(strLine);
 }
 br.close();
 }
 catch(IOException ioe)
 {
 System.err.println("IOException: " + ioe.getMessage());
 }
 }
}

________________________________________

//Java Exercises: Find the longest word in a text file

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;

public class JavaLearn {
 public static void main(String [ ] args) throws FileNotFoundException {
 new JavaLearn().findLongestWords();
 }

public String findLongestWords() throws FileNotFoundException {

String longest_word = "";
 String current;
 Scanner sc = new Scanner(new File("D:\\Downloaded files transport\\transactions.txt"));




while (sc.hasNext()) {
 current = sc.next();
 if (current.length() > longest_word.length()) {
 longest_word = current;
 }

}
 System.out.println("\n"+longest_word+"\n");
 return longest_word;
 }
}

________________________________________

import java.util.Scanner;
import java.util.ArrayList;

public class JavaLearn{
 public static void main(String[] args) {
 ArrayList<String> colors = new ArrayList<>();
 Scanner input = new Scanner(System.in);
 String colorName = null;
 do{
 colorName = input.nextLine();
 if(!colorName.equalsIgnoreCase("quit")){
 colors.add(colorName);
 }

}while(!colorName.equalsIgnoreCase("quit") );
 System.out.println(colors);
 }
}

________________________________________
import java.util.Scanner;
import java.util.LinkedList;
public class javaFX {
 public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 LinkedList<String> list = new LinkedList<String>();
 list.add("Hello1");
 list.add("Hello2");
 list.add("Hello3");
 list.add("Hello4");
 list.add("Hello5");
 list.add("Hello6");

System.out.println(list);
 System.out.println("Where you want to remove");
 int replace = input.nextByte();

list.set(replace - 1,"NewHello");

System.out.println(list);




}
 }

______________________________________________________________________
//for Radio Button tutorial

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class RadioGUI extends JFrame {
 private JTextField tf;
 private Font[] font = new Font[4] ;
 private JRadioButton[] rb = new JRadioButton[4];
 private ButtonGroup group;
 /*font[0] = pf;
 font[1] = bf;
 font[2] = itf;
 font[3] = bif;
 rb[0] = pb;
 pb[1] = bb;
 pb[2] = ib;
 pb[3] = bib;*/
 
 public RadioGUI(){
 super("The title");
 setLayout(new FlowLayout());
 
 tf=new JTextField("Hello World!!!", 25);
 add(tf);
 System.out.println("\n");
 
 rb[0] = new JRadioButton("PLAIN", true);
 rb[1] = new JRadioButton("BOLD", false);
 rb[2] = new JRadioButton("ITALICS", false);
 rb[3] = new JRadioButton("BOLD n ITALICS", false);
 group = new ButtonGroup();
 for(JRadioButton x: rb){
 add(x);
 group.add(x);
 }
 font[0] = new Font("Serif",Font.PLAIN,14);
 font[1] = new Font("Serif",Font.BOLD,14);
 font[2] = new Font("Serif",Font.ITALIC,14);
 font[3] = new Font("Serif",Font.BOLD + Font.ITALIC,14);
 
 tf.setFont(font[0]);
 
 rb[0].addItemListener(new HandlerClass(font[0]));
 rb[1].addItemListener(new HandlerClass(font[1]));
 rb[2].addItemListener(new HandlerClass(font[2]));
 rb[3].addItemListener(new HandlerClass(font[3]));
 
 /*for(int i = 0 ; i<=4; i++){
 rb[i].addActionListener(new handler(Font[i]));
 }*/ 
 } 
 private class HandlerClass implements ItemListener{
 private Font font;
 // the font item get 
 public HandlerClass(Font f){
 font = f;
 }
 public void itemStateChanged(ItemEvent event){
 tf.setFont(font);
 }
 }
}
______________________________________________________________________

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class MulSelectGUI extends JFrame {
 
 private JList leftlist;
 private JList rightlist;
 private JButton movebutton;
 private static String[] foods = {"red","blue","green","yellow","magenta","purple","pink","black","white","gre","maroon","orange"};
 
 public MulSelectGUI(){
 super("The Title is here");
 setLayout(new FlowLayout());
 leftlist = new JList(foods);
 leftlist.setVisibleRowCount(7);
 leftlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 add(new JScrollPane(leftlist));
 
 movebutton = new JButton("MOVE -->");
 movebutton.addActionListener(
 new ActionListener(){
 @SuppressWarnings("deprecation")
 public void actionPerformed(ActionEvent event){
 rightlist.setListData(leftlist.getSelectedValues());
 }
 }
 );
 add(movebutton);
 
 rightlist = new JList();
 rightlist.setVisibleRowCount(7);
 rightlist.setFixedCellWidth(100);
 rightlist.setFixedCellHeight(15);
 rightlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
 
 add(new JScrollPane(rightlist));
 
 }

}
______________________________________________________________________

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MouseEvGUI extends JFrame{
 private JPanel mousepanel;
 private JLabel statusbar;
 
 public MouseEvGUI(){
 super("this is the Title");
 
 mousepanel = new JPanel();
 mousepanel.setBackground(Color.WHITE);
 add(mousepanel,BorderLayout.CENTER);
 
 statusbar = new JLabel("Yet not Entered the Area even once");
 add(statusbar,BorderLayout.SOUTH);
 
 HandlerClass handler = new HandlerClass();
 mousepanel.addMouseListener(handler);
 mousepanel.addMouseMotionListener(handler);
 
 }
 
 private class HandlerClass implements MouseListener, MouseMotionListener{
 public void mouseClicked(MouseEvent event){
 statusbar.setText(String.format("Clicked at %d, %d", event.getX(),event.getY()));
 }
 public void mousePressed(MouseEvent event){
 statusbar.setText("You pressed down the mouse");
 }
 public void mouseReleased(MouseEvent event){
 statusbar.setText("You released the mouse");
 }
 public void mouseEntered(MouseEvent event){
 statusbar.setText("You entered the area");
 mousepanel.setBackground(Color.RED);
 }
 public void mouseExited(MouseEvent event){
 statusbar.setText("You exited the area");
 mousepanel.setBackground(Color.WHITE);
 }
 
 //these are mouse motion events
 public void mouseDragged(MouseEvent event){
 statusbar.setText("You are dragging the mouse");
 }
 public void mouseMoved(MouseEvent event){
 statusbar.setText("You moved the mouse");
 }
 
 
 }
}
______________________________________________________________________

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;




public class AdapterGUI extends JFrame{
 private String details;
 private JLabel statusbar;
 
 public AdapterGUI(){
 super("The Title");
 statusbar = new JLabel("This is a default : ");
 add(statusbar,BorderLayout.SOUTH);
 addMouseListener(new Mouseclass());
 }
 
 private class Mouseclass extends MouseAdapter{
 public void mouseClicked(MouseEvent event){
 details = String.format("You Clicked %d number of times", event.getClickCount());
 
 if(event.isMetaDown()){
 details += " you are using RIGHT click";
 }
 else if(event.isAltDown()){
 details += " you are scrolling";
 }
 else{
 details += " you are using LEFT clkick";
 }
 statusbar.setText(details);
 }
 }
}
______________________________________________________________________

import java.io.File;
import java.util.*;




public class FILE_learn {
 
 // this checks if the file exists or not
 /* File x = new File("E:\\from Saurav HomeLaptop\\tutorials\\tutorials new\\CCNA ICND1 100-105\\hello.*");
 if(x.exists()){
 System.out.println("the file exists");
 }
 else{
 System.out.println("NO");
 }*/
 
 // this creates a file
 /*final Formatter x;
 try{
 x = new Formatter("fred.txt");
 System.out.println("you created a file");
 }
 catch(Exception e){
 System.out.println("You got an error");
 }*/
 
 
 // for writing text to a file
 /*private Formatter x;
 public void openFile(){
 try{
 x = new Formatter("german.txt");
 }
 catch(Exception e){
 System.out.println("you have an error");
 }
 
 }
 public void addRecords(){
 x.format("%s , %s , %s ", "20 ", "saurav ", "gupta ");
 }
 public void closeFile(){
 x.close();
 }*/
 
 private Scanner x;
 public void openFile(){
 try{
 x = new Scanner(new File("german.txt"));
 }
 catch(Exception e){
 System.out.println("could not find file");
 }
 }
 public void readFile(){
 while(x.hasNext()){
 String a = x.next();
 
 System.out.printf("%s",a);
 System.out.println("");
 }
 }
 public void closeFile(){
 x.close();
 }
 
 }

______________________________________________________________________

import java.util.Scanner;
public class ExceptionBlock {
 public void calculate(){
 int i=1;
 do{
 try{
 Scanner input = new Scanner(System.in);
 System.out.println("Enter First num:");
 int n1 = input.nextInt();
 System.out.println("Enter Second num:");
 int n2 = input.nextInt();
 int divide = n1/n2;
 System.out.println("result = " + divide);
 i++;
 }
 catch(Exception e){
 System.out.println("You cant do that");
 }
 }while(i==1);
 }
}
______________________________________________________________________

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Layout extends JFrame {
 private JButton lb;
 private JButton cb;
 private JButton rb;
 private FlowLayout layout;
 private Container container;
 
 public Layout(){
 super("Title");
 layout = new FlowLayout();
 container = getContentPane();
 setLayout(layout);
 
 // left block is here
 lb = new JButton("LEFT");
 add(lb);
 lb.addActionListener(
 new ActionListener(){
 public void actionPerformed(ActionEvent event){
 layout.setAlignment(FlowLayout.LEFT);
 layout.layoutContainer(container);
 }
 }
 );
 
 // center block is here
 
 cb = new JButton("CENTER");
 add(cb);
 cb.addActionListener(
 new ActionListener(){
 public void actionPerformed(ActionEvent event){
 layout.setAlignment(FlowLayout.CENTER);
 layout.layoutContainer(container);
 }
 }
 ); 
 
 // right block is here
 rb = new JButton("RIGHT");
 add(rb);
 rb.addActionListener(
 new ActionListener(){
 public void actionPerformed(ActionEvent event){
 layout.setAlignment(FlowLayout.RIGHT);
 layout.layoutContainer(container);
 }
 }
 );
 } 
}

______________________________________________________________________

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LearnGraphics extends JPanel{
 public void paintComponent(Graphics g){ //build in method
 super.paintComponent(g);
 this.setBackground(Color.WHITE);
 
 g.setColor(Color.BLUE);
 g.fillRect(25, 25, 100, 30);
 
 g.setColor(new Color(190,81,25));
 g.fillRect(25, 65, 100, 30);
 
 g.setColor(Color.RED);
 g.drawString("this is some text", 25, 120);
 
 g.setColor(Color.RED);
 g.drawRect(150, 2, 25, 50);
 
 
 
 }
}




______________________________________________________________________

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ComboBoxGUI extends JFrame {
 private JComboBox box;
 private JLabel picture;
 
 private static String[] filename = {"r.JPG","c.JPG"};
 private Icon[] pics = {new ImageIcon(getClass().getResource(filename[0])),
 new ImageIcon(getClass().getResource(filename[1]))};
 
 public ComboBoxGUI(){
 super("The Title");
 setLayout(new FlowLayout());
 
 box = new JComboBox(filename);
 /*box.addItemListener(
 new ItemListener(){
 public void itemStateChanged(ItemEvent event){
 if(event.getStateChange() == ItemEvent.SELECTED){
 picture.setIcon(pics[box.getSelectedIndex()]);
 }
 }
 }
 );*/
 for(Icon x : pics){
 box.addItemListener(new HandlerClass(x)); 
 } 
 add(box);
 picture = new JLabel(pics[0]);
 add(picture); 
 }
 
 private class HandlerClass implements ItemListener{
 private Icon pic;
 public HandlerClass(Icon p){
 pic = p;
 }
 
 public void itemStateChanged(ItemEvent event){
 if(event.getStateChange() == ItemEvent.SELECTED){
 picture.setIcon(pics[box.getSelectedIndex()]);
 }
 add(picture);
 }
 }
}
______________________________________________________________________

import javax.swing.JFrame;

class hello{
 public static void main(String args[]){ 
 /* AdapterGUI gui = new AdapterGUI();
 gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 gui.setSize(400,200);
 gui.setVisible(true);
 }*/
 
 /*FILE_learn gui = new FILE_learn();
 gui.openFile();
 gui.readFile();
 gui.closeFile();*/
 
 /*ExceptionBlock ExpBl = new ExceptionBlock();
 ExpBl.calculate();*/
 
 /*Layout gui = new Layout();
 gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 gui.setSize(200,100);
 gui.setVisible(true);*/
 
 
 JFrame f = new JFrame("The Title");
 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 LearnGraphics l = new LearnGraphics();
 f.add(l);
 f.setSize(400,250);
 f.setVisible(true);
 }
}

______________________________________________________________________

import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class GUI extends JFrame{
 private JButton reg;
 private JButton custom;
 
 public GUI(){
 super("The Title");
 setLayout(new FlowLayout());
 
 reg = new JButton("Regbutton saurav");
 add(reg);
 
 Icon r = new ImageIcon(getClass().getResource("r.JPG"));
 Icon c = new ImageIcon(getClass().getResource("c.JPG"));
 
 custom = new JButton("Custom",r);
 custom.setRolloverIcon(c);
 add(custom);
 
 HandlerClass handler = new HandlerClass();
 reg.addActionListener(handler);
 custom.addActionListener(handler);
 
 }
 
 private class HandlerClass implements ActionListener{
 public void actionPerformed(ActionEvent event){
 JOptionPane.showMessageDialog(null,String.format("%s",event.getActionCommand()));
 }
 }
}
______________________________________________________________________

import java.util.Scanner;
public class mainClass {
 public static void main(String args[]){
 String[] arr = {"Saurav", "Debapriya", "Akash", "Yash" ,"Prithvi","Koushik","Gaurav"};
 Scanner input = new Scanner(System.in);
 int x = 1;
 do{
 int flag = 0;
 System.out.println("");
 System.out.println("Enter your name : ");
 String name = input.nextLine();
 name = name.trim();
 for(String y: arr){
 if(y.equalsIgnoreCase(name)){
 flag =1;
 }
 }
 if(name.equalsIgnoreCase("EXIT")){
 x = 2;
 }
 else if(flag == 0){
 System.out.println("you can't enter " + name );
 }
 else if(flag ==1)
 {
 System.out.println("Yes you can enter " + name );
 }
 else{
 System.out.println("What the heck is this ");
 x = 2;
 }
 }while(x==1);
 System.out.println("Thank You for visiting us");
 }
 }

______________________________________________________________________

long x;
 Scanner input = new Scanner(System.in);
 System.out.println("Enter number: ");
 
 x = input.nextInt();
 
 long res = fact(x);
 System.out.println("the factorial of "+x+" is "+res );
 }
 public static long fact(long num){
 if(num == 1){
 return 1;
 }
 else {
 return num * fact(num-1);
 }
 }
 
______________________________________________________________________

import java.util.ArrayList;
import java.util.List;

import java.util.Scanner;
import java.util.*;
public class mainClass {
 public static void main(String args[]){
 List<String> list1 = new ArrayList<String>();
 Scanner input = new Scanner(System.in);
 int x =1;
 do{
 System.out.println("Enter : ");
 String name = input.nextLine();
 list1.add(name);
 System.out.println("");
 
 if(name.equalsIgnoreCase("EXIT")){
 x =2;
 }
 else if(name.equalsIgnoreCase("SHOW")){
 for(String show:list1){
 System.out.println(show);
 continue;
 }
 }
 else if(name.equalsIgnoreCase("FIND")){
 mainClass obj = new mainClass();
 obj.find(list1);
 }
 }while(x ==1);
 System.out.println("Thank you for visiting us !!!");
 }
 
 public void find(ArrayList<String> search){
 Scanner input = new Scanner(System.in);
 System.out.println("Enter name to find in the list");
 String findName = input.nextLine();
 int flag = 0;
 for(String a:search){
 if(a.equalsIgnoreCase(findName)){
 flag = 1;
 }
 else{
 flag = 0;
 }
 }
 if(flag==0){
 System.out.println("Sorry " + findName + " is not in the list");
 }
 else if(flag==1){
 System.out.println("Congrats " + findName + " is in the list");
 }
 } 
}

______________________________________________________________________

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.*;

public class mainClass {
 public static void main(String args[]){ 
 String[] things = {"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN"};
 List<String> list1 = new LinkedList<String>();
 for(String x:things){
 list1.add(x);
 }
 
 String[] things2 = {"AAA","BBB","CCC","DDD","EEE","FFF","GGG"};
 List<String> list2 = new LinkedList<String>();
 for(String y:things2){
 list2.add(y);
 }
 
 list1.addAll(list2);
 list2 = null;
 
 printMe(list1);
 removeStuff(list1,2,5);
 printMe(list1);
 reverseMe(list1);
 }
 
 private static void printMe(List<String> l){
 for(String b:l){
 System.out.print(" " + b);
 }
 System.out.println("");
 }
 
 private static void removeStuff(List<String> l, int from, int to){
 l.subList(from, to).clear();
 }
 
 private static void reverseMe(List<String> l){
 ListIterator<String> revr = l.listIterator(l.size());
 while(revr.hasPrevious()){
 System.out.print(" "+ revr.previous());
 }
 System.out.println("");
 } 
}

______________________________________________________________________

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.*;

public class mainClass {
 public static void main(String args[]){ 
 String[] things = new String[4];
 //things = {"AAA","BBB","CCC","DDD","EEE","FFF","GGG","HHH","III"};
 things[0] = "AAA";
 things[1] = "BBB";
 things[2] = "CCC";
 things[3] = "DDD";
 
 LinkedList<String> list = new LinkedList<String>(Arrays.asList(things));
 
 list.add("one");
 list.addFirst("first");
 
 things = list.toArray(new String[list.size()]);
 
 System.out.println(things[3]);
 System.out.println(things[0]);
 } 
}

______________________________________________________________________

import java.util.*;

public class mainClass {
 public static void main(String args[]){ 
 String[] arr = {"AAA","CCC","DDD","FFF","BBB","EEE"};
 List <String> l1 = Arrays.asList(arr);
 
 Collections.sort(l1);
 System.out.println(l1);
 
 Collections.sort(l1,Collections.reverseOrder());
 System.out.println(l1);

} 
}

______________________________________________________________________

import java.util.*;

public class mainClass {
 public static void main(String args[]){ 
 
 //collection method specifically for list
 Character[] ray = {'p','w','n'};
 List<Character> l = Arrays.asList(ray);
 
 System.out.print("List is : " );
 output(l);
 
 //reverse and print out the list
 
 Collections.reverse(l);
 System.out.print("After reverse : ");
 output(l);
 
 Character[] newRay = new Character[3];
 List<Character> listCopy = Arrays.asList(newRay);
 
 Collections.copy(listCopy, l);
 System.out.print("Copy of list : ");
 output(listCopy);
 
 Collections.fill(l,'A');
 System.out.print("After filling the list : " );
 output(l);
 
 } 
 
 private static void output(List<Character> thelist){
 for(Character thing:thelist){
 System.out.print(thing);
 }
 System.out.println("");
 }
}

______________________________________________________________________




import java.util.*;

public class mainClass {
 public static void main(String args[]){ 
 
 //collection method specifically for list
 Character[] ray = {'p','w','n'};
 List<Character> l = Arrays.asList(ray);
 
 System.out.print("List is : " );
 output(l);
 
 //reverse and print out the list
 
 Collections.reverse(l);
 System.out.print("After reverse : ");
 output(l);
 
 Character[] newRay = new Character[3];
 List<Character> listCopy = Arrays.asList(newRay);
 
 Collections.copy(listCopy, l);
 System.out.print("Copy of list : ");
 output(listCopy);
 
 Collections.fill(l,'A');
 System.out.print("After filling the list : " );
 output(l);
 
 } 
 
 private static void output(List<Character> thelist){
 for(Character thing:thelist){
 System.out.print(thing);
 }
 System.out.println("");
 }
}

______________________________________________________________________

import java.util.*;

public class mainClass {
 public static void main(String args[]){ 
 String[] things = {"XXX","AAA","BBB","CCC","BBB","DDD","EEE","FFF","AAA"};
 List<String> list = Arrays.asList(things);
 System.out.println(list);
 
 Set<String> set = new HashSet<String>(list);
 System.out.println(set);
 }
}

______________________________________________________________________

import java.util.*;

public class mainClass {
 public static void main(String args[]){ 
 Integer[] iray = {1,2,3,4};
 Character[] cray = {'s','a','u','r','a','v'};
 
 printMe(iray);
 printMe(cray);
 }
 
 //generic Method
 public static <T> void printMe(T[] x){
 for(T b:x){
 System.out.print(b + " ");
 }
 System.out.println("");
 }
 
/* public static void printMe(Integer[] i){
 for(Integer x:i){
 System.out.print(x + " " );
 }
 System.out.println("");
 }
 
 public static void printMe(Character[] c){
 for(Character x:c){
 System.out.print(x + " ");
 }
 System.out.println("");
 }
 */
 
}

______________________________________________________________________

import java.util.*;

public class mainClass {
 public static void main(String args[]){ 
 
 System.out.println(max(12,14,2));
 System.out.println(max("hello","WORLD","world"));
 
 }
 
 public static <T extends Comparable<T>> T max(T a, T b, T c){
 T max = a;
 if(b.compareTo(a) > 0){
 max = b;
 }
 if(c.compareTo(a) > 0){
 max = c;
 }
 return max;
 }
}

______________________________________________________________________

import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.application.Application;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import sun.plugin2.liveconnect.JSExceptions;

public class javaFX extends Application implements EventHandler{
 int a = 0;
 int b = 0;

Button button1 = new Button("Click Me 1");
 Button button2 = new Button("Click Me 2");

public static void main(String[] args){
 launch(args);
 }

public void start(Stage primaryStage) throws Exception{
 primaryStage.setTitle("This is the title");

Pane layout = new Pane();
 layout.getChildren().add(button1);
 layout.getChildren().add(button2);

button1.setLayoutX(100);
 button1.setLayoutY(100);
 button2.setLayoutX(100);
 button2.setLayoutY(150);

button1.setOnAction(this);
 button2.setOnAction(this);

Scene scene = new Scene(layout,250,250);
 primaryStage.setScene(scene);
 primaryStage.show();
 }

public void handle (Event event){
 if(event.getSource() == button1){
 a+=1;
 System.out.println("You clicked Button 1 for " + a + " times");

}
 if(event.getSource() == button2){
 Alert.display("The Tile","This is the message");
 }

}
}

import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Modality;
import javafx.stage.Stage;

import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

/**
 * Created by SouravG on 24-04-2017.
 */
public class Alert {
 public static void display(String title, String message){
 Stage stage = new Stage();
 stage.initModality(Modality.APPLICATION_MODAL);

stage.setTitle(title);
 stage.setMinWidth(200);

Label l1 = new Label(message);
 Button b1 = new Button("Click to Close");
 b1.setActionCommand(e->stage.close());

VBox vbox = new VBox();
 vbox.getChildren().addAll(l1,b1);
 vbox.setAlignment(Pos.CENTER);
 Scene scene = new Scene(vbox);
 stage.getScene(scene);
 stage.showAndWait();

}

}
______________________________________________________________________




import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import java.awt.*;

public class javaFX extends Application {
 Stage stage;
 Scene mangoScene, bananaScene;
 public static void main(String[] args){
 launch(args);
 }




@Override
 public void start(Stage primaryStage) throws Exception {
 stage = primaryStage;
 Label mangoLabel = new Label("This is mango scene");
 Button mangoButton = new Button("Switch to banana");
 mangoButton.setOnAction(e->stage.setScene(bananaScene));

StackPane mangoStackPane = new StackPane();
 mangoStackPane.getChildren().addAll(mangoLabel,mangoButton);
 mangoScene= new Scene(mangoStackPane,200,200);

Label bananaLabel = new Label("This is banana Scene");
 StackPane bananaStackPane = new StackPane();
 bananaStackPane.getChildren().addAll(bananaLabel);
 bananaScene = new Scene(bananaStackPane,300,300);
 stage.setScene(bananaScene);
 stage.show();

}
}
______________________________________________________________________

import java.util.Scanner;
public class mainFunc {
 public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 int checkFlag = 0;
 while(checkFlag ==0){
 System.out.println("Enter Number");
 int a = input.nextInt();
 System.out.println("Enter Number");
 int b = input.nextInt();
 if(a>b || b == 0){
 System.out.println("Wrong Input try again");
 checkFlag = 0;
 }
 else{
 for(long i=a;i<b;i++){
 primeFunc(i);
 checkFlag = 1;
 }
 }
 }
 }

public static void primeFunc(long a){
 long num = a;
 boolean isPrime = true;
 for(int i=2;i<=num/2;i++){
 if(num%i==0){
 isPrime = false;
 }
 }
 if(isPrime == true){
 System.out.println(num);
 }
 }
}
______________________________________________________________________




import java.util.Scanner;
public class javaFX {
 public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 Animal mammals = new Animal("Quadrupeds",1 ,1 ,10,10);
 // Animal aquatic = new Animal("Chordate",1 ,1 ,10,10);




//System.out.println(mammals.getName());

Dog fido = new Dog("", 1, 4, 30);
 System.out.println("I am " + fido.getName() +" I am a "+ fido.getType() + " I have " + fido.getTail()+ " tail" + "," + fido.getTeeth()+" teeth and " + fido.getLegs()+ " legs");
 fido.eat();

}
 }




/**
 * Created by SouravG on 04-05-2017.
 */
public class Animal {
 private String type;
 private int brain;
 private int body;
 private int size;
 private int weight;

public Animal(String type, int brain, int body, int size, int weight) {
 this.type = type;
 this.brain = brain;
 this.body = body;
 this.size = size;
 this.weight = weight;
 }

public void move(){
 System.out.println("I can move");
 }

public void eat(){
 System.out.println("I can eat, So as any animal, So eating is nowhere special");
 }

public String getType() {
 return type;
 }
 public int getBrain() {
 return brain;
 }
 public int getBody() {
 return body;
 }
 public int getSize() {
 return size;
 }
 public int getWeight() {
 return weight;
 }
}

/**
 * Created by SouravG on 04-05-2017.
 */
public class Dog extends Animal{
 private String name;
 private int eye;
 private int tail;
 private int legs;
 private int teeth;

public Dog(String name, int tail, int legs, int teeth) {
 super(type, 1, 5, 5, 7);
 this.tail = tail;
 this.eye = 1;
 this.teeth = teeth;
 this.legs = legs;
 this.name =name;
 }

private void chew(){
 System.out.println("Dogs love to Chews food");
 }

@Override
 public void eat() {
 System.out.println("Dog is eating");
 chew();
 super.eat();
 }

public int getTail(){
 return tail;
 }
 public int getEye(){
 return eye;
 }
 public int getTeeth(){
 return teeth;
 }
 public int getLegs(){
 return legs;
 }
 public String getName(){
 return name;
 }

}

/**
 * Created by SouravG on 04-05-2017.
 */
/*
public class Fish extends Animal{




private int fins;
 private int gills;
 private int eyes;




public Fish(int fins, int gills, int eyes) {

this.fins = fins;
 this.gills = gills;
 this.eyes = eyes;
 }

public void getFins(){
 System.out.println("I have fins I can Swim");
 }
 public void getGills(){
 System.out.println("I have gills, I hcan breathe");
 }
 public void getEyes(){
 System.out.println("I have eyes, I can see");
 }
}
*/

______________________________________________________________________




import java.util.Scanner;
public class javaFX {
 public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 Model Chevrolet = new Model(20);
 Chevrolet.accelerate(20);
 Chevrolet.accelerate(10);
 Chevrolet.changeVelocity(2,45);
 Chevrolet.accelerate(10);
 }
 }




/**
 * Created by SouravG on 04-05-2017.
 */
public class Vehicle {
 private String name;
 private int size;

private int currentVelocity;
 private int currentDirection;




public Vehicle(String name, int size){
 this.name = name;
 this.size = size;
 this.currentVelocity = 0;
 this.currentDirection = 0;
 }

public void steer(int direction){
 this.currentDirection += direction;
 System.out.println(" Vehicle.steer() is moving in direction : " + currentDirection);
 }
 public void move(int velocity, int direction){
 currentVelocity = velocity;
 currentDirection = direction;

System.out.println("The vehicle is moving in " + velocity+" velocity at "+ direction+ " direction");
 }

public String getName() {
 return name;
 }

public int getSize() {
 return size;
 }

public int getCurrentVelocity() {
 return currentVelocity;
 }

public int getCurrentDirection() {
 return currentDirection;
 }

public void stop(){
 this.currentVelocity = 0;
 }
}

public class Cars extends Vehicle {
 public int gears;
 public boolean isManual;
 public int wheels;
 public int doors;

private int currentGear;

public Cars(String name, int size, int gears, boolean isManual, int wheels, int doors) {
 super(name, size);
 this.gears = gears;
 this.isManual = isManual;
 this.wheels = wheels;
 this.doors = doors;
 this.currentGear = 1;
 }

public void changeGear(int currentGear){
 this.currentGear = currentGear;
 System.out.println("Car.changeGear(): changed to : "+this.currentGear + " gear.");
 }

public void changeVelocity(int speed, int direction){
 move(speed,direction);
 System.out.println("Car velocity = "+speed+" and Direction is "+ direction);
 }
}




import org.omg.CORBA.PUBLIC_MEMBER;

/**
 * Created by SouravG on 04-05-2017.
 */
public class Model extends Cars{
 private int roadServiceMonth;

public Model(int roadServiceMonth) {
 super("Carrera", 6, 6, false, 4, 3);
 this.roadServiceMonth = roadServiceMonth;
 }

public void accelerate(int rate){
 int newVelocity = getCurrentVelocity() + rate;
 if(newVelocity == 0){
 stop();
 }
 else if(newVelocity >= 0 && newVelocity <=20){
 changeGear(1);
 }
 else if(newVelocity >=30){
 changeGear(2);
 }
 else if(newVelocity >=40 && newVelocity < 50){
 changeGear(3);
 }
 else
 changeGear(4);

if(newVelocity > 0){
 changeVelocity(newVelocity,getCurrentDirection());
 }

}

}

______________________________________________________________________

class JavaLearn {
 static void play()throws Exception{
 System.out.println("before");
 throw new IllegalAccessException("demo");//System.out.println("after");
 }
 public static void main(String args[]){
 try{
 play();
 }
 catch(Exception e)
 {
 System.out.println("caught me : "+e);
 }
 }
}
 // Example using throws
class ThrowsDemo{
 static void play(){
 try{
 System.out.println("before");
 throw new IllegalAccessException("demo");//System.out.println("after");
 }
 catch(Exception e){
 System.out.println("Exception e"+e);
 }
 }
 public static void main(String args[]) throws Exception {
 play();
 }
}

______________________________________________________________________

Armstrong number

import java.util.Scanner;
import java.math.*;
public class mainFunc {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 int num1 = input.nextInt();
 int num2 = num1;
 int counter = 0;
 int x = 0;
 while (num1 > 0) {
 num1 = num1 / 10;
 counter++;
 }
 
 int sum = calculateSum(counter,num2);


if(num2 == sum){
 System.out.println("Yes, it is");
 }
 else{
 System.out.println("No");
 }
 }
 public static int calculateSum(int c, int num2){
 int[] intArr = new int[c];

for (int i = 0; i < c; i++) {
 intArr[i] = num2 % 10;
 num2 = num2 / 10;
 }
 int sum = (int) (Math.pow(intArr[0],3) + Math.pow(intArr[1],3) + Math.pow(intArr[2],3));
 return sum;
 }
}

______________________________________________________________________

palindrome

import java.util.Scanner;
import java.math.*;
public class mainFunc {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 String word = input.nextLine();
 int wordLength = word.length();
 int flag = -1;
 char[] wordCharacters = new char[wordLength];
 wordCharacters = word.toCharArray();

for (int i = 0; i < wordLength; i++) {
 if (wordCharacters[i] == wordCharacters[wordLength - 1] && wordLength >= i && wordLength != i) {
 flag = 0;
 } else {
 flag = 1;
 }
 wordLength--;
 }

if (flag == 0) {
 System.out.println("This Word is Pallindrome");
 } else {
 System.out.println("No this is not pallindrome");
 }
 }
 }

______________________________________________________________________

import java.util.Scanner;

public class MatrixMultiplication {
 public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
 int[][] a = new int[3][3];
 int[][] b = new int[3][3];
 int[][] c = new int[3][3];

System.out.println("Enter First array");

for(int i=0;i<3;i++){
 for(int j=0;j<3;j++){
 System.out.println("Enter :");
 a[i][j] = input.nextInt();
 }
 }

System.out.println("Enter Second array");
 for(int i=0;i<3;i++){
 for(int j=0;j<3;j++){
 System.out.println("Enter : ");
 b[i][j] = input.nextInt();
 }
 }

for(int i=0;i<3;i++){
 for(int j=0;j<3;j++){
 c[i][j] = a[i][j] * b[i][j];
 }
 }

System.out.println("The result is : ");
 for(int i=0;i<3;i++){
 for(int j=0;j<3;j++){
 System.out.print(c[i][j]+"\t");
 }
 System.out.println();
 }
 }
}

______________________________________________________________________

/*MAtrix Multiplication*/

import java.util.Scanner;

public class mainFunc {

public static void main(String[] args) {
 Scanner s = new Scanner(System.in);
 System.out.print("Enter number of rows in A: ");
 int rowsInA = s.nextInt();
 System.out.print("Enter number of columns in A / rows in B: ");
 int columnsInA = s.nextInt();
 System.out.print("Enter number of columns in B: ");
 int columnsInB = s.nextInt();
 int[][] a = new int[rowsInA][columnsInA];
 int[][] b = new int[columnsInA][columnsInB];
 System.out.println("Enter matrix A");
 for (int i = 0; i < a.length; i++) {
 for (int j = 0; j < a[0].length; j++) {
 a[i][j] = s.nextInt();
 }
 }
 System.out.println("Enter matrix B");
 for (int i = 0; i < b.length; i++) {
 for (int j = 0; j < b[0].length; j++) {
 b[i][j] = s.nextInt();
 }
 }
 int[][] c = multiply(a, b);
 System.out.println("Product of A and B is");
 for (int i = 0; i < c.length; i++) {
 for (int j = 0; j < c[0].length; j++) {
 System.out.print(c[i][j] + " ");
 }
 System.out.println();
 }
 }

public static int[][] multiply(int[][] a, int[][] b) {
 int rowsInA = a.length;
 int columnsInA = a[0].length; // same as rows in B
 int columnsInB = b[0].length;
 int[][] c = new int[rowsInA][columnsInB];
 for (int i = 0; i < rowsInA; i++) {
 for (int j = 0; j < columnsInB; j++) {
 for (int k = 0; k < columnsInA; k++) {
 c[i][j] = c[i][j] + a[i][k] * b[k][j];
 }
 }
 }
 return c;
 }
}

______________________________________________________________________

/*Angle and quadrant*/

import java.io.*;
import java.util.Scanner;
import java.lang.Math;




public class mainFunc
{
 /**
 Calculate the quadrant of an angle.
 */
 public static void main (String[] args)
 {

int angle = 0;
 System.out.println("Type an integer angle (in degrees) and press Enter:");
 Scanner sc = new Scanner(System.in);
 angle= sc.nextInt();
 int value =0;

int quadrant =0;
 if(angle > 360){
 angle = angle % 360;
 value = angle / 360;
 }

if(angle>=0 && angle <=90){
 quadrant = 1;
 }
 else if(angle >90 && angle <=180){
 quadrant = 2;
 }
 else if(angle >180 && angle <=270){
 quadrant = 3;
 }
 else if(angle >270 && angle <=360){
 quadrant = 4;
 }

// output
 System.out.println("Quadrant is:" + quadrant);




}
}

______________________________________________________________________

import java.io.*;
import java.util.Scanner;
public class mainFunc {

public static String names[] = {"harry", "michael", "will", "tom", "jackie"};
 public static String surnames[] = {"potter", "jackson", "smith", "cruise", "chan"};

public static void main(String a[]) throws Exception {
 Scanner sc = new Scanner(System.in);
 String name;
 int found = -1;




System.out.println("Enter the name:");
 name = sc.next();
 System.out.println("Full name of the celebraty is:");
 /*write down your logic*/

int l = names.length;

for(int i=0;i< l;i++){
 if(name.equalsIgnoreCase(names[i])){
 found = i ;
 break;
 }
 }
 System.out.println(names[found] + " " + surnames[found]);
 }//main
}

______________________________________________________________________

/*Rectangle made with stars*/

import java.io.*;
import java.util.Scanner;
public class mainFunc {




public static void main(String a[]) throws Exception {
 Scanner input = new Scanner(System.in);
 int length = input.nextInt();
 int width = input.nextInt();

printLendth(length);
 System.out.println();
 printWidth(width-2, length -2);
 printLendth(length);
 }
 public static void printLendth(int length){
 for(int i=0;i<length;i++){
 System.out.print("*");
 }

}
 public static void printWidth(int width, int length){

for(int j=0;j<width;j++){
 System.out.print("*");
 for(int i=0;i<length;i++){
 System.out.print(" ");
 }
 System.out.print("*");
 System.out.println();
 }
 }
}

______________________________________________________________________

/*Lucky Number from Birthdate*/

/*Lucky number calculater(just calculates the sum of digits of the given date*/
import java.io.*;
class digitsum{

public static void main(String arg[])throws Exception{

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the date(ddmmyy):");
int number =Integer.parseInt(br.readLine());
 int sum = number;
 while(sum > 9){
 sum = calculate(sum);
 }
 System.out.println("Your lucky number is:"); 
 System.out.println(sum);

}

private static int calculate(int x){
 int count = 0;
 int sum = 0;
 int copyX = x;
 while(x > 0){
 x=x/10;
 count ++;
 }
 for(int i=0;i<count;i++){
 sum += copyX%10;
 copyX /= 10;
 }

return sum;
 }
}
______________________________________________________________________

/*count number of 1's between a range*/
import java.util.*;

public class mainFunc {
 public static int ones =0;
 static int count = 0;

public static void main(String args[]) throws Exception {
 Scanner input = new Scanner(System.in);
 System.out.println("Enter Lower Limit");
 int a = input.nextInt();
 System.out.println("Enter Upper limit");
 int b = input.nextInt();
 CountOnes(a,b);
 }
 private static void CountOnes(int x, int y)
 {
 int j =0;
 for(int i=x;i<=y;i++){
 j=i;
 while (j>0) {
 if (j % 10 == 1) {
 count++;
 }
 j = j / 10;
 }
 }
 System.out.println("total count : " + count);
 }
}
______________________________________________________________________

import java.util.*;

public class countone {
 public static int ones =0;
 static int count = 0;

public static void main(String args[]) throws Exception {
 Scanner input = new Scanner(System.in);
 //System.out.println("Enter Lower Limit");
 //int a = input.nextInt();
 int a =1;
 System.out.println("Enter the Maximum value:");
 int b = input.nextInt();
 CountOnes(a,b);
 }
 private static void CountOnes(int x, int y)
 {
 int j =0;
 for(int i=x;i<=y;i++){
 j=i;
 while (j>0) {
 if (j % 10 == 1) {
 count++;
 }
 j = j / 10;
 }
 }
 System.out.println("Total sum of count of 1s: "+count); 
 }
}

______________________________________________________________________

using System;
using System.Collections.Generic;
using C = System.Console;

namespace MainFunc
{
 class Program
 {
 static void Main(string[] args)
 {
 C.WriteLine("Enter Number : ");
 int x = Convert.ToInt32(C.ReadLine());
 if (x % 2 == 0)
 {
 C.WriteLine(Answer(x - 1));
 }
 else
 {
 C.WriteLine(Answer(x));
 }
 }
 public static int Answer(int x)
 {

if (x == 1)
 return 1;
 else {
 return x + Answer(x - 2);
 }

}
 }
}

______________________________________________________________________

/*
 * Write a program which takes two integers N and M and produces last samples of N of the integers from N-1 to N-M.

for Ex:
1) if user inputs N = 10 M = 4 output will be 9 8 7 6
means it produces last 4 samples from 0 to 10.

2) if user inputs N = 5 M = 2 output will be 4 3
 
*/

using System;
using System.Collections.Generic;
using C = System.Console;

namespace MainFunc
{
 class Program
 {
 static void Main(string[] args)
 {
 C.WriteLine("Enter N(larger number) : ");
 int n = Convert.ToInt32(C.ReadLine());
 C.WriteLine("Enter M(Smaller number) : ");
 int m = Convert.ToInt32(C.ReadLine());
 int temp;
 if (m > n) {
 temp = m;
 m = n;
 n = temp;
 }
 for (int i = n - 1; i >= n - m; i--)
 {
 C.Write(i + " ");
 }
 }
 }
}

______________________________________________________________________

import java.util.*;
import java.util.Scanner;

public class mainFunc {
 public static int ones =0;

public static void main(String args[]) throws Exception {
 Scanner input = new Scanner(System.in);
 String word = input.nextLine();

char[] charArr = new char[word.length()];
 for(int i=0;i<word.length();i++){
 charArr[i] = word.charAt(i);
 }
 char t;
 for(int j=0;j<word.length()-1;j++) {
 for (int k = 0; k < word.length() - 1 - j; k++) {
 if (charArr[k] > charArr[k + 1]) {
 t = charArr[k];
 charArr[k] = charArr[k + 1];
 charArr[k + 1] = t;
 }
 }
 }
 for(char x : charArr){
 System.out.print(x);
 }

}
}

______________________________________________________________________

using System;
using System.Collections;

namespace MainFunc
{
 class Program
 {
 public static void Main(string[] args)
 {
 Customer[] customer = new Customer[3];
 customer[0] = new Customer
 {
 gender = 1,
 name = "Saurav"
 };
 customer[1] = new Customer
 {
 gender = 2,
 name = "Eikmen"
 };
 customer[2] = new Customer
 {
 gender = 0,
 name = "Computer"
 };

foreach(Customer cust in customer)
 {
 System.Console.WriteLine("Name is {0} and gender is {1}",cust.name, getGender(cust.gender)); 
 }
 }

public static String getGender(int x) {
 switch (x) 
 { 
 case 0:
 return "Unknown";
 case 1:
 return "Male";
 case 2:
 return "Female"; 
 default:
 return "Invalid input";
 } 
 }
 }

public class Customer{
 public int gender {get; set;}
 public String name {get; set;}
 }
}
 
 ______________________________________________________________________
 
 using System;
using System.Collections;

namespace MainFunc
{
 public enum Gender { 
 Male,
 Female,
 Unknown
 }
 class Program
 {
 public static void Main(string[] args)
 {
 Customer[] customer = new Customer[3];
 customer[0] = new Customer
 {
 gender = Gender.Male,
 name = "Saurav"
 };
 customer[1] = new Customer
 {
 gender = Gender.Female,
 name = "Eikmen"
 };
 customer[2] = new Customer
 {
 gender = Gender.Unknown,
 name = "Computer"
 };

foreach(Customer cust in customer)
 {
 System.Console.WriteLine("Name is {0} and gender is {1}",cust.name, getGender(cust.gender)); 
 }
 }

public static String getGender(Gender x) {
 switch (x) 
 { 
 case Gender.Unknown:
 return "Unknown";
 case Gender.Male:
 return "Male";
 case Gender.Female:
 return "Female"; 
 default:
 return "Invalid input";
 } 
 }
 }

public class Customer{
 public Gender gender {get; set;}
 public String name {get; set;}
 }
}
 
 ______________________________________________________________________
 
 using System;
using System.Collections;

namespace MainFunc
{
 class Program
 {
 // 33-47 and 59-64 special character
 // 48-57 numbers
 // 65-90 big alphabet
 // 97-122 small alphabet
 public static void Main(string[] args)
 {
 bool isSpecial = false;
 bool isNumber = false;
 bool isUpperChar = false;
 bool isLowerChar = false;
 Console.WriteLine("Enter String : ");
 String password = Console.ReadLine();

char[] letter = password.ToCharArray();
 for (int i = 0; i < password.Length;i++)
 {
 if (((int)letter[i] >= 33 && (int)letter[i] <= 47) || ((int)letter[i] >= 59 && (int)letter[i] <= 64))
 {
 isSpecial = true;
 }
 else if ((int)letter[i] >= 48 && (int)letter[i] <= 57)
 {
 isNumber = true;
 }
 else if ((int)letter[i] >= 65 && (int)letter[i] <= 90)
 {
 isUpperChar = true;
 }
 else if ((int)letter[i] >= 97 && (int)letter[i] <= 122)
 {
 isLowerChar = true;
 }
 else 
 {
 isLowerChar = false;
 isUpperChar = false;
 isNumber = false;
 isSpecial = false;
 }
 }
 getCheck(isLowerChar, isUpperChar, isSpecial, isNumber, password.Length);
 }
 public static void getCheck(bool lc, bool uc, bool sc, bool no, int pl) 
 {
 if (lc == false || uc == false || sc == false || no == false || pl < 8)
 {
 if (lc == false)
 {
 Console.WriteLine("Enter one Lower character atleast");
 }
 if (uc == false)
 {
 Console.WriteLine("Enter one Upper character atleast");
 }
 if (sc == false)
 {
 Console.WriteLine("Enter one Special character atleast");
 }
 if (no == false)
 {
 Console.WriteLine("Enter one Number atleast");
 }
 if(pl < 8)
 {
 Console.WriteLine("The Password must be 8 character atleast");
 }
 }
 else 
 {
 Console.WriteLine("Your Password is Accepted");
 }
 }
 }
}
 
 ______________________________________________________________________
 
 using System;
using System.Collections;

namespace MainFunc
{
 class Program
 {
 public static void Main(string[] args)
 {
 int i,j,k,numOfLines;
 Console.WriteLine("Enter the number of lines:");
 numOfLines=Convert.ToInt32(Console.ReadLine());
 
 for(i=1;i<=numOfLines;i++)
 {
 for(k=numOfLines-i;k>=1;k--)
 {
 Console.Write(" ");
 }
 if(i%2!=0)
 {
 for(j=1;j<=i;j++)
 { 
 if(j%2==0)
 {
 Console.Write("0 ");
 }
 else
 {
 Console.Write("1 ");
 }
 }
 }
 else if(i%2==0)
 {
 for(j=1;j<=i;j++)
 {
 if(j%2==0)
 {
 Console.Write("1 ");
 }
 else
 {
 Console.Write("0 ");
 }
 }
 } 
 Console.WriteLine();
 }
 }
 }
 }

______________________________________________________________________
 
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication3
{
 class Program
 {
 static void Main(string[] args)
 {
 Console.Write("enter string:");
 string str = Console.ReadLine();
 Console.Write("enter character you want to remove:");
 char remChar = Convert.ToChar(Console.ReadLine());
 char[] strArr = str.ToLower().ToCharArray();
 int counter = 0;
 for (int i = 0; i < str.Length;i++ )
 {
 if (strArr[i] == remChar)
 {
 counter++;
 continue;
 }
 else {
 Console.Write(strArr[i]);
 }
 }
 Console.WriteLine("\n {0} is present {1} number of times", remChar,counter);
 }
 }
}

______________________________________________________________________

using System;
using System.Collections;

namespace MainFunc
{
 class Program
 {
 public static void Main(string[] args)
 {
 ArrayList primeList = new ArrayList();
 Console.WriteLine("Enter Limit : ");
 int num = Convert.ToInt32(Console.ReadLine());
 int primeCheck = 0;
 for (int i = 2; i < num;i++)
 {
 primeCheck=findPrime(i);
 if(primeCheck !=0)
 {
 primeList.Add(primeCheck);
 }
 }
 int[] primeArr = (int[])primeList.ToArray(typeof(int));
 checkSexyPair(primeArr,num);
 }
 private static void checkSexyPair(int[] primeArrays, int num) 
 {
 for (int i = primeArrays.Length-1; i >= 0;i--)
 {
 if (primeArrays.Contains(primeArrays[i] - 6)) 
 {
 Console.WriteLine("{0} and {1} are SexyPairs", primeArrays[i], primeArrays[i] - 6);
 }
 }

}
 private static int findPrime(int x) 
 {
 bool flag = true;
 for (int i = 2; i <= x/2; i++)
 {
 if(x%i == 0)
 {
 flag = false;
 }
 }
 if (flag == true)
 {
 Console.WriteLine("{0} is prime", x);
 return x;
 }
 else 
 {
 return 0;
 }
 }
 }
}
 
______________________________________________________________________
public class TestOuter{
 public static void main(String[] args){
 new Thread(
 new MyRunnable(){
 public void run(){
 for(int i=0;i<10;i++){
 System.out.println("Child Thread");
 }
 }
 }).start();
 for(int i=0;i<10;i++){
 System.out.println("Main Thread");
 } 
 }
}




/*public class TestOuter{
 public static void main(String[] args){
 new MyThread(){
 public void run(){
 System.out.println("I am Child Thread");
 }
 }.start();
 System.out.println("I am main Thread");
 }
}
*/

/*class PopCorn{
 public void justPrint(){
 System.out.println("Direct Class");
 }
}

public class TestOuter{
 public static void main(String[] args){
 PopCorn p1 = new PopCorn();
 PopCorn p2 = new PopCorn(){
 public void justPrint(){
 System.out.println("Anonymous Class"); 
 }
 };
 p2.justPrint();
 p1.justPrint();
 System.out.println("Direct : "+p1.getClass().getName());
 System.out.println("Anonymous "+p2.getClass().getName());
 }
}
*/
import java.util.*;
class test{
psvm(String[] args){
 Scanner input = new Scanner(System.in);
 int i = input.nextInt();
 int j = input.nextInt();
 int k = input.nextInt();
 input.close(); 
 sout("i = "+i);
 sout("j = "+j);
 sout("k = "+k);
}
}
/////////////////////////////////
import java.util.*;
public class Test{
 public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 System.out.println("Enter Number : ");
 int a = input.nextInt();
 boolean isEven = EvenOddFun(a);
 if(isEven){
 if(a>=2 && a<5){
 System.out.println("Not Wierd");
 }
 else if(a>=6 && a<20){
 System.out.println("Wierd");
 }
 else{
 System.out.println("Not Wierd");
 }
 }
 
 }
 private static boolean EvenOddFun(int n){
 if(n%2==0){
 return true;
 }
 else{
 system.out.println("Wierd");
 return false;
 } 
 } 
}
//////////////////////////////////
Note: If you use the nextLine() method immediately following the nextInt() method, recall that nextInt() reads integer tokens; because of this, the last newline character for that line of integer input is still queued in the input buffer and the next nextLine() will be reading the remainder of the integer line
 (which is empty).
 
 : Solution : https://stackoverflow.com/questions/23036062/cant-use-scanner-nextint-and-scanner-nextline-together . 
 
 
 import java.util.Scanner;

public class Solution {

public static void main(String[] args) {
 Scanner sc=new Scanner(System.in);
 System.out.println("================================");
 for(int i=0;i<3;i++){
 String s1=sc.next();
 int x=sc.nextInt();
 System.out.printf("%-15s%03d\n",s1,x);
 
 }
 System.out.println("================================");

}
}
//////////////////////////////////////
import java.util.Scanner;
public class Test{
 public static void main(String[] args){
 Scanner input = new Scanner(System.in);
 int N=input.nextInt();
 int[] firstArr = new int[N];
 int[] SecondArr = new int[N];
 int[] sumArr = new int[N];
 
 
 for(int i=0;i<N;i++){
 firstArr[i] = input.nextInt();
 }
 for(int i=0;i<N;i++){
 SecondArr[i] = input.nextInt();
 }
 for(int i=0;i<N;i++){
 SumArr[i] = firstArr[i]+ SecondArr[i];
 System.out.print(sumArr[i]+" ");
 }
 
 }
}
//////////////////////////////////////
/*Bubble Sort* -- compare two adjacent/
import java.util.Scanner;
public class BubbleSortTest{
 public static void main(String[] args){
 int[] a = new int[5];
 Scanner input = new Scanner(System.in);
 for(int i=0;i<5;i++){
 a[i] = input.nextInt();
 }
 int[] bubbleArray = new int[5];
 bubbleArray = bubbleFunc(a);
 }
 public static bubbleFunc(int[] k){
 int l = k.length;
 for(int i=0;i<l-1;i++){
 for(int j=i;j<l-1;j++){
 if(k[j] > k[j+1]){
 swap(k[j],k[j+1]);
 }
 else{
 continue;
 }
 }
 }
 }
}

minimum one by one
public class SortedArrayTest{
 public static void main(String[] args){
 int[] a = new int[5];
 for(int j=0;j<5;j++){
 for(int i=j;i<5;i++){
 if(a[j]<a[i]){
 continue;
 }
 else{
 swap(a[0],a[i]);
 }
 } 
 }
 }
}

////////////////////////////////////////////
First of all take hundreds place digit by deviding by 100 and print corresponding number by calling method numberToWord((number / 100), " HUNDRED"); since number / 100 would be in between 0 to 9 so it will print digit in word concatenated by HUNDRED.

Now you left with two digit number for that you directly call numberToWord((number % 100), " "); since we are taking modulo 100 of number so it would pass two digit only. if (num > 19) {System.out.print(tens[num / 10] + " " + ones[num % 10]);} then it will take tens place and print tens word concatenated by ones. else {System.out.print(ones[num]);} directly prints word between 1 to 19 from the array.

import java.util.Scanner;

public class Test1 {
 public static void main(String[] args) {
 int number = 0;
 Scanner scanner = new Scanner(System.in);
 System.out.print("Please type a number between 0 and 999 OR type -1 to exit: ");
 number = scanner.nextInt();
 while(number!=-1){
 if(number>=0 && number<=999){
 if(number==0){
 System.out.print("NUMBER AFTER CONVERSION:\tZERO");
 } else {
 System.out.print("NUMBER AFTER CONVERSION:\t");
 numberToWord(((number / 100) % 10), " HUNDRED");
 numberToWord((number % 100), " ");
 }
 } else{
 System.out.print("NUMBER OUT OF RANGE");
 }
 System.out.print("\nPlease type a number between 0 and 999 OR type -1 to exit: ");
 number = scanner.nextInt();
 }
 }
 public static void numberToWord(int num, String val) {
 String ones[] = {" ", " ONE", " TWO", " THREE", " FOUR", " FIVE", " SIX", " SEVEN", " EIGHT", " NINE", " TEN", " ELEVEN", " TWELVE", " THIRTEEN", " FOURTEEN", " FIFTEEN", " SIXTEEN", " SEVENTEEN", " EIGHTEEN", " NINETEEN"
 };
 String tens[] = {" ", " ", " TWENTY", " THIRTY", " FOURTY", " FIFTY", " SIXTY", " SEVENTY", " EIGHTY", " NINETY"};
 if (num > 19) {
 System.out.print(tens[num / 10] + " " + ones[num % 10]);
 } else {
 System.out.print(ones[num]);
 }
 if (num > 0) {
 System.out.print(val);
 }
 }
 }

 

 

 

Examples for all videos from 128-138

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.*;
import javafx.scene.text.*;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.control.Label;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.paint.Color;

import java.awt.*;
//import java.awt.Color;

import static java.awt.Color.*;

public class Main extends Application {

@Override
 public void start(Stage primaryStage) throws Exception{
 Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
 primaryStage.setTitle("Hello JavaFX");
 primaryStage.setScene(new Scene(root, 300, 275));
 primaryStage.show();
 }
 public static void main(String[] args) {

launch(args);
 }
}
----------------------------------------------------------------------------
package sample;
public class Controller {
}
----------------------------------------------------------------------------
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.text.Font?>

<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Slider?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.control.RadioButton?>
<?import javafx.scene.control.ToggleGroup?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.collections.FXCollections?>
<?import java.lang.String?>
<?import javafx.scene.control.Spinner?>
<?import javafx.scene.control.ColorPicker?>
<?import javafx.scene.control.DatePicker?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.control.Accordion?>
<?import javafx.scene.layout.VBox?>
<GridPane fx:controller="sample.Controller"
 xmlns:fx="http://javafx.com/fxml" alignment="CENTER" hgap="10" vgap="10" gridLinesVisible="False">

<Button GridPane.columnIndex="0" GridPane.rowIndex="0" text="ClickMe">
 <!--<graphic>-->
 <!--<ImageView>-->
 <!--<Image url=""/>-->
 <!--</ImageView>-->
 <!--</graphic>-->
 </Button>
 <Label GridPane.rowIndex="0" GridPane.columnIndex="1" text="This is a sample label" textFill="darkblue" wrapText="True">
 <font>
 <Font name="Times New Roman BOLD" size="21"/>
 </font>
 <!--<graphic>-->
 <!--<ImageView>-->
 <!--<Image url=""/>-->
 <!--</ImageView>-->
 <!--</graphic>-->
 </Label>

<fx:define>
 <ToggleGroup fx:id="colorRadioGroup"/>
 </fx:define>
 <RadioButton GridPane.columnIndex="2" GridPane.rowIndex="0" text="red" toggleGroup="$colorRadioGroup"/>
 <RadioButton GridPane.columnIndex="3" GridPane.rowIndex="0" text="Blue" toggleGroup="$colorRadioGroup"/>
 <RadioButton GridPane.columnIndex="4" GridPane.rowIndex="0" text="green" toggleGroup="$colorRadioGroup"/>
<CheckBox text="Subscribe" GridPane.columnIndex="2" GridPane.rowIndex="2" indeterminate="True"/>

<ComboBox GridPane.rowIndex="2" GridPane.columnIndex="0" promptText="hello">

</ComboBox>
<ChoiceBox GridPane.rowIndex="2" GridPane.columnIndex="3" >
 <items>
 <FXCollections fx:factory="observableArrayList">
 <String fx:value="CB 1"/>
 <String fx:value="CB 2"/>
 <String fx:value="CB 3"/>
 <String fx:value="CB 4"/>
 <String fx:value="CB 5"/>
 </FXCollections>
 </items>
</ChoiceBox>
<Slider GridPane.rowIndex="2" GridPane.columnIndex="1" showTickLabels="true" showTickMarks="true" minorTickCount="1" snapToTicks="true" min="0" max="10" orientation="HORIZONTAL"/>
<Spinner GridPane.columnIndex="3" GridPane.rowIndex="3" min="0" max="100" editable="false" initialValue="60"/>
<ColorPicker GridPane.rowIndex="3" GridPane.columnIndex="2" />
<DatePicker GridPane.columnIndex="4" GridPane.rowIndex="3" cache="true" promptText="Today"/>
 <Accordion GridPane.rowIndex="0" GridPane.columnIndex="5" GridPane.columnSpan="4">
 <panes>
 <TitledPane text="titled Pane 1">
 <Label text="This is label ONE "/>
 </TitledPane>
 <TitledPane text="titled Pane 1">
 <Label text="This is label ONE "/>
 </TitledPane>
 <TitledPane text="titled Pane 1">
 <VBox>
 <Label text="This is label ONE "/>
 <Label text="This is label ONE "/>
 <Label text="This is label ONE "/>
 <Button text="Hello"/>
 <Button text="Hello"/>
 <Button text="Hello"/>
 </VBox>
 </TitledPane>
 <TitledPane text="titled Pane 1">
 <Label text="This is label ONE "/>
 </TitledPane>
 </panes>
 </Accordion>
</GridPane>
=================================================================================================================================================

//Main.java
package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
 @Override
 public void start(Stage primaryStage) throws Exception{
 Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
 primaryStage.setTitle("Hello JavaFX");
 primaryStage.setScene(new Scene(root, 300, 275));
 primaryStage.show();
 }
 public static void main(String[] args) {
 launch(args);
 }
}
----------------------------------------------------
Controller.java
package sample;

import javafx.fxml.FXML;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.control.Button;
import javafx.event.ActionEvent;
public class Controller {
 @FXML
 public void initialize(){
 helloButton.setDisable(true);
 byeButton.setDisable(true);
 }
 @FXML
 private TextField inputText;
 @FXML
 private Button helloButton;
 @FXML
 private Button byeButton;
 @FXML
 private CheckBox checkBox;
 @FXML
 public void OnButtonClicked(ActionEvent e){
 if(e.getSource().equals(helloButton)){
 System.out.println("Hello ," +inputText.getText());
 }
 else if(e.getSource().equals(byeButton)){
 System.out.println("Bye ,"+inputText.getText());
 }
 try{
 Thread.sleep(3000);
 }
 catch (InterruptedException event){
 // this could be anything
 }
 if(!checkBox.isSelected()){
 inputText.clear();
 }
 }
 @FXML
 public void HandleReleasedFunc() {
 String name = inputText.getText();
 if(name.isEmpty() || name.trim().isEmpty()){
 helloButton.setDisable(true);
 byeButton.setDisable(true);
 }
 else{
 helloButton.setDisable(false);
 byeButton.setDisable(false);
 }
 }

public void checkBoxEvent(){
 try {
 System.out.println("The Check Box is " + (checkBox.isSelected() ? "Selected" : "Not Selected"));
 }
 catch (NullPointerException e){
 System.out.println("There is a Null Pointer Exception");
 }
 }
}
--------------------------------------------
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.CheckBox?>
<GridPane fx:controller="sample.Controller" xmlns:fx="http://javafx.com/fxml" alignment="CENTER" hgap="10" vgap="10" gridLinesVisible="False">
 <Button fx:id="helloButton" text="Hello" onAction="#OnButtonClicked"
 GridPane.rowIndex="2" GridPane.columnIndex="0"/>
 <Button fx:id="byeButton" text="Bye" onAction="#OnButtonClicked"
 GridPane.rowIndex="2" GridPane.columnIndex="1"/>
 <TextField fx:id="inputText" promptText="TypeHere" onKeyReleased="#HandleReleasedFunc"
 GridPane.columnIndex="0" GridPane.rowIndex="0"/>
 <CheckBox fx:id="confirmCheckBox" text="Please check it to proceed" onAction="#checkBoxEvent"
 GridPane.rowIndex="1" GridPane.columnIndex="0"/>
</GridPane>
========================================================================================================================

 

 

 

//javaFX bucky

//Video1 : Simple Scene, Stage and Button
public Class Main extends Application{
 Stage = myWindow;
 Scene = scene1;
 Button = myButton;
 public void Start(Stage primaryStage) throws Exception{
 myWindow = primaryStage;
 myWindow.setTitle("This is the Title of my Stage");
 myButton = new Button("ClickMe");
 //myButton.setText("ClickMe");
 StackPane myStackPaneLayout = new StackPane();
 myStackPaneLayout.getChildren().add(myButton);
 
 scene1 = new Scene(myStackPaneLayout, 300,500);
 scene1.show();
 
 }
 public static void main(String[] args){
 launch(args);
 }
}
===========================================================
Video2 : Understanding Event Handling for a button
public Class Main extends Application implements EventHandler<ActionEvent>{
 Stage = myWindow;
 Scene = scene1;
 Button = myButton1,myButton2;
 public void Start(Stage primaryStage) throws Exception{
 myWindow = primaryStage;
 myWindow.setTitle("This is the Title of my Stage");
 myButton1 = new Button("I am Button 1");
 myButton2 = new Button("I am Button 2")
 //myButton.setText("ClickMe");
 myButton.setOnAtcion(this); // this line says that the implementation required handle method is present in the same instance of this class
 StackPane myStackPaneLayout = new StackPane();
 myStackPaneLayout.getChildren().add(myButton);
 
 scene1 = new Scene(myStackPaneLayout, 300,500);
 scene1.show();
 
 }
 public static void main(String[] args){
 launch(args);
 }
 
 @Override
 public void Handle(ActionEvent event){
 if(event.getSource()==myButton1){
 System.out.println("This Button1 Works perfectly");
 }
 if(event.getSource()==myButton2){
 System.out.println("This Button2 Works perfectly");
 }
 }
}

========================================================
Video3 : EventHandler for an annonymous class
public Class Main extends Application{
 Stage = myWindow;
 Scene = scene1;
 Button = myButton1,myButton2;
 public void Start(Stage primaryStage) throws Exception{
 myWindow = primaryStage;
 myWindow.setTitle("This is the Title of my Stage");
 myButton = new Button("ClickMe");
 //myButton.setText("ClickMe");
 myButton1.setOnAtcion(new EventHandler<ActionEvent>(){
 System.out.println("This is an anonymous inner class ONE")
 });
 myButton2.setOnAtcion(new EventHandler<ActionEvent>(){
 System.out.println("This is an anonymous inner class TWO")
 });
 StackPane myStackPaneLayout = new StackPane();
 myStackPaneLayout.getChildren().add(myButton);
 
 scene1 = new Scene(myStackPaneLayout, 300,500);
 scene1.show();
 
 }
 public static void main(String[] args){
 launch(args);
 }
XXXXXXXXXXXXXXXXXXXXXXXXX

using lamda expression to define EventHandling

myButton1.setOnAtcion(e->(){
 System.out.println("This is lambda Expression ONE")
 });
 myButton2.setOnAtcion(e->(){
 System.out.println("This is lambda Expression TWO")
 });
=======================================================

Video4 : Switching Scenes

public Class Main extends Application{
 Stage = myWindow;
 Scene = scene1,scene2;
 Button = myButton1,myButton2;
 Label label = new Label("");
 public void Start(Stage primaryStage) throws Exception{
 myWindow = primaryStage;
 
 myWindow.setTitle("The Scene Project");
 myWindow.setScene(scene1);
 myWindow.setTitle("Scene 1");
 VBox verBox1 = new VBox(20);
 VBox verBox2 = new VBox(20);
 myButton1 = new Button("ClickMe to visit Scene ONE");
 myButton2 = new Button("ClickMe to visit Scene TWO");
 
 //Creating Scene 1
 verBox1.getChildren.addAll(label,myButton2);
 verBox2.getChildren.addAll(label,myButton1);
 myButton1.setOnAtcion(e->(){
 myWindow.setScene(scene2);
 myWindow.setTitle("Scene 2");
 label.setText("Welcome to Scene 2");
 });
 myButton2.setOnAtcion(e->(){
 myWindow.setScene(scene1);
 myWindow.setTitle("Scene 1");
 label.setText("Welcome to Scene 2")
 });
 scene1 = new Scene(verBox,300,500);
 scene2 = new Scene(verBox,300,500); 
 }
 public static void main(String[] args){
 launch(args);
 }
 
========================================================

Video5 : Creating alert Box with Modularity

public Class Main extends Application{
 Stage = myWindow;
 public static void main(String[] args){
 launch(args);
 }
 public void Start(Stage primaryStage) throws Exception{
 myWindow = primaryStage;
 myWindow.setTitle("Main Window");
 myWindow.setMinWidth(350);
 Button myButton = new Button("ClickMe");
 myButton.setOnAtcion(e-> AlertBox.Display("Alert Box Title", "This is an alert box, press close to exit"));
 Label mainLabel = new Label("This is Main content, press button for alert box");
 VBox mainContent = new VBox(20);
 mainContent.getChildren().addAll(mainLabel,myButton);
 mainContent.setAlignment(Pos.CENTER);
 Scene mainScene = new Scene(mainContent,300,500);
 }
}
public class AlertBox{
 public static void Display(String Title, String Message){
 Stage alertWindow = new Stage();
 alertWindow.setTitle(Title);
 alertWindow.setMinWidth(250);
 alertWindow.initModality(Modality.APPLICATION_MODAL); // this line will give you functionality to not operate on any other window unless this window is encountered properly
 
 Label alertMesg = new Label(Message);
 Button closeButton = new Button("Close");
 closeButton.setOnAtcion(e->alertWindow.close());
 
 VBox alertBoxContent = new VBox(20);
 alertBoxContent.getChildren.addAll(alertMesg,closeButton);
 mainContent.setAlignment(Pos.CENTER);
 Scene alertScene = new Scene(mainContent,300,500);
 }
}
========================================================
Video6 : Communicating between different stages

public Class Main extents Application{
 public static void main(String[] args){
 launch(args`);
 }
 public void Start(Stage primaryStage) throws Exception{
 Stage mainStage = primaryStage;
 mainStage.setTitle("Main Stage");
 Button myButton = new Button("Click Me");
 myButton.setOnAtcion(e->(){
 boolean result = Confirmation.display("ConfirmationBox","Are you sure you wanna do this :");
 });
 
 }
}
public class Confirmation{
 public static boolean display(String Title, String Mesg){
 boolean answer = false;
 Stage confirmStage = new Stage();
 confirmStage.initModality(Modality.APPLICATION_MODAL);
 confirmStage.setMinWidth(250);
 confirmStage.setTitle(Title);
 Label label = new Label(Mesg);
 Button yesButton = new Button("Yes");
 Button noButton = new Button("No");
 answer = yesButton.setOnAtcion(e->(){return true;confirmStage.close();});
 answer = noButton.setOnAtcion(e->(){return false;confirmStage.close();});
 VBox vboxLayout = new VBox(20);
 Scene confirmScene = new Scene(vboxLayout,300,500);
 confirmScene.show(); 
 
 return answer;
 }
}
========================================================
Video6 : Closing application properly
public class Main extends application{
 public static void main(String[] args){
 launch(args);
 }
 public void Start(Stage primaryStage)throws Exception{
 Stage mainStage = primaryStage;
 Label labelMesg = new label("Press 'Exit' Button to Quit");
 Button buttonConfirm = new Button("Exit");
 buttonConfirm.setOnAtcion(e->(){
 boolean result = Confirmation.display("ExitBox", "Are you sure you want to exit");
 if(result == true){
 System.out.println("You File is saved");
 mainStage.close();
 }
 });
 VBox layout = new VBox(20);
 layout.getChildren().addAll(labelMesg,buttonConfirm);
 Scene sceneMain = new Scene(layout,500,300);
 mainStage.setOnCloseRequest(e->(){
 e.consume();
 closeProgram();
 });
 }
}

public class Confirmation{
 public static boolean display(String Title, String mesg){
 boolean answer=false;
 Stage stageConfirmBox = new Stage();
 stageConfirmBox.setTitle(Title);
 Label labelMesg = new Label(mesg);
 Button yesButton,noButton;
 yesButton = new Button("Yes");
 noButton = new Button("No");
 VBox layout = new VBox(20);
 Scene sceneConfirm = new Scene(layout,500,300);
 scene.show();
 yesButton.setOnAtcion(e->(){
 answer = true;
 stageConfirmBox.close();
 });
 noButton.setOnAtcion(e->(){
 answer = false;
 stageConfirmBox.close();
 });
 return answer;
 
 }
}

========================================================
Video 10: Recieve input from TextField and validate the data

public class Main extends Application{
 public static void main(String[] args){
 launch(args);
 }
 public void Start(Stage primaryStage) throws Exception{
 Stage mainWindow = primaryStage;
 TextField inputText = new TextField();
 inputText.setprompt("Enter Text Here");
 Button submitButton = new Button("Submit");
 submitButton.setOnAtcion(e->(){
 boolean response = submitResponse(inputText.getText());
 });
 }
 public static boolean submitResponse(String input){
 try{
 int x = Integer.parseInt(input);
 return true;
 }catch(NumberFormatException e){
 System.out.println("Errrr... "+ input+ "is not ");
 return false;
 }
 }
}

 

Design a site like this with WordPress.com
Get started