You are here: Home / Topics / Search / java
Showing 268 Search Results for : java

Program to use setPriority( ) method of Thread in Java

Filed under: Java
//  Program to use setPriority( ) method.class A extends Thread{public void run(){ for( int i=1 ; i<=10 ; i++ ) {       System.out.println( " THREAD A = " + i ); } System.out.println( " END OF THREAD A." );}}class B extends Thread{public void run(){&nb  ......

Program 2 to create Applet with param tag in Java

Filed under: Java
//  Program to create Applet with param tag.import java.awt.*;import java.applet.Applet;/*<applet  code="AppletTest3.class" width="300" height="60"><param name="msg" value="Let's learn Applet.">  </applet>*/public class AppletTest3 extends Applet {String msg = "  ......

Program to create Applet with param tag in Java

Filed under: Java
// Program to create Applet with param tag.import java.awt.*;import java.applet.Applet;/*<applet code="AppletTest2b.class" width="300" height="100"><param name="message" value="BIIT Computer Education" /></applet>*/public class  AppletTest2b  extends  Applet {St  ......

Program to use Applet with Button and it's event in Java

Filed under: Java
// Program to use Applet with Button and it's event.import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.applet.Applet;import java.awt.Button;/*<applet code="AppletTest2.class" width="300" height="100"></applet>*/public class AppletTest2 extends Applet   ......

Program with param tag in applet tag in Java

Filed under: Java
//  Program with param tag in applet tag.import java.awt.*;import java.applet.*;/*<applet code="Applet06" width="300" height="50"><param name="message" value="Java makes the Web move!"></applet>*/public class  Applet06 extends Applet implements Runnable {String   ......

Program to display string in Status window in Java

Filed under: Java
//  Program to display string in Status window.import java.awt.*;import java.applet.*;/*<applet code="Applet04" width="300" height="50"></applet>*/public class Applet04 extends  Applet{public void init() { setBackground(Color.yellow);}public void paint(Graphics g)&nbs  ......

Program with Banner applet in Java

Filed under: Java
// Program with Banner applet.import java.awt.*;import java.applet.*;/*<applet code="Applet03" width="300" height="50"></applet>*/public class  Applet03 extends Applet implements Runnable {String msg = "Java Programming Examples";Thread t = null;boolean flag;public void in  ......

Program to use Boolean Wrapper class in Java

Filed under: Java
// Program to use Boolean Wrapper classclass  WrapperBoolean{public static void main( String args[ ] ){ Boolean b1 = new Boolean(false); Boolean b2 = new Boolean("true"); System.out.println(b1.booleanValue()); System.out.println(b2.booleanValue());}}Output:falsetrue

Program to use Simple Wrapper Class in Java

Filed under: Java
//  Program to use Simple Wrapper Class.class  Wrapper1{public static void main( String args[ ] ){ // Boxing Integer  iOb = new Integer(100); // Unboxing int i = iOb.intValue(); System.out.println(i + " : " + iOb); }}Output:100 : 100

Program to use enum in an application in Java

Filed under: Java
//  Program to use enum in an application.import java.util.Random;enum  Answers {NO, YES, MAYBE, LATER, SOON, NEVER}class Question {Random rand = new Random();Answers ask() { int prob = (int) (100 * rand.nextDouble()); if (prob < 15)  return Answers.MAYBE;   ......

Comparison in Enum example in Java

Filed under: Java
// Program to explain that enum has Ordinal// number that is used in comparison.enum  Colour {Red, Green, Blue, Black, White, Orange, Yellow}class  EnumDemo4 {public static void main(String args[ ]){ Colour c1, c2, c3; // Obtain all ordinal values using ordinal().   ......

Program to use Java Enum as a Class type in Java

Filed under: Java
//  Program to use Java Enum as a Class type.enum Colour {Red(200), Green(150), Blue(100), Black(250), White(175), Orange(225), Yellow(125);private int price;   // price of each colourColour(int p) {  price = p; }int getPrice() {  return price;   ......

Program to use Enumeration Named Constants in Java

Filed under: Java
//  Program to use Enumeration Named Constants.enum Colour {Red, Green, Blue, Black, White, Orange, Yellow}class EnumDemo1 {public static void main(String args[ ]){ Colour c1; c1 = Colour.Red; System.out.println("Value of c1: " + c1); c1 = Colour.Blue; if(c1 =  ......

Chained exception example in Java

Filed under: Java
//  Program to explain Chained Exception.class  ChainedException{static void demoproc() { NullPointerException e = new NullPointerException("top layer"); e.initCause(new ArithmeticException("cause")); throw e;}public static void main(String args[ ]) { try   ......

User defined exception example 2 in Java

Filed under: Java
//  Program to create User-defined Exception//  for checking validity of number for Square root.class NegativeNumberException extends Exception {private double num;NegativeNumberException(double n) { num = n;}public String toString() { return "Square root of " + nu  ......

User defined exception example in Java

Filed under: Java
// Program to create User-defined Exception// for checking validity of age.class InvalidAgeException extends Exception {private int age;InvalidAgeException(int a) { age = a;}public String toString() { return "Age: " + age + " is not a valid age.";}}class  Exception14&nb  ......

Finally block example in Java

Filed under: Java
// Program to use finally Block with exception handling.class  finallyBlockWithException{// Through an exception out of the method.static void procA() { try  {  System.out.println("inside procA");  throw new RuntimeException("demo"); }  finally   ......

Throw statement example in Java

Filed under: Java
//  Program to use throw statement to raise exception and rethrow the exception.class  ThrowExceptionExample {static void demoproc() { try  {  throw new NullPointerException("demo"); }  catch(NullPointerException e)  {  System.out  ......

Nested try catch block example in Java

Filed under: Java
//  Program to explain Nested Try-Catch Block.class NestedTryCatch{public static void main(String args[ ]) { try  {  int a = args.length;  int b = 10 / a;  System.out.println("a = " + a);  try   {    if(a==1)     a   ......

Order of exception subclass and superclass in Java

Filed under: Java
//Program to explain that, when we use multiple catch statements, it is //important to remember that exception subclasses must come before any of their superclasses.class  MultipleException{public static void main(String args[ ]) { try  {  int a = 0;  int b =   ......

Multiple catch block example in Java

Filed under: Java
// Program to use Multiple Catch Block with Exception.class Exception05 {public static void main(String args[ ]) { try  {  int a = args.length;  System.out.println("a = " + a);  int b = 10 / a;  int c[ ] = { 1 };  c[10] = 100; }  catch  ......

Try and catch example in Java

Filed under: Java
//  Simple try and catch example for exception handlingclass  SimpleTryCatchExample {public static void main(String args[ ]) { int d, a; try  {   d = 0;  a = 10 / d;  System.out.println("This will not be printed."); }  catch   ......

Stack trace of default Exception Handler of JVM

Filed under: Java
// Program without Exception Handling and // stack trace of Default Handler of JVM.class  DefaultException2 {static void subroutine() { int d = 0; int a = 10 / d;}public static void main(String args[ ]) { Exception02.subroutine();}}Output:Exception in thread "  ......

Default Exception Handler of JVM

Filed under: Java
// Simple  Program without Exception Handling and // use of Default Handler of JVM.class  DefaultException{public static void main(String args[ ]) { int  d = 0; int  a = 10 / d; // here JVM automatiically handle exaception}}Output:Exception in thread "mai

program to explain static import for static Field in Java

Filed under: Java
// program to explain static import for static Field.import java.util.Scanner;import static java.lang.Math.PI;class StaticImport2{public static void main( String args[ ] ){ double r, a; Scanner sc = new Scanner( System.in );  System.out.print("Enter Radius : "); r = sc.nextD  ......

Program to explain static import statement in Java

Filed under: Java
//  program to explain static import statement.import static java.lang.Math.*;//   import static java.lang.Math.sqrt;class StaticImport{public static void main( String args[ ] ){ double a = 3.0, b = 4.0; double c = sqrt( a*a + b*b ); System.out.println(" C = " + c );}} 

Import with * sign example in Java

Filed under: Java
//  import with * sign.import  java.util.*;class  ImportTest2{public static void main( String args[ ] ){ double r, a; Scanner sc = new Scanner( System.in );  System.out.print("Enter Radius : "); r = sc.nextDouble();  a = 3.14 * r * r;  Syst

Using class without import in Java

Filed under: Java
//  Using class without import.class  ImportTest{public static void main( String args[ ] ){ double  r, a; java.util.Scanner sc = new java.util.Scanner( System.in );  System.out.print("Enter Radius : "); r = sc.nextDouble();  a = 3.14 * r * r; &n

Using class with import example in Java

Filed under: Java
//  Using class with import.import java.util.Scanner;class ImportTest2{public static void main( String args[ ] ){ double r, a; Scanner sc = new Scanner( System.in );  System.out.print("Enter Radius : "); r = sc.nextDouble();  a = 3.14 * r * r;  Syste

Visibility control in another package example in Java

Filed under: Java
// Program to  Visibility Control in Another Package.// First File ( Base.java ) in package p1package  p1;public class  Base {private int n_pri = 1;int n_def = 2;protected int n_pro = 3;public int n_pub = 4;public Base() { System.out.println("base constructor"); Sy  ......

Program to explain Importing Package example in Java

Filed under: Java
//  Program to explain Importing Packagepackage MyPack;public class  Balance {String name;double bal;public Balance(String n, double b) { name = n; bal = b;}public void show() { if(bal<0)  System.out.print("--> "); System.out.println(name + ":   ......

Program to explain Creating Package in Java

Filed under: Java
//  Program to explain Creating Package.package MyPack;class  Balance {String name;double bal;Balance(String n, double b) { name = n; bal = b;}void show() { if(bal<0)  System.out.print("--> "); System.out.println(name + ": Rs. " + bal);}}class   ......

Program to explain Importing Package in Java

Filed under: Java
// Program to explain Importing Package.package  Pack1;public class  First{public void view( ){ System.out.println( "This is First Class." );}}// Second File as (ImportPack1.java in current folder) :import Pack1.*;public class  ImportPack1{public static void main( String args[ ] 

Creating package example in Java

Filed under: Java
// Program to explain Creating Package.package  Pack1;class First{public void view( ){ System.out.println( "This is First Class." );}}public class  ImportPack2{public static void main( String args[ ] ){ First f = new First(); f.view();}} Output:This is First Class.

Polymorphism with interface example in Java

Filed under: Java
//  Polymorphism  with interface exampleinterface Shape{void draw();}class Rectangle implements Shape{public void draw(){ System.out.println("Drawing Rectangle.");}}class Triangle implements Shape{public void draw(){ System.out.println("Drawing Triangle.");}}class  Polymorph  ......

Program to explain Inheritance of a interface in Java

Filed under: Java
//  Program to explain Inheritance of a interface//  from another interface.interface AInterface{void showA();}interface BInterface extends AInterface {void showB();}class Test  implements BInterface{public void showA(){ System.out.println("showA() of A interface.");}public   ......

Use fields in interface example in Java

Filed under: Java
//  Program to use field in interface.interface AInterface{int  SIZE = 100;void  showA();}class Test  implements  AInterface{public void showA(){ System.out.println("showA() of A interface."); System.out.println("SIZE = " + SIZE);}}class  InterfaceTest2{public  ......

Simple interface example in Java

Filed under: Java
//  Program to use Simple Interface.interface  AInterface{void showA();}class Test  implements  AInterface{public void showA(){ System.out.println("showA() of A interface.");}}class  InterfaceTest1{public static void main( String args[ ] ){ Test  t1 = new Test  ......

Program to explain final method restricts in Java

Filed under: Java
//  Program to explain final method restricts //  (not allow) the overriding of that methodclass  A{final void display(){ System.out.println(" A\'s display().");}}class  B extends A{// final method can't be override.// void display()void show(){ System.out.println(  ......

Program to explain final class restricts (not allow) in Java

Filed under: Java
// Program to explain final class restricts (not allow) // the inheritance from that class.final class A{void display(){ System.out.println(" A\'s display().");}}// final class can't be inherited.// class B extends A // Errorclass B{void display(){ System.out.println(" B\'s display().  ......

Program to explain Polymorphism with abstract class in Java

Filed under: Java
//  Program to explain Polymorphism with abstract class.abstract class Shape{abstract void draw();}class Rectangle extends Shape{void draw(){ System.out.println("Drawing Rectangle.");}}class Triangle extends Shape{void draw(){ System.out.println("Drawing Triangle.");}}class  Poly  ......

Program to explain Polymorphism in Java

Filed under: Java
//  Program to explain Polymorphism or //  Dynamic Method Dispatch or Run Time Binding.class  Shape{void draw(){ System.out.println("Drawing Shape.");}}class  Rectangle extends Shape{void draw(){ System.out.println("Drawing Rectangle.");}}class  Triangle exten  ......

Method overriding example in Java

Filed under: Java
// Program to explain Method Overriding.class  A {int  i,  j;A(int a, int b) { i = a; j = b;}void show() { System.out.println("i and j: " + i + " " + j);}}class  B extends A {int  k;B(int a, int b, int c) { super(a, b); k = c  ......

Method Overloading example in Java

Filed under: Java
// Program to explain Method Overloading.class  A {int i, j;A(int a, int b) { i = a; j = b;}void show() { System.out.println("i and j: " + i + " " + j);}}class  B extends A {int k;B(int a, int b, int c) { super(a, b); k = c;}void show(Strin  ......

Hierarchical inheritance example in Java

Filed under: Java
//  hierarchical inheritance exampleclass student1{   private String name;   private int rno;      void setname(String name, int rno)   {       this.name = name;       this.rno = rno;   }  &  ......

Use of this keyword example in Java

Filed under: Java
//  Program to use this keywordclass n {   public int i;   int getI() {       return i;   }}class M extends n {   int a, b;   void sum(int a, int b) {       int d = getI();       this.a  ......

Multilevel inheritance example in Java

Filed under: Java
//  Program to explain Multilevel Inheritance.class Box {private double width;private double height;private double depth;Box(Box ob) {  width = ob.width; height = ob.height; depth = ob.depth;}Box(double w, double h, double d) { width = w; height = h;  ......

Simple Inheritance Example 2 in Java

Filed under: Java
// Simple Inheritance example 2class  A {int i, j;void showij() { System.out.println("i and j: " + i + " " + j);}}class B extends A {int k;void showk() { System.out.println("k: " + k);}void sum() { System.out.println("i+j+k: " + (i+j+k));}}class  Inh  ......

Simple Inheritance Example in Java

Filed under: Java
// Simple Inheritance examplepublic class SimpleInheritance{   public static void main(String[] args) {       SubClass ob1 = new SubClass();       ob1.showmsgSuper();       ob1.showmsgSub();   }}class SuperClass{  &  ......

Array of String Example in Java

Filed under: Java
// Program to explain the concept of "ARRAY OF STRING".class  StrArray{public static void main( String args[ ] ){ final int days = 7; String str[ ] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"   };   for( int  j=0 ; j<day  ......

stringBuffer reverse () method example in Java

Filed under: Java
// Program to explain the following StringBuffer function :// StringBuffer reverse()class  Mreverse{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." ); System.out.println( " String = " + sb );  sb.reverse(); Sys  ......

stringBuffer replace () method example in Java

Filed under: Java
// Program to explain the following StringBuffer function :// StringBuffer replace( int startIndex, int endIndex, String str )class  Mreplace1{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." ); System.out.println( " String =   ......

stringBuffer insert(index, obj) function example in Java

Filed under: Java
// Program to explain the following StringBuffer function :// StringBuffer insert( int index, Object ob )class  Minsert1{public static void main(String args[ ]){ StringBuffer sb = new StringBuffer(40); sb = sb.insert(0, 'A'); System.out.println(" String 1 = " + sb);  sb  ......

stringBuffer insert() method example in Java

Filed under: Java
// Program to explain the following StringBuffer function :// StringBuffer insert( int index, String str )class  Minsert{public static void main( String args[ ] ){ String s = new String( "Java" ); StringBuffer sb = new StringBuffer( " Examples." ); sb = sb.insert( 0, s ); Sy  ......

stringBuffer deleteCharAt() method in Java

Filed under: Java
// Program to explain the following StringBuffer function :// StringBuffer deleteCharAt( int loc )class  MdeleteCharAt{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." ); System.out.println( " String = " + sb );  sb   ......

stringBuffer delete function in Java

Filed under: Java
// Program to explain the following StringBuffer function ://StringBuffer delete( int startIndex, int endIndex )class  Mdelete{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." ); System.out.println( " String = " + sb ); &  ......

toString() method in spring buffer in Java

Filed under: Java
// Program to explain the following StringBuffer function ://String toString()class  MtoString{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( "Java Programming Examples." );  String s = sb.toString(); System.out.println( " String = " + s );&nb

subString() method example in stringBuffer in Java

Filed under: Java
// Program to explain the following StringBuffer function ://String substring( int startIndex )//String substring( int startIndex, int endIndex )class  Msubstring1{public static void main( String args[ ] ){ StringBuffer sb1 = new StringBuffer( "Java Programming Examples." );  Sys  ......

setLength() method example in Java

Filed under: Java
// Program to explain the following StringBuffer function :// void setLength( int len )class  MsetLength{public static void main(String args[ ]){ StringBuffer sb1 = new StringBuffer("Java Programming Examples."); System.out.println(" String = " + sb1); sb1.setLength(12); Sys  ......

Use of setCharAt() method in Java

Filed under: Java
// Program to explain the following StringBuffer function :// void setCharAt( int where, char ch )class  MsetCharAt1{public static void main( String args[ ] ){ StringBuffer sb1 = new StringBuffer( "Java Nrogramming Examples." ); System.out.println( " String Before Replacing = " + sb1   ......

capacity() method example in Java

Filed under: Java
// Program to explain the following StringBuffer function :// int capacity()class  Mcapacity{public static void main( String args[ ] ){ StringBuffer sb1 = new StringBuffer(); StringBuffer sb2 = new StringBuffer( "Java Programming Examples" ); System.out.println( " Capacity = " +   ......

stringBuffer append example in Java

Filed under: Java
// Program to explain the following StringBuffer function :// StringBuffer append( char c )class  Mappend1{public static void main( String args[ ] ){ StringBuffer sb = new StringBuffer( 40 ); sb = sb.append( 'J' ); System.out.println( " String 1 = " + sb );  sb.append(   ......

stringBuffer() example in Java

Filed under: Java
// Program to explain the following StringBuffer function :// StringBuffer()// StringBuffer( int size )// StringBuffer( String str )class  MStringBuffer1{public static void main(String args[ ]){ StringBuffer sb = new StringBuffer("Java");  System.out.println(" sb = " + sb );   ......

lastIndexOf() method example in Java

Filed under: Java
// Program to explain the following String function :// int lastIndexOf( String str )class  MlastIndexOf{public static void main( String args[ ] ){ String s1 = "Java Programming Examples Java Programming Examples.";    System.out.println( " Last Index of " + 'P' + " = " + s1  ......

index of() method example in Java

Filed under: Java
// Program to explain the following String function :// int indexOf(int ch) // int indexOf( String str )class  MindexOf{public static void main(String args[ ]){ String s1 = "Java Programming Examples Java Programming Examples.";    System.out.println(" Index of " + 'P'   ......

subString() method example in Java

Filed under: Java
// Program to explain the following String function :// String substring( int startIndex )// String substring( int startIndex, int endIndex )class  Msubstring{public static void main( String args[ ] ){ String s1 = "Java Programming Examples.";   String s2 = s1.substring( 5 )  ......

valueOf() method example in Java

Filed under: Java
//  Program to explain the following String function ://  static String valueOf( double num )class  MvalueOf {public static void main( String args[ ] ){ char  ch[ ] = { 'J', 'A', 'V', 'A' }; String s1 = String.valueOf( ch ); System.out.println( " String 1 : "   ......

trim() method example in Java

Filed under: Java
// Program to explain the following String function :// String  trim()class  Mtrim{public static void main( String args[ ] ){ String s = "            Java Programming Examples.           ".trim(); System.out.print( "String af

toUpperCase() method example in Java

Filed under: Java
// Program to explain the following String function :// String toUpperCase()class  MtoUpperCase{public static void main( String args[ ] ){ String s1 = "Java Programming Examples"; String s2 = s1.toUpperCase(); System.out.println( " Original  String : " + s1 ); System.ou  ......

toLowerCase() method example in Java

Filed under: Java
// Program to explain the following String function : // String toLowerCase()class  MtoLowerCase{public static void main( String args[ ] ){ String s1 = "Java Programming Examples."; String s2 = s1.toLowerCase(); System.out.println( " Original  String : " + s1 ); Sy  ......

split() method example in Java

Filed under: Java
// Program to explain the following String function :// String[ ] split( Stirng regExp )class  Msplit{public static void main( String args[ ] ){ String s1 = new String( "Java Programming Examples" ); String s2[ ] = s1.split( " " ); System.out.println( " String = " + s2[0] );   ......

regionMatches() method example in Java

Filed under: Java
// Program to explain the following String function :// boolean regionMatches( int startIndex,// String str2, int str2StartIndex, int numChars )class  MregionMatches1 {public static void main(String args[ ]){ boolean b,b1; String s1 = new String("Java Programming Examples.");&nbs  ......

getChars() method example in Java

Filed under: Java
// Program to explain the following String function :// void getChars( int sourceStart, int sourceEnd,// char target[], int targetStart )class  MgetChars{public static void main( String args[ ] ){ char  ch[ ] = new char[4]; String s1 = "Java Programming Examples.";  &nb  ......

compareTo() method example in Java

Filed under: Java
// Program to explain the following String function :// int compareTo( String str )class  McompareTo{public static void main( String args[ ] ){ String s1 = "JAVA"; String s2 = "JAVA"; String s3 = "Java";    System.out.println( s1 + " compared to " + s2 + " = " + s1  ......

Difference between equals and == operator in Java

Filed under: Java
// Program to explain the following String function :// equals versus ==class  MequalsVersusEqualto{public static void main( String args[ ] ){ boolean b; String s1 = "JAVA"; String s2 = "JAVA"; String s3 = "Java"; String s4 = new String( "JAVA" ); String s5 = new S  ......

equalsIgnoreCase() function example in Java

Filed under: Java
// Program to explain the following String function :// boolean equalsIgnoreCase( Object str )class  MequalsIgnoreCase{public static void main( String args[ ] ){ String s1 = "JAVA";  String s2 = "JAVA"; String s3 = "Java"; System.out.println( s1 + " equals " + s2 + " =   ......

length() function example in Java String

Filed under: Java
// Program to explain the following String function :// int length()class  Mlength{public static void main( String args[ ] ){ char ch[ ] = { 'J', 'A', 'V', 'A' }; String s1 = new String( ch ); System.out.println( " String = " + s1 ); System.out.println( " Length = " + s1.len  ......

Java Program to use charAt function in string

Filed under: Java
// Program to explain the following String function :// char charAt( int where )class  McharAt{public static void main( String args[ ] ){ char ch; String s1 = "Nils";   ch = s1.charAt( 0 ); System.out.println( " Character at 0 : " + ch ); ch = "Java".charAt( 3  ......

Make string using ASCII value in Java

Filed under: Java
// Program to explain the following String function :// String( byte asciiChars[ ] )class  MString4{public static void main( String args[ ] ){ char ch[ ] = { 'J', 'A', 'V', 'A' }; String s1 = new String( ch ); byte b[ ] = { 65, 66, 67, 68, 69, 70 }; String s2 = new String( b  ......

Simple string function example in Java

Filed under: Java
// Program to explain the following String function :// String(char chars[ ], int startIndex, int numChars)class  MString2{public static void main( String args[ ] ){ char ch[ ] = { 'J', 'A', 'V', 'A' }; String s = new String( ch, 2, 2 ); System.out.println( " String = " + s );&nb  ......

Simple string example in Java

Filed under: Java
// Program to explain the following String function :// String( String strObj )class  MString11{public static void main( String args[ ] ){ String s1 = "Nils : " + 5 + 5;  String s2 = "Nils : " + (5 + 5); System.out.println( s1 ); System.out.println( s2 );}}Output:Nils :

Initialise 2D array in Java

Filed under: Java
// Program to initialize 2D array with expressionclass  InitTwoDWithExp {public static void main(String args[ ]) { double a[ ][ ] = {   { 0*0, 1*0, 2*0, 3*0 },   { 0*1, 1*1, 2*1, 3*1 },   { 0*2, 1*2, 2*2, 3*2 },   { 0*3, 1*3, 2*3, 3*3 } };&  ......

Jagged array example in Java

Filed under: Java
//  Program to explain Jagged Arrayclass  JaggedArray2 {public static void main(String args[ ]) { int ar[ ][ ] = new int[4][ ]; ar[0] = new int[1]; ar[1] = new int[2]; ar[2] = new int[3]; ar[3] = new int[4]; int  i, j, x = 1; for( i=0 ; i &  ......

Jav Program to find sum of two matrices

Filed under: Java
// Program to addition of two Matrixclass  MatrixAddition{public static void main( String args[ ] ){ int  i, j; int  c[ ][ ] = new int[3][3];  int  a[ ][ ] = {      {1, 2, 3},     {4, 5, 6},     {7, 8, 9}  };&n  ......

Transpose of the array in Java

Filed under: Java
//Program to find transpose of the Matrixclass  MatrixTranspose{public static void main( String args[ ] ){ int i, j; int  b[ ][ ] = new int[3][3];  int   a[ ][ ] = {      {1, 2, 3},    {4, 5, 6},      {7, 8, 9}  };   ......

Matrix of array example in Java

Filed under: Java
// print simple matrix of arraypublic class PrintingInMatrixFormat{   public static void main(String[] args)   {       int i,j;       int a[][]=new int[3][3];       a[0][0]=10;       a[0][1]=20;   ......

Iterate 2D array in Java

Filed under: Java
// Program to use Two dimensional Arrayclass TwoDArray {public static void main(String args[ ]) { int a[ ][ ]= new int[2][3]; int i, j, x = 1; for(i=0; i<2; i++) {  for(j=0; j<3; j++)   {   a[ i ][ j ] = x;   x++;  } }&  ......

Program for Sum of 2D array elements in Java

Filed under: Java
// Sum Of Array Elementspublic class SumOfArrayElements{   public static void main(String[] args) {       int i, j, sum = 0;       int a[][] = {{10, 20, 30}, {40, 50, 60}, {70, 80, 90}};       for (i = 0; i < 3; i++) {  &n  ......

Merge sort example in Java

Filed under: Java
// Program to Implement Merge Sortimport java.util.Scanner;public class MergeSort {   /* Merge Sort function */   public static void sort(int[] a, int low, int high)    {       int N = high - low;           &nb  ......

Quick sort example in Java

Filed under: Java
// Java Program to Implement Quick Sortimport java.util.Scanner; public class QuickSort {   /** Quick Sort function **/   public static void sort(int[] arr)   {       quickSort(arr, 0, arr.length - 1);   }   /** Quick so  ......

Selection sort example in Java

Filed under: Java
// Program to SORT the Array elements using SELECTION SORTclass  SelectionSort{public static void main( String args[ ] ){ int  i, j; int  a[ ] = { 40, 20, 50, 10, 30 };  System.out.print( "\n Unorted Numbers are = " ); for( i=0 ; i<5 ; i++ ) {  Sy  ......

Insertion sort example in Java

Filed under: Java
//  Program to SORT the Array elements using INSERTION SORTclass  InsertionSort{public static void main( String args[ ] ){ int  a[ ] = { 0, 20, 40, 10, 50, 30 }; int i, n = 5; System.out.print( " The Unsorted Array is = " ); for( i=1 ; i<=n ; i++ ) {    ......

Bubble sort example in java

Filed under: Java
// Program to SORT the Array elements using BUBBLE SORTclass  BubbleSort{public static void main( String args[ ] ){ int i, j, t; int  a[ ] = { 40, 20, 50, 10, 30 };  System.out.print( "\n Unorted Numbers  are = " ); for( i=0 ; i<5 ; i++ ) {  Syste  ......

Fibonacci series using Array in Java

Filed under: Java
//  Program to Print the Fibonacci Series using Array.class  FiboArray{public static void main( String args[ ] ){ int n, i; int  a[ ] = new int[20];   n = 10; a[0] = 0;   a[1] = 1;   for(i=2 ; i<n ; i++)    {  a[  ......

Program to arrange array in Ascending order in Java

Filed under: Java
// Arrange Array in Ascending orderpublic class ArrayAscending {   public static void main(String[] args) {       int i, temp, j;       int a[] = {1, 7, 5, 9, 2, 12, 53, 25};System.out.println("Before Ascending order:");for (i = 0; i < 8; i++) {&n  ......

Read array from keyboard in Java

Filed under: Java
//  Read array from keyboardimport java.util.*;class  ArrayTest{public static void main( String args[ ] ){ Scanner sc = new Scanner( System.in ); int  i; int  a[ ] = new int[5];  for( i=0 ; i<5 ; i++ ) {  System.out.print( "Enter Value : " );  ......

Simple static Array example in Java

Filed under: Java
// Simple static arraypublic class SimpleArray{   public static void main(String[] args)    {       int a[]={10,20,30,40,50};       for(int i=0;i<5;i++)       {           System.out.

How to Add Jar Files in Library of project in IntelliJ Idea

Filed under: Java
Hello Developers, If you stuck to find how to add jar files in library of your project in IntelliJ Idea follow below steps:Open your IntelliJ idea and open the project on which you are working.You will see a setting icon on top right corner of your screen. Click on that and select project struc  ......

Do while Loop example in Java

Filed under: Java
// Do while exampleclass  DoWhileTest{public static void main( String args[ ] ){ int   i = 1; // 1.  Initialization do {  System.out.print( "  " + i );  i++; // 3.  Increment. }while ( i <= 5 ); // 2.  Test / Condition}}Output: 1 &n

Program to check Armstrong number in Java

Filed under: Java
An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.Code// Program to check whether a given Number is// ArmStrong Number or not.class  ArmstrongTest{p  ......

Program to find Strong number in Java

Filed under: Java
What is strong number?Strong number is a special number whose sum of the factorial of digits is equal to the original number. For Example: 145 is strong number. Since, 1! + 4! + 5!Code//Program to Check the given Number is STRONG Number or not.// Logic 145 = 1! + 4! + 5!  (i.e.,  145 = 1 +  ......

Count number of digits in any given number in Java

Filed under: Java
// count number of given digitsclass  NumberOfDigits{public static void main( String args[ ] ){ int n, c;  n = 1234; c = 0; while( n != 0 ) {  n = n / 10;  c++; } System.out.println( " Number of Digits : " + c );}}Output:Number of Digits : 4

Nested while Loop example in Java

Filed under: Java
// Nested while loop examplepublic class NestedWhile{   public static void main(String[] args) {       int a = 1, b;       while (a <= 5) {           b = 1;           while (b <= a) {&  ......

While Loop Example in Java

Filed under: Java
// simple while loop examplepublic class WhileLoop{   public static void main(String[] args) {       //learning       int a = 1;       while (a <= 5) {           System.out.println(" "+a);  &n  ......

For each loop example 2 in Java

Filed under: Java
// for each loop exampleclass  ForEachTest {public static void main( String args[ ] ){  int  ar[ ] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };   for(int  x : ar)    { System.out.print(x + " ");  x = x * 10;  // no effect on num  ......

For each loop example in Java

Filed under: Java
// foreach examplepublic class ForEachLoop {   public static void main(String[] args) {       int arrayname[] = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21};//learn       for (int val : arrayname) {           System.out.print  ......

Advance for loop example in Java

Filed under: Java
public class AdvancedForLoop {   public static void main(String[] args) {             String s1 = "INDIA";       char s2[] = new char[s1.length()];       for (int i = 0; i < s1.length(); i++) {      ......

Program to find HCF and LCM of two numbers in Java

Filed under: Java
 // Program to find HCF and LCM of Two given Number.import java.util.Scanner;class  HcfAndLcmExample{public static void main( String args[ ] ){ int a, b, i, s, hcf=0, lcm=0; Scanner sc = new Scanner( System.in );  System.out.print( " Enter First Number : " ); a = s  ......

Program to check whether given number is Perfect or not in Java

Filed under: Java
Before proceeding to our program code, we must see what is perfect number.What is perfect number?In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3 (excluding itself), and 1   ......

Program to Print Lucas series in Java

Filed under: Java
// Program to Print the Lucas Series.//  1  1  1  3  5  9.....n  Terms.class  LucasTest {public static void main( String args[ ] ){ int n, i , a = 1, b = 1, c = 1, d;   n = 10; System.out.print( " " + a + " " + b + " " + c);    ......

Print Fibonacci numbers example using Java

Filed under: Java
//  Program to Calculate the Fibonacci Series of the Given Number.class  FibonacciTest {public static void main( String args[ ] ){ int n, i , a = 0, b = 1, c = 0;   n = 6; System.out.print( " " + a + " " + b );    for( i=1 ; i<=(n-2) ; i++ )&  ......

Continue statement example in Java

Filed under: Java
// continue staement examplepublic class ContinueStatement{   public static void main(String[] args) {       for (int i = 0; i < 10; i++) {                       if (i % 2 == 0) {          ......

Break statement example in Java

Filed under: Java
// Break startment in for loop examplepublic class BreakStatement{   public static void main(String[] args) {       for (int i = 0; i < 10; i++) {           System.out.println(i);           if(i==5){  &  ......

Square Pattern of star logic in Java

Filed under: Java
//pattern using for and whilepublic class ForPattern{   public static void main(String[] args) {       int i, j;       for (i = 1; i <= 5; i++) {           for (j = 1; j <= 5; j++) {        &nbs  ......

Print star Patter 2 logic in Java

Filed under: Java
// for loop and while looppublic class ForWhile {   public static void main(String[] args) {       for (int i = 1; i <= 5; i++) {           int j = i;           while (j <= 5) {         ......

Print star patter 1 logic in Java

Filed under: Java
// For loop patternpublic class NestedFor {   public static void main(String[] args) {       for (int i = 0; i < 5; i++) {           for (int j = 0; j <= i; j++) {               System.out.print  ......

Sum of Even and Odd using For Loop in Java

Filed under: Java
This program will print sum of Even numbers and odd numbers separately.// sum of even odd using while loopclass OddEvenSum {   public static void main(String[] args) {       int i;       int sum = 0;       int sum1 = 0;  &nbs  ......

Get Sum of n numbers using For Loop in Java

Filed under: Java
This program will print the sum of n numbers. // sum of numbers using command lineclass  ArguSum{   public static void main( String args[ ] )   { int  s = 0, len; len = args.length;  for( int i=0 ; i<len ; i++ ) {  int  x = Int  ......

Simple for loop example in Java

Filed under: Java
Here we have made a simple for loop example in Java.// Simple for loop examplepublic class ForLoop{   public static void main(String[] args) {       for (int i = 0; i < 5; i++) {           System.out.println("Loop : "+i);    &n

String Literal in case of Switch in Java

Filed under: Java
//  Program to use String literal in case of switch-case statementimport java.util.*;class  SwitchString{public static void main(String args[ ]){ String dname; Scanner sc = new Scanner( System.in );  System.out.print( " Enter Day Name = " ); dname = sc.next();   ......

Type of byte using Switch case in Java

Filed under: Java
// Switch case examplepublic class SwitchCase{   public static void main(String[] args) {       int choice = 1;       switch (choice) {           case 0:               System.out.p  ......

Find Odd Even using Switch statement in Java

Filed under: Java
// Even odd using switch caseclass  EvenOdd{public static void main(String args[ ]){ for( int i=1 ; i<=10 ; i++ ) {  switch( i )  {   case 1:   case 3:   case 5:   case 7:   case 9:    System.out.println( i + " -  ......

Simple Switch case example in Java

Filed under: Java
// Simple switch case exampleclass SwitchDemo {public static void main( String args[ ] ){ int  a = 2;  switch (a)  {  case 1 :   System.out.println("One.");   break;  case 2 :   System.out.println("Two.");   break;&  ......

Program to find leap year in Java

Filed under: Java
// Program to find given year is leap year or notclass  Leap2{public static void main( String args[ ] ){ int y; y = 2016; if( y % 100 == 0 ) {  if( y % 400 == 0 )   System.out.println( " It is a LEAP Year." );  else   System.out.println( " It is  ......

Nested if-else example in Java

Filed under: Java
// Program to find Maximum of Three numbers using Nested-If.class Max3IfElse{public static void main( String args[] ){ int a, b, c, max; a = 23; b = 93; c = 10; if( a > b ) {  if( a > c )   max = a;  else   max = c;       ......

Nested if example in Java

Filed under: Java
//  Nested if examplepublic class NestedIf{  public static void main(String[] args) {  int a = 10;    if(a>0){      if(a<=10){          System.out.println("a --> 0 to 10");      }      &  ......

Program to find Odd Even in Java

Filed under: Java
// Simple if else to find even odd numberclass EvenOddTest{public static void main( String args[] ){ int n; n = 23; if( n % 2 == 0 )  System.out.println("Number " + n + " is Even Number." ); else  System.out.println("Number " + n + " is Odd Number." );}}Output:Number 23

Program to Find maximum number in Java

Filed under: Java
// Simple if else examplepublic class IfElse{   public static void main(String[] args)    {      int a = 23, b = 47, c;        if(a>b)      {          System.out.println("a is greater than b")  ......

If else example in Java

Filed under: Java
//  Simple if else exampleclass IfElse{public static void main( String args[ ] ){ int  n;  n = 23; if( n > 100 ) {  System.out.println( " The number is greater than 100." ); }  else {  System.out.println( " The number is smaller tha

Simple If statement example in Java 2

Filed under: Java
// Simple if examplepublic class SimpleIf{   public static void main(String[] args) {       int a = 10;       int b = 20;              if(a>b){           System.out.println("a i  ......

Simple If statement example in Java

Filed under: Java
// Simple if exampleclass  SimpleIf{public static void main(String args[ ] ){ int  n;  n = 230; if( n > 100 ) {  System.out.println( " The number is greater than 100." ); }}}Output:The number is greater than 100.

Program to explain Implicit in Java

Filed under: Java
// Program to explain Implicit Conversion ( Automatic Type Conversion )class ImplicitConversion{public static void main( String args[ ] ){ Int  i = 2; float  f = 12.33f; byte  b = 1;  double d = 124.097; double  res = ( i - b ) * ( d / f );  &nb

Type Casting Example in Java

Filed under: Java
//  Program to explain Type Casting ( Explicit Conversion )class TypeCasting{public static void main( String args[ ] ){ int a; float b = 123.333f; System.out.println( " Before Casting = " + b ); a = (int) b;  System.out.println( " After Casting  = " + a );}}Ou

Conditional Operators Examples 2 in Java

Filed under: Java
// Program to find the Largest of three given numbers using Conditional Operatorclass MaxOf3ConditionalOperator{public static void main( String args[ ] ){ int a, b, c, max = 0; a = 20; b = 30; c = 45;    max = ((a>b) ? ((a>c) ? a : c ) : ((b>c) ? b : c )); 

Conditional Operators Examples in Java

Filed under: Java
//Program to explain the concept of Conditional Operator in different styleclass ConditionalOperator{public static void main( String args[ ] ){       int a, b, max; a = 25; b = 14; max = ( ( a > b ) ? a : b ); System.out.print("\nMaximum Value is= " + max )

Boolean Logical Operator Example in Java

Filed under: Java
//  Program to use Boolean Logical Operators ( &, |, ^, !  )class  BoolLogic {public static void main(String args[ ]) { boolean a = true; boolean b = false;  boolean c = a | b; boolean d = a & b; boolean e = a ^ b; boolean f = !a;&n  ......

Modulus Operator example in Java

Filed under: Java
// Program to use Modulus  operator ( % )class Modulus {public static void main(String args[ ]) { int x = 42; double y = 42.25; System.out.println("x mod 10 = " + x % 10); System.out.println("y mod 10 = " + y % 10);}}Output:x mod 10 = 2 y mod 10 = 2.25

Decrement Operator example in Java

Filed under: Java
// Decrement Operator Exampleclass DecrementOperatorExample{public static void main( String args[ ] ){ int a = 10, b = 20 ,c;  c = ( --a ) + ( --b ); //c = ( a-- ) + ( b-- );  System.out.println( " Value of a = " + a ); System.out.println( " Value of b = " + b );&n

Increment Operator Example in Java

Filed under: Java
// Increment Operator exampleclass  IncrementOperatoeExample{public static void main( String args[ ] ){ int a = 10, b = 20 ,c;  c = ( ++a ) + ( ++b );  // a++ is Post fix increment // ++b is pre fix increment  System.out.println( " Value of a = " + a );&n  ......

Logical Bitwise Operators Examples in Java

Filed under: Java
//Program to use Logical Bitwise Operatorsclass BitwiseOperatorExample{public static void main(String args[ ]) { int a = 3, b = 6, c; System.out.println("a = " + a); System.out.println("b = " + b); c = a & b; System.out.println("a & b = " + c);  c = a   ......

Relational Operators Examples in Java

Filed under: Java
// Program to explain the working of Relational Operatorsclass RelationalOpr{public static void main( String args[ ] ){ int a = 20, b = 10; System.out.println( " a = " + a ); System.out.println( " b = " + b ); System.out.println( " a < b = " + ( a < b ) ); System.out.p  ......

Arithmetic Operators Examples In Java

Filed under: Java
// Arithmetic Operator Exampleclass ArithOpr{public static void main( String args[ ] ){ int a = 25, b = 10; float c = 25.5f, d = 4.0f; System.out.println( " a = " + a ); System.out.println( " b = " + b ); System.out.println( " c = " + c ); System.out.println( " d = " +   ......

Exit() function example in Java

Filed under: Java
// Program to use exit() functionclass ExitTest{public static void main( String args[] ){ int a = 10; System.out.println( "AAA" ); if( a == 10 )  System.exit(0); System.out.println( "BBB" );}}Output:AAA

Use of Return in Java

Filed under: Java
// Program to use of retuen statementclass ReturnTest{public static void main( String args[] ){ int a = 10; System.out.println( "Before return." ); if( a == 10 )  return; System.out.println( "After return." );}} Output:Before return.

Take Input from User by Using Scanner Class in Java

Filed under: Java
This program will show how to use scanner class to take user input.//  Scanner exampleimport java.util.Scanner;class ScannerExample{public static void main( String args[ ] ){ Scanner sc = new Scanner( System.in ); int n;  System.out.print( "Enter a Number : "); n = sc.n  ......

Simple Sum Program Using Windows Command in Java

Filed under: Java
// Simple sum example using command lineclass  Sum{public static void main( String args[ ] ){ int  num1, num2, sum; num1 = Integer.parseInt( args[0] ); num2 = Integer.parseInt( args[1] ); sum = num1 + num2; System.out.println( " Sum = " + sum );}}Output: (In comman

Take Input from User through Console in Java

Filed under: Java
// Input using Console Exampleimport java.io.*;class ConsoleExample{public static void main( String args[ ] ){ Console cn = System.console(); int n;  System.out.print( "Enter a Number : "); n = Integer.parseInt( cn.readLine() ); System.out.println( "The given number : "

Java Program to convert days into Year, Month, Day

Filed under: Java
// Program to convert Total Number of Days into Years, Months, Weeks and remaing days.class  Days{public static void main( String args[ ] ){   int  days, years, months, weeks;   days = 1050; years = days / 365;   days = days % 365;   months  ......

Swaping of Variables using third Variable in Java

Filed under: Java
// Swapping example using third variableclass  Swap{public static void main( String args[ ] ){ int  a, b, t; a = 10; b = 20;  System.out.print( "\nBefore Swapping :" ); System.out.print( a + "   " + b ); t = a; a = b; b = t;  Syst  ......

Declare variable at the end of Java Program

Filed under: Java
// declare variable at endclass  DeclareAtEnd{public static void main( String args[ ] ){ msg = "Hello Java Developer..!";       System.out.println("Message : " + msg);}static String msg;}Output:Message : Hello Java Developer..!

How to create Local Constant in Java

Filed under: Java
// Program to using final variable within method// to create local constant.class  FinalVar1{public static void main( String args[ ] ){ double r = 10.0, a; final double PI = 3.14159; a = PI * r * r; System.out.println("Area of Circle : " + a);}}Output:Area of Circle : 314.15

Final Variable Example in Java

Filed under: Java
//  Program to use final variable to Create constant.class  FinalVar{final static double PI = 3.14159;public static void main( String args[ ] ){ double r = 10.0, a; a = PI * r * r; System.out.println("Area of Circle : " + a);}}Output:Area of Circle : 314.159

Constants in Java

Filed under: Java
// Constant exampleclass Constant1{static final int NUMBER_OF_MONTHS = 12;static final double PI = (double) 22 / 7;public static void main( String args[] ){ System.out.println("NUMBER_OF_MONTHS : " + NUMBER_OF_MONTHS ); System.out.println("PI : " + PI );}}Output:NUMBER_OF_MONTHS : 12PI : 3

Dynamic Variable Initiazation in Java

Filed under: Java
// Program to show dynamic variable initialization of variableclass  DynInit{public static void main( String args[ ] ){ double a = 8.0, b = 6.0; // c is dynamically initialized double c = Math.sqrt(a * a + b * b); System.out.println("Hypotenuse is " + c);}}Output:Hypotenuse 

Boolean Data Type in Java

Filed under: Java
// Boolean variable Exampleclass BoolTest {public static void main(String args[ ]) { boolean b; b = false; System.out.println("b is " + b); b = true; System.out.println("b is " + b); if(b) {    System.out.println("This is executed."); }}}Ou

Character Demo in Java

Filed under: Java
// Character exampleclass  CharDemo {public static void main(String args[ ]) { char  aChar, bChar; aChar = 88;   // code for X bChar = 'Y'; System.out.print("aChar and bChar : "); System.out.println(aChar + " " + aChar); aChar++;    //  ......

Java Program Comments

Filed under: Java
// Simple example of commentsclass Comments{// Your program begins with a call to main().// this is single line commentpublic static void main( String args[ ] ){ System.out.println("Java Programming Examples");/*   This is multiline comment  with multiple lines*/}}Output:Java Pro

Java Program for Calculating Interest

Filed under: Java
// Simple example to calculate Interestclass  CompInterest{public static void main( String args[ ] ){ double a, p, r ,n ,ci; p = 1000; r = 10; n = 3;      a = p * Math.pow(( 1 + ( r / 100.0 ) ), n );      ci = a - p;     System.ou  ......

Java Program for Area Of Triangle

Filed under: Java
// Program to find area of triangleclass   AreaTriangle{public static void main( String args[ ] ){ double area, a, b, c, s; a = 3; b = 4; c = 5; s = (a + b + c) / 2; area = Math.sqrt( s * (s-a) * (s-b) * (s-c) ); System.out.println("Area of Triangle is = " + a

Java Program for finding the area of Circle

Filed under: Java
// Program to find area of circleclass  AreaCircle{ public static void main( String args[ ] ){ double rad; final double PI = 3.14159; rad = 10.0; double area = PI * rad * rad; System.out.print( "\n Area of Circle is = " + area );}}Output:Area of Circle is = 314.159

Hello World Program in Java

Filed under: Java
// Hello World Exampleclass  FirstProgram    {         public static void main( String args[ ] )         {         System.out.println("Hello Java World..!" );         }    }Ou

Arrow Function in JavaScript

Filed under: JavaScript
In this post, we are going to show you arrow function. Watch the below example carefully.<!DOCTYPE html><html><body><h1>JavaScript Functions</h1><h2>The Arrow Function</h2><p>This example shows the syntax of an Arrow Function, and how to use it.&l  ......

For Loop Iteration In JavaScript

Filed under: JavaScript
In this example, we will see for loop iteration. We have taken one blank array. We will push the values in this array using for loop. Below is the complete example of this action.<!DOCTYPE html><html lang="en"><head>   <meta charset="UTF-8">   <meta nam  ......

While Loop example in JavaScript

Filed under: JavaScript
In this post we will see while loop in JavaScript. While loop keep working until the condition is true. As soon as the condition is false it stops.For example we have taken one array here and we will push the values in this array with the help of while loop.<!DOCTYPE html><html lang="en">  ......

Return the Remainder from Two Numbers in JavaScript

Filed under: JavaScript
There is a single operator in JavaScript, capable of providing the remainder of a division operation. Two numbers are passed as parameters. The first parameter divided by the second parameter will have a remainder, possibly zero. Return that value. Examplesremainder(1, 3) ➞ 1remainder(3, 4) β  ......

Convert Hours into Seconds in JavaScript

Filed under: JavaScript
Write a function that converts hours into seconds. Examples:howManySeconds(2) ➞ 7200howManySeconds(10) ➞ 36000howManySeconds(24) ➞ 86400Notes:   60 seconds in a minute, 60 minutes in an hour <script>function howManySeconds(hour){var seconds = hour * 60 * 60 *;} v  ......

Power Calculator in JavaScript

Filed under: JavaScript
Create a function that takes voltage and current and returns the calculated power.Examples:circuitPower(230, 10) ➞ 2300circuitPower(110, 3) ➞ 330circuitPower(480, 20) ➞ 9600Notes:Requires basic calculation of electrical circuits. Power = voltage * current; We will use this calculation in   ......

Return the First Element in an Array in JavaScript

Filed under: JavaScript
Create a function that takes an array containing only numbers and return the first element.Examples:getFirstValue([1, 2, 3]) ➞ 1

getFirstValue([80, 5, 100]) ➞ 80getFirstValue([-500, 0, 50]) ➞ -500Notes:The first element in an array always has an index of 0.Code: <script>function   ......

Convert Age to Days in JavaScript

Filed under: JavaScript
Create a function that takes the age in years and returns the age in days.Examples:calcAge(65) ➞ 23725

calcAge(0) ➞ 0

calcAge(20) ➞ 7300 Notes:Use 365 days as the length of a year for this challenge.Ignore leap years and days between last birthday and now.Expect only positive intege  ......

Convert Minutes into Seconds in JavaScript

Filed under: JavaScript
Write a function that takes an integer minutes and converts it to seconds.Examples:convert(5) ➞ 300

convert(3) ➞ 180

convert(2) ➞ 120 Code<script>function convert(minutes){return minutes * 60;  //1 minutes equals to 60 seconds.}convert(5) // output 300convert(3) // output

Return the Sum of Two Numbers in JavaScript

Filed under: JavaScript
Create a function that takes two numbers as arguments and returns their sum.Examplesaddition(3, 2) ➞ 5

addition(-3, -6) ➞ -9

addition(7, 3) ➞ 10 Code: <script>function addition(a, b){return a+b;} addition(3, 2); //output 5addition(-3, -6); //output -9addition(7, 3); 

What is DOM?

DOM stands for Document Object Model.  DOM is a programming interface for HTML and XML documents.When the browser tries to render an HTML document, it creates an object based on the HTML document called DOM. Using this DOM, we can manipulate or change various elements inside the HTML document.

Explain WeakSet in javascript

In javascript, a Set is a collection of unique and ordered elements. Just like Set, WeakSet is also a collection of unique and ordered elements with some key differences:Weakset contains only objects and no other type.An object inside the weakset is referenced weakly. This means, that if the object   ......

Why do we use callbacks in Javascript?

A callback function is a method that is sent as an input to another function (now let us name this other function "thisFunction"), and it is performed inside the thisFunction after the function has completed execution.JavaScript is a scripting language that is based on events. Instead of waiting for  ......

Methods to include JavaScript in HTML Code?

Filed under: JavaScript
Javascript can be added to our HTML code in mostly 2 ways:Internal Javascript: Javascript in this case is directly added to the HTML code by adding the JS code inside the <script> tag, which can be placed either inside the <head> or the <body> tags based on the requirement of the u  ......

What are the features of JavaScript?

Filed under: JavaScript
Following are the features of javascript:It was developed with the main intention of DOM manipulation, bringing forth the era of dynamic websites.Javascript functions are objects and can be passed in other functions as parameters.Can handle date and time manipulation.Can perform Form Validation.A co

What is NaN property in JavaScript?

NaN property represents the β€œNot-a-Number” value. It indicates a value that is not a legal number.typeof of NaN will return a Number.To check if a value is NaN, we use the isNaN() function,Note- isNaN() function converts the given value to a Number type, and then equates to NaN.isNaN("Hello") &n  ......

Explain Hoisting in javascript

Hoisting is the default behaviour of javascript where all the variable and function declarations are moved on top.This means that irrespective of where the variables and functions are declared, they are moved on top of the scope. The scope can be both local and global.Example 1:hoistedVariable = 3;
  ......

What do you understand by classes in java?

In Java, a class is a user-defined data type from which objects are created. It can also be called as a blueprint or prototype. A class is a collection of various methods and variables which represent a set of properties that are common to all the objects of one type. A class includes components suc  ......

What do you mean by an object in java?

An object is a basic entity in an object-oriented programming language that represents the real-life entities. Many objects are created by a java program that interacts with the invoking methods. The state of an object is represented by its attributes and reflects its properties. The behavior of an   ......

Compare java and python.

Java and Python, both the languages hold an important place in today’s IT industry. But in some factors, one is better than the other. Such factors are:Java is easy to use, whereas Python is very good in this case.The speed of coding in Java is average, whereas in Python it is excellent.In Java, t  ......

Outline the major features of Java.

The major features of Java are listed below: –Object-oriented: – Java language is based on object-oriented programming. In this, the class and the methods describe the state and behavior of an object. The programming is done by relating a problem with the real world object.Portable: – the conv  ......

Looping in JAVA and Types of Loops in JAVA

If we want to execute a statement or a block of statements repeatedly in java, then loops are used. And such a process is known as looping. There are basically 3 types of looping. They are: –"For loop": – for executing a statement or a set of statements for a given number of times, for loops are  ......

What is the need of the JAVA?

The need of Java is that it enforces an object-oriented programming model and can be used to create complete applications that can run on a single computer or be distributed across servers and clients in a network thus it can easily build mobile applications or run on desktop applications that use d

What are the different data types present in javascript?

Filed under: Javascript
To know the type of a JavaScript variable, we can use the typeof operator.Primitive types String - It represents a series of characters and is written with quotes. A string can be represented using a single or a double quote.Example :var str = "Vivek Singh Bisht"; //using double quotes
var str  ......

List some features of JavaScript

Filed under: JavaScript
Some of the features of JavaScript are:
1.    Lightweight
2.    Interpreted programming language
3.    Good for the applications which are network-centric
4.    Complementary to Java
5.    Complementary to HTML
6.    Open source
7.    Cross-platform 

What is JavaScript?

Filed under: JavaScript
JavaScript is a scripting language. It is different from Java language. It is object-based, lightweight, cross-platform translated language. It is widely used for client-side validation. The JavaScript Translator (embedded in the browser) is responsible for translating the JavaScript code for the we