Java Codes
Java Codes
PrintStream;
import [Link];
}
}
import [Link].*;
ArrayDeque<Integer>ad1=new ArrayDeque<>();
[Link](25);
[Link](69);
[Link](75);
[Link](85);
[Link](12);
[Link](36);
[Link](47);
[Link](85);
[Link](ad1);
}
}
}
}
import [Link];
import [Link];
@Override
public String toString() {
return " Error ............ \n Number cannot be greater than
100000";
}
@Override
public String getMessage() {
return " Error ...... Multiplication input cannot be greater than
1000";
}
@Override
public String getLocalizedMessage() {
return "Error ...... 2nd number cannot be greater than 1st number";
}
class calculator {
if (b > 100000) {
if(b>a){
throw new calexp();
}
[Link]("Subtraction of " + b + " from " + a + " is " +
(a-b));
}
public void multiplication() throws calexp{
[Link](" MULTIPLICATION ");
Scanner sc = new Scanner([Link]);
[Link]("Enter your first Number: ");
int a = [Link]();
[Link]("Enter your second number Number : ");
int b = [Link]();
}
[Link]("Multiplication of " + a + " and " + a + " is
" + (a*b));
if( b == 7000){
throw new calexp();
}
[Link]("Division of " + a + " by " + b + " is " +
(a/b));
if (num == 1) {
try {
[Link]();
} catch (Exception e) {
[Link]([Link]());
}
} else if (num == 2) {
try {
[Link]();
} catch (Exception e) {
[Link]([Link]());
}
} else if (num == 3) {
try {
[Link]();
} catch (Exception e) {
[Link]([Link]());
}
} else if (num == 4) {
try {
[Link]();
} catch (Exception e) {
[Link]("Error......cannot divide a number by
zero");
}
}
else{
[Link]("Please enter a correct preference ....");
}
}
}
}
import [Link];
import [Link];
//
LocalDateTime dt = [Link]();
// [Link](dt);
DateTimeFormatter df = [Link]("dd-MM-yyyy--E a
");
import [Link].*;
class c1 {
public int x = 5;
int z = 6;
private int a = 78;
}
}
import [Link];
import [Link];
import [Link];
import [Link].*;
LocalDate d = [Link]();
[Link](d);
LocalTime t = [Link]();
[Link](t);
}
}
interface bicycle{
int a = 45;
}
interface hornbycycle{
void applybrake2();
void speedup2();
}
}}
av.applybrake2();
av.speedup2();
}
}
class classA {
classA(){
}
}
classC(int x, int y) {
super(x);
}
}
import [Link];
public class JAVA_exception {
public static void main(String[] args) {
int a = 6;
int b = 0 ;
try {
int c = a / b;
[Link](c);
}
catch (Exception e){
[Link](" we failed to divide . Reason : ");
[Link](e);
}
}
}
import [Link];
@Override
public String toString() {
return " I am toString()";
}
@Override
public String getMessage() {
return " I am getmessage()";
}
}
if (a < 9) {
try {
else{
[Link](" You enterd number greater than 9");
}
}
}
import [Link];
@Override
public String toString() {
return " I am the toString exception....";
}
@Override
public String getMessage() {
return " You entered a number above 100 \n please enter a number
below 100 ";
}
}
int a =100;
if( num>=100) {
try {
throw new exp();
}
catch (Exception e ) {
[Link]([Link]());
}
}
[Link](" Sum of " + num +" + " +" 100 is --> " +
(num+100));
}
}
public class JAVA_FInally_block {
finally {
[Link]("End of this program");
}
return -1;
}
public static void main(String[] args) {
int a = 50;
int b = 10;
while (true) {
try {
[Link](a / b);
}
catch (Exception e) {
[Link](e);
break;
}
finally {
[Link]("I am finally value of b = " + b);
}
b--;
}
}
}
import [Link];
try{
[Link](" The value at array index entered is : " +
arr[ind]);
[Link](" The value of array value divided by number
is : " + arr[ind]/numb);
}
catch(ArithmeticException e){
[Link]("Arithmetic exception occured !!!" );
}
catch( Exception e ){
[Link](" Some unknown error occured , plzz check
your input ");
}
}
}
interface sampleinterface{
void meth1();
void meth2();
}
}
class mysamplespace implements childsampleinterface{
public void meth1(){
[Link]();
}
public void meth2(){
[Link]();
}
my.meth1();
my.meth2();
my.meth3();
my.meth4();
}
}
interface cellphone{
void ring();
void keypad();
interface GPS{
void location();
void traffic();
}
interface camera {
void photo();
void video();
}
interface mediaplayer{
void playmusic();
void playlist();
@Override
public void playmusic() {
[Link]( "playing music");
}
@Override
public void playlist() {
[Link](" fing the best playlist ");
}
}
}
interface cellphone2{
void ring();
void keypad();
interface GPS2{
void location();
void traffic();
}
interface camera2 {
void photo();
void video();
}
interface mediaplayer2{
void playmusic();
void playlist();
@Override
public void video() {
[Link](" playimg video ");
}
@Override
public void playmusic() {
[Link]( "playing music");
}
@Override
public void playlist() {
[Link](" fing the best playlist ");
}
}
class mythread extends Thread{
public void run() {
}
}
}
}
}
}
import [Link];
try {
[Link](" Welcome to the video");
try {
[Link]( "Value at the specified index position
is --> " + arr[num]);
} catch (ArrayIndexOutOfBoundsException e) {
[Link](" Sorry this index value does not
index , check your input ");
[Link](" exception in level 2");
}
}
catch (Exception e ){
[Link](" exception is level 1" );
}
}
}
class class1 {
void methd1(){
[Link](" I am method 1 of class 1 ");
}
class class2 extends class1{
void methd1(){
[Link](" i am method 2 of class 2 ");
}
class Threadc extends Thread {
}
}
// [Link](10);
// [Link](20);
[Link](6);
[Link](9);
[Link]([Link]());
[Link]([Link]());
// [Link]();
// [Link]();
}
}
import [Link];
} catch (Exception e) {
aman();
}
}
mport [Link];
class arrexp extends Exception{
@Override
public String toString() {
return "Error";
}
}
if (i > 5) {
try {
throw new arrexp();
} catch (Exception e) {
[Link]([Link]());
}
}
}
}
}
class thread1 extends Thread {
public thread1 (String name) {
super(name);
}
[Link]();
try{
[Link]();
}
catch( Exception e ){
[Link](e);
}
[Link]();
}
}
class my_threads_runable1 implements Runnable {
public void run() {
for (int i = 1; i <= 100; i++) {
[Link](" I am a thread 1 not a threat 1");
}
}
}
[Link]();
[Link]();
}
}
import [Link];
}
}
class negexp extends Exception{
@Override
public String toString() {
return " Radius cannot be negative ";
}
@Override
public String getMessage() {
return " Do not enter negative radius";
}
}
return 3.14*r*r;
}
try{
[Link](area(-5));
}
catch(Exception e){
[Link](e);
}
}
}
class myexp extends Exception{
@Override
public String toString() {
return "Radius cannot be negative";
}
@Override
public String getMessage() {
return " Radius cannot be negative ";
}
}
class practice{
if(r<0){
throw new myexp();
}
return 3.14*r*r ;
}
}
while(true){
[Link](" Enter the array index : ");
int num = [Link]();
try{
catch (ArrayIndexOutOfBoundsException e) {
}
import [Link].*;
}
[Link]("\n");
}
[Link](booknm);
Calendar c = [Link]();
[Link]([Link]());
}
public class Library_Management_System {
public static void main(String[] args) {
try {
[Link]();
} catch (Exception e) {
[Link](e);
}
} else if (command == 4) {
[Link]();
}
}
}
import [Link];
import [Link].*;
[Link](6);
[Link](7);
[Link](5);
[Link](3);
[Link](1);
[Link](685);
[Link](30);
[Link](15);
[Link](25);
[Link](685);
// [Link]();
// [Link]([Link](10));
//[Link]([Link](25));
}
}
class mythr extends Thread {
public mythr(String name) {
super(name);
}
[Link](Thread.MAX_PRIORITY);
[Link](Thread.MIN_PRIORITY);
[Link](Thread.MIN_PRIORITY);
[Link](Thread.MIN_PRIORITY);
[Link](Thread.MIN_PRIORITY);
[Link](Thread.MIN_PRIORITY);
[Link](Thread.MIN_PRIORITY);
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
}
}
class rectangle{
int length;
int breadth;
int height;
[Link](5);
[Link](10);
[Link](15);
[Link]();
[Link]();
[Link]();
}
}
deleting and creating a file from java code
package [Link];
import [Link];
import [Link];
try {
[Link]();
}
catch (IOException e){
[Link]("Unable to create this file");
}
}
package [Link];
import [Link];
import [Link];
import [Link];
}
[Link]();
}
catch(FileNotFoundException e){
[Link](e);
}
}
}
package [Link];
import [Link];
/**
* This documentation would tell us about deleting a file from java
* @author Aman Patre
* @version 20003.1
* @since 2005
*/
class library{
import [Link];
import [Link];
try {
FileWriter fileWriter = new FileWriter("Aman [Link]");
[Link]("hello ....... ");
[Link]();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Practice questions
package questions;
import [Link];
int count=0;
while(num>0)
{
num=num/10;
count++;
}
[Link]("Number of digits in the given number is :" +
count);
}
}
package questions;
import [Link];
String str=[Link](a,"");
}
}
package questions;
import [Link];
for(int i = 0;i<[Link]();i++){
}
}
package questions;
import [Link];
try{
[Link]();
}
catch(Exception e){
[Link](e);
}
}
}
package questions;
import [Link];
import [Link];
import [Link];
int num=0;
boolean flag = false;
String[] arr={"Aman" , "Aditya" , "Yash", "Mayank" , " Ravi","Aman"
};
for(int i = 0 ; i<[Link];i++){
for(int j=i+1;j<[Link];j++){
if(arr[i]==arr[j]){
if(flag==false){
[Link]("Duplicate element not found ");
}
else{
[Link]("Duplicate elent found ....");
}
}
package questions;
import [Link];
//method1
//
// boolean status =[Link](a1,a2);
// if (status==true){
// [Link]("Arrays are equal ");
// }
// else {
// [Link]("Arrays are not equal");
// }
if ([Link] == [Link]) {
if (a1[i] != a2[i]) {
status = false;
}
else {
status=true;
}
}
else{
status = false;
}
if(status==true){
[Link]("Arrays are equal");
}
else{
[Link]("Arrays are not equal");
}
}
}
package questions;
if (arr[i] % 2 == 0) {
[Link]( arr[i]);
}
}
[Link]("Odd numbers are : ");
for (int i = 0; i < [Link]; i++) {
if (arr[i] % 2 != 0) {
[Link]( arr[i]);
}
}
}
}
package questions;
import [Link];
long fact=1;
fact=fact*i;
}
[Link](fact);
}
}
package questions;
int n1 = 0;
int n2=1;
int sum=0;
n1=n2;
n2=sum;
}
package questions;
int a = 10;
int b = 200;
int c = 3;
/*
if(a>b && a>c ){
[Link]("a is largest ");
else if (c>a&&c>b ) {
*/
}}
package questions;
max=a[i];
}
[Link]("The max value of array is : "+max + "\n");
if(a[i]<min){
min=a[i];
}
}
}
package questions;
int sum = 0;
int add = 0;
int a1 []= {1,2,3,4,5,6,7,9,10};
add = add+j;
}
int num = add-sum;
package questions;
import [Link];
}
}
package questions;
import [Link];
if(num%2==0){
even_count++;
}
else{
odd_count++;
}
num = num/10;
}
}
}
import [Link];
int rev = 0;
while (num != 0) {
if (rev == org_num) {
[Link]("Enterd number is a palindrome number " +
"\n");
} else {
[Link]("Number is not a palindrome number " +
"\n");
}
}
}
package questions;
import [Link];
import [Link];
[Link]("\n");
if (org_str.equals(str2)) {
[Link]("Entered string is a palindrome string " + "
\n");
}
else {
[Link]("not a palindrome string " + "\n");
}
}
}
package questions;
import [Link];
int count=0;
if(num>=1){
for(int i =1;i<=num;i++){
if(num%i==0){
count++;
}
}
if(count==2){
[Link](num + " is a prime number ");
}
else {
}
else{
}
}
package questions;
import [Link];
public class random_number {
public static void main(String[] args) {
//Apraoch1
//Aproach2
}
}
package questions;
import [Link];
import [Link];
package questions;
}
}
package questions;
import [Link];
//Approach - 1
// String s = "Welcome to java ";
//
//
// String [] words = [Link](" ");
//
//
//
// String reverseString = " ";
//
// for(String w:words){
// ;
// String reverseword=" ";
// // [Link](w);
//
// for(int j = [Link]()-1; j>=0;j--){
// reverseword=reverseword+[Link](j);
//
// }
//
// reverseString = reverseString+reverseword;
// }
//
//
// [Link](reverseString);
//Approach2
[Link](reverseword);
}
}
package questions;
import [Link];
// using algorithm
// int rev = 0;
// while (num != 0) {
//
// rev = rev * 10 + num % 10;
// num = num / 10;
// }
//
// [Link]("Reverse number is " +rev);
//logic2
//logic3
// StringBuilder sbl = new StringBuilder();
// [Link](num);
// [Link]([Link]());
}
package questions;
//logic1
//logic2
//logic3
}
}
package questions;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
while([Link]()){
[Link]([Link]());
}
[Link]();
}
catch (Exception e ){
[Link]("unable to read the data");
}
}
}
package questions;
import [Link];
if(num==arr[i]) {
[Link](arr[i] + " is present in the array ");
check=true;
if(check==false){
[Link](num + " is not present in the array ...");
}
}
package questions;
import [Link];
int n = [Link];
if(arr[j]>arr[j+1]){
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
[Link]([Link](arr));
}
package questions;
import [Link];
import [Link];
import [Link];
import [Link];
//aproach 2 -- [Link]
//
// [Link](arr);
//
// [Link]("Array elements after sorting : " +
[Link](arr));
[Link](arr,[Link]());
[Link]([Link](arr));
}
}
package questions;
int sum=0;
while(num>0){
sum=sum+num%10;
num=num/10;
}
[Link](sum);
}
}
package questions;
int sum = 0;
int [] arr = {1,2,3,4,5,6};
for(int i = 0 ; i<[Link];i++){
sum=sum+arr[i];
}
[Link](sum);
}
}
package questions;
// logic 1
int a = 10;
int b = 20;
[Link]("The values before swapping a = " + a + " b = " +
b );
//
//
// int t = a ;
// a=b;
// b=t;
//
// [Link]("The values after swapping a = " + a + " b = "
+ b );
//logic 2
// a=a+b;
// b=a-b;
// a=a-b;
//
//
// [Link]("Values after swaping a =" + a + " b = " + b
);
//logic3
// a=b/a;
// b=b/a;
// a=a*b;
//
//
// [Link]("Values after swaping a =" + a + " b = " + b
);
//logic4
//
// a=a^b;
// b=a^b;
// a=a^b;
// [Link]("Values after swaping a =" + a + " b = " + b
);
b =a+b-(a=b);
}
}
package questions;
import [Link];
try {
FileWriter fileWriter = new FileWriter("[Link]");
[Link]("The VIT legacy, which started from Vellore Engineering
College 35 years ago to " +"\n"+
"four Universities in India, today, is a result of constant efforts
to impart high " + "\n"+
"quality of education. The Govt. of India has recognized VIT as No.
1 Private Institution for " +"\n"+
"Innovation, ARIIA 2019, and the recent recognition, as an
Institution of Eminence, has paved a" +"\n"+
" way to focus more on research with international collaborations
to move up in the global ranking and " +"\n"+
"contribute in the capacity building of our nation.");
[Link]();
}
catch (Exception e){
[Link]("Unable to write unto a file ....");
}
}
}