You are here: Home / Topics / Search /
Showing 951 Search Results for :

Primitive Data Types in java

Filed under: Java Tutorial on 2024-03-01 21:08:59
There are eight primitive data types that are supported in Java programming language. These are the fundamental and predefined datatypes of the programming language. Java determines the size of each primitive data type, it cannot be changed. Reserved keywords represent primitive data types.The primi

Understanding Variables in Java

Filed under: Java Tutorial on 2024-03-01 20:50:25
In Java, the variables can be declared to store data in the program for a specific time. In a programming language, few variations are there todeclare a variable. The following program will explain to declare and then initialize an int variable.public static void main(String[] args) {int data1;data1

Variable and Data Type in Java

Filed under: Java Tutorial on 2024-03-01 20:43:00
VariableVariables occupy the memory to store data for a particular time. Data Type A data type is used to identify the size and type of information stored in a variable. Data types help in memory management. It helps to assign thememory depending upon the type of data type. Most importantl

First Program in Java

Filed under: Java Tutorial on 2024-03-01 20:39:53
This Java program has been developed to display the text 'Hello Planet!' onthe console screen.// File-Name: Hello.javapublic class Hello {     public static void main(String[] args) {     // Displaying "Hello Planet!" on the console     System.out.println

what is JDK, JRE, Garbage Collector and Classpath in Java

Filed under: Java Tutorial on 2024-03-01 16:56:07
Java Development Kit (JDK): Overview: The JDK is a comprehensive package for Java development. It encompasses essential components like the compiler, Java Runtime Environment (JRE), Java debuggers, documentation, and more. To write, compile, and run Java programs, it's imperative to install the

Program to Serialize Student Deserialize student object in Java

Filed under: Java on 2024-03-01 06:48:15
// Program to Serialize Student Deserialize student object.import java.io.*;class Student implements Serializable{int rno;String sname;double marks; // ConstructorStudent( int r, String nm, double m ){ rno = r; sname = nm; marks = m;}void display(){ System.out.println(" Roll

Program to Serialize Student object in Java

Filed under: Java on 2024-03-01 06:47:34
// Program to Serialize Student object student object.import java.io.*;class Student implements Serializable{int rno;String sname;double marks; // ConstructorStudent( int r, String nm, double m ){ rno = r; sname = nm; marks = m;}void display(){ System.out.println(" Roll No. 

Program to De-serialize object of Box class in Java

Filed under: Java on 2024-03-01 06:46:15
// Program to De-serialize object of Box class.import java.io.*;import java.util.*;// Box classclass Box  implements  Serializable{// instance variablesprivate double width;private double height;private double depth;// default constructorBox(){ width = 0; height = 0; depth =

Program to Serialize object of Box class in Java

Filed under: Java on 2024-03-01 06:45:40
// Program to Serialize object of Box class.import java.io.*;import java.util.*;// Box classclass  Box  implements Serializable{// instance variablesprivate double width;private double height;private double depth;// default constructorBox(){ width = 0; height = 0; depth = 0;

Program to read data from text file using FileReader in Java

Filed under: Java on 2024-03-01 06:44:32
// Program to read data from text file using // FileReader  and display it on the monitor.import java.io.*;class FileReaderDemo{public static void main( String args[ ] ) throws IOException{ // attach file to FileReader FileReader fr = null; try {  fr = new FileRead

What is Bytecode in the Development Process

Filed under: Java on 2024-02-27 15:43:54
Description: During the development process, Java source code is compiled into a special format called bytecode by the Javac compiler found in the Java Development Kit (JDK). This bytecode can be executed by the JVM and is saved with a .class extension.

What is Java Virtual Machine (JVM)?

Filed under: Java on 2024-02-27 15:42:54
Definition: The JVM is a critical component in the world of Java programming. It serves two primary functions: enabling Java applications to run across various devices and operating systems (the "Write once, run anywhere" principle) and efficiently managing and optimizing program memory. Technical D

Create a method named calc, which accepts an integer (int), a character (char) and one more integer (int), and depending on the character, returns the result

Filed under: Java on 2024-02-27 13:59:41
Create a method named calc, which accepts an integer (int), a character (char) and one more integer (int), and depending on the character, returns the result of the corresponding operation on numbers:'+' — sum of integers'-' — integer difference (first minus second)'*' — product of integers'/'

Event Types in Node Js

Filed under: NodeJs on 2024-02-22 21:01:23
Sr.No.Events & Description1newListener1. event − String: the event name2. listener − Function: the event handler functionThis event is emitted any time a listener is added. When this event is triggered, the listener may not yet have been added to the array of listeners for the event.2removeL

Event Emitter Pattern in Node Js

Filed under: NodeJs on 2024-02-22 20:51:05
AIM:To demonstrate the event emitter patternObjective:Explanation of event emitter pattern with programme.Theory:The EventEmitter is a module that facilitates communication/interaction between objects in Node. EventEmitter is at the core of Node asynchronous event-driven architecture. Many of Node

Standard Callback Pattern in Node Js

Filed under: NodeJs on 2024-02-22 20:46:50
AIM: To demonstrate the use of Standard callback pattern Objective: Node js callback pattern function callback Theory: Callback is an asynchronous equivalent for a function. A callback function is called at the completion of a given task. Node makes heavy use of callbacks. All the APIs of 

Node.js – Console

Filed under: NodeJs on 2024-02-22 20:42:55
Node.js console is a global object and is used to print different levels of messages to stdout and stderr. There are built-in methods to be used for printing informational, warning, and error messages. It is used in synchronous way when the destination is a file or a terminal and in asynchronous way

Node.js - REPL Terminal

Filed under: NodeJs on 2024-02-22 20:38:39
REPL stands for Read Eval Print Loop and it represents a computer environment like a Windows console or Unix/Linux shell where acommand is entered and the system responds with an output in an interactive mode. Node.js or Node comes bundled with a REPLenvironment. It performs the following tasks −R

Traditional Web Server Model

Filed under: NodeJs on 2024-02-22 16:28:21
The traditional web server model consists of a pool of threads which may process requests. Each time a new request comes in, it is assigned to a different thread in the pool. In the event a request is received and a thread is not available, the request will have to wait until a previous request fini

How to Install Node.js and NPM on Windows

Filed under: NodeJs on 2024-02-22 16:25:43
In a web browser, navigate to https://nodejs.org/en/download/. Click the Windows Installer button to download the latest default version. At the time this article was written, version 10.16.0-x64 was the latest version. The Node.js installer includes the NPM package manager.Step 2: Install Node.js a

What is Node.js Process Model

Filed under: NodeJs on 2024-02-22 16:22:25
The Node.js process model differs from traditional web servers in that Node.js runs in a single process with requests being processed on a single thread. One advantage of this is that Node.js requires far fewer resources. When a request comes in, it will be placed in an event queue. Node.js uses an 

Advantage of Node Js

Filed under: NodeJs on 2024-02-22 16:20:16
The ability to scale up quickly: Each of the nodes in Node.js is based around an “event.” A customer buys an in-app purchase, or sends an email to customer service, for instance. The amount of nodes you can add to your core programming function are nearly limitless. This means you can scale vert

What is Node Js?

Filed under: NodeJs on 2024-02-22 16:18:35
It is a free, open-source, cross-platform runtime environment that runs on JavaScript. Meant mainly for the server side, or client side, of a mobile application, it is a full-stack development environment that divides up tasks into fully separate “nodes.”When people ask, “what are the advantag

Ball Game example In Java

Filed under: Java on 2024-02-16 10:05:17
In this example, i have shown you an example which have mainly three classes:BallGame.javaBallGameImpl.javaApp.javaWhat does this game does?In this game, you will fill the no. of players and no. of balls. Then this game will distribute these balls among the players. After distribution it will tell h

How to update vscode .deb in ubuntu?

Filed under: Coding on 2024-01-16 19:39:28
To update Visual Studio Code (VSCode) on Ubuntu using the .deb package, you can follow these steps:you can manually download the latest .deb package from the VSCode website, and then install it using the following steps:Download the Latest .deb Package:Go to the VSCode website and download the lates

Unit-6: Functions | BCA semester 1

Filed under: BCA Study Material on 2023-10-31 09:08:27
basic types of functionIn C programming, there are two basic types of functions:Library functions: These are the built-in functions in C that are included in the C library. For example, printf, scanf, strcpy, etc. Library functions are used to perform specific tasks, such as reading from the standar

Unit-3: Control structures : BCA semester 1

Filed under: BCA Study Material on 2023-10-30 07:39:03
Control structures in C programming allow you to control the flow of execution of your program based on conditions or repetition. There are three main control structures in C:Conditional (if-else) statements: These are used to execute a block of code only if a certain condition is met.Example:int x 

Java program to sort an array in ascending order

Filed under: Java on 2023-10-29 09:53:28
In this java program, we are reading total number of elements (N) first, and then according the user input (value of N)/total number of elements, we are reading the elements. Then sorting elements of array in ascending order and then printing the elements which are sorted in ascending order.Programi

Java String compareTo() Example Code

Filed under: Java on 2023-10-26 21:45:31
class Main { public static void main(String[] args) {   String str1 = "Learn Java";   String str2 = "Learn Java";   String str3 = "Learn Kolin";   int result;   // comparing str1 with str2   result = str1.compareTo(str2);   S

Java String split() Example

Filed under: Java on 2023-10-26 21:42:57
class Main { public static void main(String[] args) {   String text = "Java is a fun programming language";   // split string from space   String[] result = text.split(" ");   System.out.print("result = ");   for (String str : result) {  &n

Program to use File class and its methods in Java

Filed under: Java on 2023-10-25 06:51:37
//  Program to use File class and its methodsimport java.io.*;class FileDemo{   public static void main(String args[ ])    {       File f = new File("FileDemo.java");       System.out.println("File : " + f.getName() + (f.isFile() 

Program to use URLConnection class in Java

Filed under: Java on 2023-10-25 06:49:31
//  Program to use URLConnection class.import java.io.*;import java.net.*;import java.util.Date;class URLConnectionDemo{public static void main(String args[ ]) throws Exception{ int ch; URL ob = new URL("http://www.bethedeveloper.com/java/"); URLConnection uc = u.openConnection()

Program to display all parts of URL in Java

Filed under: Java on 2023-10-25 06:48:59
// Program to display all parts of URL.import java.net.*;class URLDemo{public static void main( String args[ ] ) throws Exception{ URL ob = new URL("http://www.bethedeveloper.com/java/"); System.out.println(" Protocol : " + ob.getProtocol()); System.out.println(" Host : " + ob.getHost

Program to Display host name by IP address in Java

Filed under: Java on 2023-10-25 06:48:30
// Program to Display host name by IP address.import java.net.*;class HostName{public static void main( String args[ ] ) { // byte ad[ ] = { (byte)192, (byte)168, 1, 2 };  try {  // InetAddress ip = InetAddress.getByAddress( ad );  InetAddress ip = InetAddress.getB

Program to create Menu in AWT in Java

Filed under: Java on 2023-10-25 06:47:10
//  Program to create Menu in AWT.import java.awt.*;import java.applet.*;import java.awt.event.*;class MyMenu extends Frame implements ActionListener{String str="";CheckboxMenuItem cmiBold , cmiItalic;MenuItem miNew , miOpen , miSave, miCut, miCopy, miPaste, miRed, miGreen, miBlue;MyMenu(){&nbs

Program to explain Dialog class in Java

Filed under: Java on 2023-10-25 06:46:42
//  Program to explain Dialog class.import java.applet.*;import java.awt.*;import java.awt.event.*;class MyDialog extends Dialog implements ActionListener{  Button b1;  Label l1;    MyDialog( Frame f, String s, boolean u )  { super( f, s, u ); setLayout( 

Program to use GridBagLayout in Java

Filed under: Java on 2023-10-25 06:46:11
// Program to use GridBagLayout.import java.awt.*;import java.awt.event.*;public class GridBagLayoutDemo1 extends Frame{GridBagLayout gb;GridBagConstraints gbc;Button b1, b2, b3, b4, b5, b6, b7;public GridBagLayoutDemo1( String s ){ super( s );    gb = new GridBagLayout(); g

Program to explain CardLayout in Java

Filed under: Java on 2023-10-25 06:45:42
//  Program to explain CardLayout.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="CardLayoutDemo" width=300 height=100></applet>*/public class CardLayoutDemo extends Applet implements ActionListener, MouseListener {Button b1, b2, b3, b4, b5;Panel 

Program to use GridLayout in Java

Filed under: Java on 2023-10-25 06:45:00
//  Program to use GridLayout.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="GridLayoutDemo" width="300" height="150"></applet>*/public class GridLayoutDemo extends Applet {Button b1, b2, b3, b4, b5;public void init() { setLayout(new Gr

Program to use Insets in Java

Filed under: Java on 2023-10-25 06:44:35
// Program to use Insets.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="InsetsDemo" width="300" height="150"></applet>*/public class InsetsDemo extends Applet {Button b1, b2, b3, b4, b5;public void init() { setLayout(new BorderLayout());&nbs

Program to use BorderLayout in Java

Filed under: Java on 2023-10-25 06:44:03
//  Program to use BorderLayout.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="BorderLayoutDemo" width="300" height="150"></applet>*/public class BorderLayoutDemo extends Applet {Button b1, b2, b3, b4, b5;public void init() { setLayout(

Program to use FlowLayout in Java

Filed under: Java on 2023-10-25 06:43:36
//  Program to use FlowLayout.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="FlowLayoutDemo" width="300" height="150"></applet>*/public class FlowLayoutDemo extends Applet {Button b1, b2, b3, b4, b5;public void init() { setLayout(new Fl

Program to use Scrollbar AWT control in Java

Filed under: Java on 2023-10-25 06:43:08
//  Program to use Scrollbar AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="ScrollbarDemo" width="250" height="150"></applet>*/public class ScrollbarDemo extends Applet implements AdjustmentListener, MouseMotionListener {String msg = 

Program to use List AWT control in Java

Filed under: Java on 2023-10-25 06:42:37
//  Program to use List AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="ListDemo" width=300 height=150></applet>*/public class ListDemo extends Applet implements ActionListener {List os, browser;String msg = "";public void init() 

Program to use Choice AWT control in Java

Filed under: Java on 2023-10-25 06:42:11
//  Program to use Choice AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="ChoiceDemo" width="300" height="150"></applet>*/public class ChoiceDemo extends Applet implements ItemListener {Choice os, browser;String msg = "";public void in

Program to use CheckboxGroup ( RadioButton ) AWT control in Java

Filed under: Java on 2023-10-25 06:41:41
//  Program to use CheckboxGroup ( RadioButton ) AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="RadioButtonDemo" width="250" height="100"></applet>*/public class RadioButtonDemo extends Applet implements ItemListener {String msg = "";

Program to use Checkbox AWT control in Java

Filed under: Java on 2023-10-25 06:40:54
// Program to use Checkbox AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="CheckBoxDemo" width="250" height="150"></applet>*/public class CheckBoxDemo extends Applet implements ItemListener {String msg = "";Checkbox cbRed, cbGreen, cbBlue;p

Program to use TextArea AWT control in Java

Filed under: Java on 2023-10-25 06:40:28
//  Program to use TextArea AWT control.import java.awt.*;import java.applet.*;/*<applet code="TextAreaDemo" width="300" height="200"></applet>*/public class TextAreaDemo extends Applet {public void init() { String val =  "Java SE 6 is the latest version of the m

Program to use TextField AWT control in Java

Filed under: Java on 2023-10-25 06:39:56
// Program to use TextField AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="TextFieldDemo" width=350 height=150></applet>*/public class TextFieldDemo extends Applet implements ActionListener {TextField tfname, tfpass;public void init() 

AWT frame class example in Java

Filed under: Java on 2023-10-25 06:39:22
//  Program to use Frame class.import java.awt.*;import java.awt.event.*;public class FrameTest extends Frame implements ActionListener{TextField tf;Button b;String s = "";   public  FrameTest(){ tf = new TextField( 10 ); b = new Button( "Show" );  add( "North

AWT button example in Java

Filed under: Java on 2023-10-25 06:38:57
//  Program to use Button  AWT control.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="ButtonDemo" width=250 height=150></applet>*/public class ButtonDemo extends Applet implements ActionListener {String msg = "";Button b1, b2, b3;public void

AWT Label example in Java

Filed under: Java on 2023-10-25 06:38:35
// Program to use Label  AWT control.import java.awt.*;import java.applet.*;/*<applet code="LabelDemo" width=300 height=100></applet>*/public class LabelDemo extends Applet {public void init() { Label l1 = new Label("Java"); Label l2 = new Label("Programming");&n

Program to use Window Event in Java

Filed under: Java on 2023-10-19 07:07:54
//  Program to use Window Event.import java.awt.*;import java.awt.event.*;public class WindowEventDemo extends Frame implements WindowListener{public WindowEventDemo(){ addWindowListener( this ); setSize( 250, 150 ); setVisible( true );}public void windowOpened( WindowEvent we ){

Program to expain Fucus Event in Java

Filed under: Java on 2023-10-19 07:07:22
//  Program to expain Fucus Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="FocusEventDemo" width="200" height="100"></applet>*/public class FocusEventDemo extends Applet implements FocusListener{Button b1, b2, b3;Label l1, l2;public void init(){

Program to use MouseAdapter class as Inner class in Java

Filed under: Java on 2023-10-19 07:05:55
//  Program to use MouseAdapter class as Inner class.import java.applet.*;import java.awt.event.*;/*<applet code="MouseAdapterInnerTest" width="300" height="100"></applet>*/public class MouseAdapterInnerTest extends Applet {public void init() { addMouseListener(new My

Program to use MouseAdapter class in Java

Filed under: Java on 2023-10-19 07:05:02
//  Program to use MouseAdapter class.import java.applet.*;import java.awt.event.*;/*<applet code="MouseAdapterTest" width="200" height="100"></applet>*/public class MouseAdapterTest extends Applet {public void init() { addMouseListener(new MyMouseAdapter(this));}}cla

Program to explain Key Event with Virtual Key in Java

Filed under: Java on 2023-10-19 07:04:19
//  Program to explain Key Event with Virtual Key.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet code="KeyEventTest1" width="300" height="100"></applet>*/public class KeyEventTest1 extends Applet implements KeyListener {String msg = "";int X = 10, Y = 

Program to explain Key Event in Java

Filed under: Java on 2023-10-19 07:03:47
//  Program to explain Key Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet  code="KeyEventTest"  width="300" height="200"></applet>*/public class KeyEventTest extends Applet implements KeyListener {String msg = "";int X = 10, Y = 20;&nbs

Program to explain Mouse Event and Mouse Motion Event in Java

Filed under: Java on 2023-10-19 07:03:14
//  Program to explain Mouse Event and Mouse Motion Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet  code="MouseEventTest"  width="300" height="200"></applet>*/public class MouseEventTest extends Applet implements  MouseListener, MouseMo

Program to explain Mouse Motion Event in Java

Filed under: Java on 2023-10-19 07:02:42
//  Program to explain Mouse Motion Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet  code="MouseMotionEventTest" width="300" height="200"></applet>*/public class MouseMotionEventTest extends Applet implements MouseMotionListener {String msg =

Program to explain Mouse Event in Java

Filed under: Java on 2023-10-19 07:01:58
//  Program to explain Mouse Event.import java.awt.*;import java.awt.event.*;import java.applet.*;/*<applet  code="MouseEventTest1"  width="300" height="200"></applet>*/public class MouseEventTest1 extends Applet implements MouseListener {String msg = "";int mouseX = 

Program to change color using setColor() method in Java

Filed under: Java on 2023-10-16 07:07:57
//  Program to change color using setColor() method.import java.awt.*;import java.applet.*;/*<applet code="GraphicsColor" width="300" height="200"></applet>*/public class  GraphicsColor  extends  Applet {public void paint(Graphics g) { Color c1 = new Co

Program to change Font using setFont() method in Java

Filed under: Java on 2023-10-16 07:07:16
//  Program to change Font using setFont() method.import java.awt.*;import java.applet.*;/*<applet code="DrawStringFontTest1a" width="200" height="100" ></applet>*/public class  DrawStringFontTest1a  extends Applet  {Font f;public void init() { setBackground

Program to draw Arc in Applet using fillArc() method in Java

Filed under: Java on 2023-10-16 07:06:07
// Program to draw Arc in Applet using fillArc() method.import java.awt.*;import java.applet.*;/*<applet code="FillArcTest1a" width="200" height="100" ></applet>*/public class  FillArcTest1a  extends  Applet  {public void paint(Graphics g) { setBackground( C

Program to draw Arc in Applet using drawArc() method in Java

Filed under: Java on 2023-10-16 07:05:37
// Program to draw Arc in Applet using drawArc() method.import java.awt.*;import java.applet.*;/*<applet code="DrawArcTest1a" width="200" height="100" ></applet>*/public class DrawArcTest1a extends Applet  {public void paint(Graphics g) { setBackground( Color.yellow );&nbs

Program to draw oval in Applet using drawOval() method in Java

Filed under: Java on 2023-10-16 07:04:38
//  Program to draw oval in Applet using drawOval() method.import java.awt.*;import java.applet.*;/*<applet code="DrawOvalTest1a" width="200" height="100" ></applet>*/public class DrawOvalTest1a extends Applet  {public void paint(Graphics g) { setBackground( Color.yel

Program to draw line in Frame using drawLine() method in Java

Filed under: Java on 2023-10-16 07:02:07
//  Program to draw line in Frame using drawLine() method.import java.awt.*;public class DrawLineTest1b  extends  Frame  {public DrawLineTest1b(){ setSize(200, 200); setVisible(true);}public void paint(Graphics g) { g.drawLine(20, 40, 180, 180);}public static 

Program to use Thread without Synchronization in Java

Filed under: Java on 2023-10-16 06:50:51
//  Program to use Thread without Synchronization.class Shared{void justDoIt( String s ){ System.out.println( " Starting ::: " + s ); try {  Thread.sleep( 500 ); } catch( InterruptedException e )  { } System.out.println( " Ending ::: " + s );}}class 

Program to use suspend( ) and resume( ) method in Java

Filed under: Java on 2023-10-16 06:48:35
// Program to use suspend( ) and resume( ) method.class NewThread implements Runnable{String tn;Thread t;NewThread( String tname ){ tn = tname; t = new Thread( this, tn ); System.out.println( " New Thread ::: " + t ); t.start();}public void run(){ try {  for( int i

Python program to print formatted string

Filed under: Python on 2023-09-23 06:44:48
print("""a string that you "don't" have to escapeThisis a  ....... multi-lineheredoc string --------> example""")      Output:a string that you "don't" have to escape                                

Program to use setPriority( ) method of Thread in Java

Filed under: Java on 2023-09-22 06:48:31
//  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 to extend multiple classes from Thread class in Java

Filed under: Java on 2023-09-22 06:47:47
//  Program to extend multiple classes from Thread class.class A extends Thread{public void run(){ for( int i=1 ; i<=10 ; i++) {  System.out.println( " Java" ); }}}class B extends Thread{public void run(){ for( int i=1 ; i<=10 ; i++) {  System.out.printl

Java Program to explain Main thread and currentThread( ) method

Filed under: Java on 2023-09-22 06:46:01
// Program Main thread and currentThread( ) methodclass CurrentThread{public static void main( String args[ ] ){ Thread t = Thread.currentThread(); System.out.println( "Current Thread is = " + t ); t.setName( "My Thread" ); System.out.println( "After Changing Name is = " + t );}}

C# program to check whether a character is vowel or consonant

Filed under: C# on 2023-09-22 06:42:40
Here you will find an algorithm and program in C# programming language to check whether the given character is vowel or consonant.Explanation : In English, five alphabets A, E, I, O, and U are called as Vowels. In English, all alphabets other than vowels are Consonant. Algorithm to check whethe

C# Program to Print Fibonacci Series upto N terms

Filed under: C# on 2023-09-21 06:59:51
Here you will find an algorithm and program in C# programming language to print fibonacci series. First let us understand what fibonacci series means.Explanation : The Fibonacci sequence is a sequence consisting of a series of numbers and each number is the sum of the previous two numbers. For Examp

C# program to swap two numbers without using temporary variable

Filed under: C# on 2023-09-21 06:58:23
Here you will find an algorithm and program in C# programming language to swap 2 numbers without using any third or temporary variable.Swapping two number : Swap two numbers means exchange the values of two variables with each other. Suppose we are given 2 numbers num1 = 10 and num2 = 20 and we have

C# Program to Find the Sum of Digits in a Given Number

Filed under: C# on 2023-09-21 06:56:45
Here you will find an algorithm and program in C# programming language to find the sum of digits in number. Now let us understand this.Explanation : Suppose we are having number 12548 and we have to calculate the sum of digits in the given number, so here we have the following digits 1, 2, 5, 4, 8 a

C# Program to Count the Number of Digits in a Number

Filed under: C# on 2023-09-21 06:55:39
Here you will find an algorithm and program in C# programming language to count number of digits in a number. First let us understand this.Explanation : Suppose an input number is given as 12341 then the output will be 5 as there are 5 digits in the given number and digits are 1, 2, 3, 4, 1.Algorith

C# Program to Check Whether the Given Year is Leap Year or Not

Filed under: C# on 2023-09-21 06:54:20
Here you will find an algorithm and program in C# programming language to check whether the given year is leap year or not. First let us understand what is leap year?Explanation : A leap year is a calendar year that contains an additional day added to keep the calendar year synchronized. A leap year

C# program to check whether the given number N is even or odd

Filed under: C# on 2023-09-21 06:52:53
Here you will find an algorithm and program in C# programming language to check whether the given number is even or odd number. First let us understand what is even number and odd number.Explanation : If the number is divisible by 2 then the number is even number and if the number is not divisible b

C# Program to Display Hello World on Screen

Filed under: C# on 2023-09-21 06:50:25
Here you will find an algorithm and program in C# programming language to print Hello World on screen. The "Hello World" program is the first step towards learning any programming language and also one of the simplest programs you will learn. All you have to do is display the message "Hello World" o

Program 2 to create Applet with param tag in Java

Filed under: Java on 2023-09-20 06:41:28
//  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 on 2023-09-20 06:40:46
// 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 on 2023-09-20 06:39:13
// 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 to use getCodeBase() and getDocumentBase() in Java

Filed under: Java on 2023-09-20 06:38:44
// Program to use getCodeBase() and getDocumentBase().import java.awt.*;import java.applet.*;import java.net.*;/*<applet code="Applet07" width="300" height="50"></applet>*/public class  Applet07  extends Applet{public void paint(Graphics g) { String msg;  UR

Program with param tag in applet tag in Java

Filed under: Java on 2023-09-20 06:38:12
//  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 on 2023-09-20 06:36:38
//  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 on 2023-09-20 06:36:06
// 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 Applet with init(), start() and paint() in Java

Filed under: Java on 2023-09-20 06:35:34
// Program to use Applet with init(), start() and paint().import java.applet.Applet;import java.awt.*;/*<applet  code="AppletTest1.class" width="300" height="100"></applet>*/public class AppletTest1 extends  Applet {String msg = "";public void init() { setBackgro

Program to use Applet Program and it's Life Cycle in Java

Filed under: Java on 2023-09-20 06:34:59
// Program to use Applet Program and it's Life Cycle.import java.awt.*;import java.applet.*;/*<applet code="Applet01" width="300" height="200"></applet>*/public class  Applet01  extends  Applet {public void init() { setBackground(Color.yellow); System.o

Program to use Boolean Wrapper class in Java

Filed under: Java on 2023-09-19 08:09:43
// 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 expression with Wrapper classes in Java

Filed under: Java on 2023-09-19 08:09:17
//  Program to use expression with Wrapper classes.class Wrapper5{public static void main(String args[ ]) { Integer iOb = 100; Double dOb = 123.45; dOb = dOb + iOb; System.out.println("dOb after expression: " + dOb);}}Output:dOb after expression: 223.45

Program to use Simple Wrapper Class in Java

Filed under: Java on 2023-09-19 08:07:19
//  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 on 2023-09-19 08:06:50
//  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 on 2023-09-19 06:56:08
// 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 on 2023-09-19 06:55:19
//  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; 

Java Program to use values() and valueOf() methods of Enum

Filed under: Java on 2023-09-19 06:52:39
//  Program to use values() and valueOf() methods of Enum.enum Colour {Red, Green, Blue, Black, White, Orange, Yellow}class EnumDemo2 {public static void main(String args[ ]){ Colour c1;  System.out.println("All Colour constants: "); Colour  clr[ ] = Colour.va

Program to use Enumeration Named Constants in Java

Filed under: Java on 2023-09-19 06:51:52
//  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 on 2023-09-19 06:50:25
//  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 on 2023-09-19 06:50:00
//  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 on 2023-09-19 06:49:36
// 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 on 2023-09-19 06:49:11
// 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 on 2023-09-19 06:48:47
//  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 with function example in Java

Filed under: Java on 2023-09-19 06:48:23
// Program to explain Nested Try-Catch Block with Function.class  NestedTryCatchWithFunction{static void nesttry(int a) { try  {  if(a==1)    a = a / (a-a);  if(a==2)   {   int c[ ] = { 1 };   c[10] = 100;  } }

Nested try catch block example in Java

Filed under: Java on 2023-09-19 06:47:47
//  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 on 2023-09-19 06:47:05
//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 exceptions in single catch block example in Java

Filed under: Java on 2023-09-19 06:45:58
// Program to catch Multiple exceptions in single Catch Block.class  Exception6{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; }  

Multiple catch block example in Java

Filed under: Java on 2023-09-19 06:45:13
// 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 on 2023-09-19 06:44:48
//  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 on 2023-09-19 06:44:23
// 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 on 2023-09-19 06:43:44
// 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 display the examination schedule

Filed under: Python on 2023-09-18 06:58:11
Python program to display the examination schedule. (extract the date from exam_st_date).exam_st_date = (11, 12, 2014)Sample Output: The examination will start from : 11 / 12 / 2014 Code:exam_st_date = (11,12,2014)print( "The examination will start from : %i / %i / %i"%exam_st_date)   &nbs

Python program which takes radius from user and print area

Filed under: Python on 2023-09-18 06:50:25
#Write a Python program which accepts the radius of a circle from the user and compute the area Python: Area of a CircleIn geometry, the area enclosed by a circle of radius r is πr2. Here the Greek letter π represents a constant, approximately equal to 3.14159, which is equal to the ratio of 

Python code to find sum of elements in given array

Filed under: Python on 2023-09-17 22:28:23
#!/usr/bin/python# -*- coding: utf-8 -*-# Python 3 code to find sum# of elements in given arraydef _sum(arr):   # initialize a variable   # to store the sum   # while iterating through   # the array later   sum = 0   # iterate through the a

Python program for implementation of Bubble Sort

Filed under: Python on 2023-09-17 22:27:52
#!/usr/bin/python# -*- coding: utf-8 -*-# Python program for implementation of Bubble Sortdef bubbleSort(arr):   n = len(arr)   # Traverse through all array elements   for i in range(n - 1):   # range(n) also work but outer loop will repeat one time more than 

Python program for implementation of Quicksort Sort

Filed under: Python on 2023-09-17 22:27:24
#!/usr/bin/python# -*- coding: utf-8 -*-# Python program for implementation of Quicksort Sort# This function takes last element as pivot, places# the pivot element at its correct position in sorted# array, and places all smaller (smaller than pivot)# to left of pivot and all greater elements to righ

Python program to swap first and last element of a list

Filed under: Python on 2023-09-17 22:25:39
#!/usr/bin/python# -*- coding: utf-8 -*-# Python3 program to swap first# and last element of a list# Swap functiondef swapList(newList):   size = len(newList)   # Swapping   temp = newList[0]   newList[0] = newList[size - 1]   newList[size - 1] = tem

Python program to find maximum in arr[] of size n

Filed under: Python on 2023-09-17 22:24:05
#!/usr/bin/python# -*- coding: utf-8 -*-# Python3 program to find maximum# in arr[] of size n# python function to find maximum# in arr[] of size ndef largest(arr, n):   # Initialize maximum element   max = arr[0]   # Traverse array elements from second   # and

Python Program to check if a string is palindrome or not

Filed under: Python on 2023-09-17 22:02:50
#!/usr/bin/python# -*- coding: utf-8 -*-# Program to check if a string is palindrome or notmy_str = 'aibohphobia'# make it suitable for caseless comparison# reverse the stringrev_str = reversed(my_str)# check if the string is equal to its reverseif list(my_str) == list(rev_str):   print 'T

Python program to find H.C.F of two numbers

Filed under: Python on 2023-09-17 22:02:23
#!/usr/bin/python# -*- coding: utf-8 -*-# Python program to find H.C.F of two numbers# define a functiondef compute_hcf(x, y):# choose the smaller number   if x > y:       smaller = y   else:       smaller = x   for i in range(

Python Program to display the Fibonacci sequence up to n-th term

Filed under: Python on 2023-09-17 22:01:16
#!/usr/bin/python# -*- coding: utf-8 -*-# Program to display the Fibonacci sequence up to n-th termnterms = int(input('How many terms? '))# first two terms(n1, n2) = (0, 1)count = 0# check if the number of terms is validif nterms <= 0:   print 'Please enter a positive integer'elif nterm

Python program for Armstrong number

Filed under: Python on 2023-09-17 22:00:40
#!/usr/bin/python# -*- coding: utf-8 -*-# Python program to check if the number is an Armstrong number or not# take input from the usernum = int(input('Enter a number: '))# initialize sumsum = 0# find the sum of the cube of each digittemp = numwhile temp > 0:   digit = temp % 10  &

Python program to find the Factorial of any number

Filed under: Python on 2023-09-17 21:59:54
#!/usr/bin/python# -*- coding: utf-8 -*-# Python program to find the factorial of a number provided by the user.# change the value for a different result# To take input from the usernum = int(input('Enter a number: '))factorial = 1# check if the number is negative, positive or zeroif num < 0:&nbs

Python program to find the largest of three numbers

Filed under: Python on 2023-09-17 21:57:19
#!/usr/bin/python# -*- coding: utf-8 -*-# Python program to find the largest number among the three input numbers# change the values of num1, num2 and num3# for a different result# uncomment following lines to take three numbers from usernum1 = float(input('Enter first number: '))num2 = float(input(

Python program to find the roots of Quadratic equation

Filed under: Python on 2023-09-17 21:56:49
#!/usr/bin/python# -*- coding: utf-8 -*-# Solve the quadratic equation ax**2 + bx + c = 0# import complex math moduleimport cmatha = 1b = 5c = 6# calculate the discriminantd = b ** 2 - 4 * a * c# find two solutionssol1 = (-b - cmath.sqrt(d)) / (2 * a)sol2 = (-b + cmath.sqrt(d)) / (2 * a)print 'The s

Python Program to find the area of triangle

Filed under: Python on 2023-09-17 21:55:27
#!/usr/bin/python# -*- coding: utf-8 -*-# Python Program to find the area of triangle# Uncomment below to take inputs from the usera = float(input('Enter first side: '))b = float(input('Enter second side: '))c = float(input('Enter third side: '))# calculate the semi-perimeters = (a + b + c) / 2# cal

Python program to swap two variables

Filed under: Python on 2023-09-17 21:54:55
#!/usr/bin/python# -*- coding: utf-8 -*-# Python program to swap two variables# To take inputs from the userx = input('Enter value of x: ')y = input('Enter value of y: ')# create a temporary variable and swap the valuestemp = xx = yy = tempprint 'The value of x after swapping: {}'.format(x)print 'Th

program to explain static import for static Field in Java

Filed under: Java on 2023-09-17 15:41:32
// 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 on 2023-09-17 15:40:54
//  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 on 2023-09-17 15:40:07
//  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 on 2023-09-17 15:39:27
//  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 on 2023-09-17 15:38:49
//  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 on 2023-09-17 15:38:14
// 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 Visibility Control in Same Package example in Java

Filed under: Java on 2023-09-17 15:37:29
// Program to Visibility Control in Same 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"); System.out.println("n_p

Program to explain Importing Package example in Java

Filed under: Java on 2023-09-17 15:36:40
//  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 on 2023-09-17 15:36:05
//  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 on 2023-09-17 15:35:29
// 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 on 2023-09-17 13:20:18
// 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.

Program to Implement a class from multiple interfaces in Java

Filed under: Java on 2023-09-17 13:18:41
// Program to Implement a class from multiple interfaces.interface  A{void showA();}interface  B {void showB();}class  C  implements  A, B{public void showA(){ System.out.println("showA() of A interface.");}public void showB(){ System.out.println("showB() of B

Polymorphism with interface example in Java

Filed under: Java on 2023-09-17 13:17:59
//  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 on 2023-09-17 13:16:47
//  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 on 2023-09-17 13:15:33
//  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 on 2023-09-17 13:14:57
//  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 on 2023-09-17 07:10:08
//  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 on 2023-09-17 07:09:35
// 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 on 2023-09-17 07:05:35
//  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 on 2023-09-17 07:01:53
//  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 on 2023-09-17 07:00:43
// 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 on 2023-09-17 07:00:19
// 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 on 2023-09-17 06:58:31
//  hierarchical inheritance exampleclass student1{   private String name;   private int rno;      void setname(String name, int rno)   {       this.name = name;       this.rno = rno;   }  &

Use of super keyword to call super class constructor in Java

Filed under: Java on 2023-09-17 06:57:43
// Program to use super keyword to call Super class constructor to // initialize super class instance variablesclass Box {private double width;private double height;private double depth;Box(Box ob) {  width = ob.width; height = ob.height; depth = ob.depth;}Box(doub

Use of this keyword example in Java

Filed under: Java on 2023-09-17 06:56:56
//  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 on 2023-09-17 06:56:32
//  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 on 2023-09-17 06:56:01
// 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 on 2023-09-17 06:55:33
// 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 on 2023-09-17 06:55:03
// 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 on 2023-09-17 06:54:31
// 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 on 2023-09-17 06:53:46
// 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 on 2023-09-17 06:53:13
// 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 on 2023-09-17 06:52:17
// 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 on 2023-09-17 06:51:38
// 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 on 2023-09-17 06:51:06
// 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 ); &

Use ViewResolver in Spring MVC

Filed under: Spring on 2023-08-27 17:24:38
view resolver is a class in spring framework which allows us to configure urls dynamically ctrl + shift + T to open type in eclipse, search *Viewresolver you will find InternalResourceViewResolver this class will do it automatically.Make a bean of this class in mainController-servlet.xml file (

Map your Controller with the jsp file (Views) in Spring MVC

Filed under: Spring on 2023-08-27 17:24:05
In previous spring topic, we were returning a string from our methods which were written in our controller.In this topic, we are going to see how to map url with the viewNote: all the views will be stores in WEB-INF folder. You can store anywhere but it is recommended that you store all the views in

toString() method in spring buffer in Java

Filed under: Java on 2023-08-23 18:58:36
// 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 on 2023-08-23 18:57:52
// 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 on 2023-08-23 18:57:03
// 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 on 2023-08-23 18:56:33
// 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 on 2023-08-23 18:56:04
// 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 on 2023-08-23 18:55:29
// 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 on 2023-08-23 18:54:55
// 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 on 2023-08-23 18:54:29
// 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 on 2023-08-23 18:54:04
// 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 on 2023-08-23 18:53:38
// 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 on 2023-08-23 18:53:00
//  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 on 2023-08-23 18:52:29
// 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 on 2023-08-23 18:51:59
// 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 on 2023-08-23 18:51:33
// 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 on 2023-08-23 18:51:06
// 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 on 2023-08-23 18:50:39
// 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 on 2023-08-23 18:49:57
// 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 on 2023-08-23 18:49:18
// 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 on 2023-08-23 18:48:34
// 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 on 2023-08-23 18:47:45
// 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 on 2023-08-23 06:58:27
// 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 on 2023-08-23 06:57:40
// 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 on 2023-08-23 06:57:05
// 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 on 2023-08-23 06:56:05
// 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 on 2023-08-23 06:55:35
// 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 on 2023-08-23 06:54:46
// 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 on 2023-08-23 06:54:05
//  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 on 2023-08-23 06:53:38
// 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 on 2023-08-23 06:51:24
//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 on 2023-08-23 06:50:50
// 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 on 2023-08-23 06:49:05
// 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 on 2023-08-23 06:48:23
// 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 on 2023-08-23 06:47:40
// 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 on 2023-08-23 06:47:20
// 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 on 2023-08-23 06:46:58
// 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 on 2023-08-23 06:46:38
//  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 on 2023-08-23 06:46:12
// 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 on 2023-08-23 06:45:49
//  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[

Array Example in C++

Filed under: C++ on 2023-08-20 14:11:47
#include<stdio.h>#include<conio.h>int main(){int i, arr[7]={1,2,3,4,5,6,7};for(i=0; i<10; i++){ printf("\n %d", arr[i]);}} 

All C++ Functions List Alphabatically

Filed under: C++ on 2023-08-20 14:09:09
##define#elif#else#endif#if#ifdef#ifndef#include#pragma pack#pragma#undef BBeginPaint()BitBlt()BOOLBUTTON CCreateCompatibleDC()CreateFontIndirect()CreateHatchBrush()CreatePatternBrush()CreatePen()CreateSolidBrush()CreateWindow() DDispatchMessage()DefWindowProc()DeleteObject()DrawText(

Program to arrange array in Ascending order in Java

Filed under: Java on 2023-08-19 18:39:56
// 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 on 2023-08-19 18:38:03
//  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 on 2023-08-19 18:36:19
// 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 on 2023-08-19 13:09:43
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 on 2023-08-18 07:00:44
// 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 on 2023-08-18 07:00:21
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 on 2023-08-18 06:59:13
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 +

Program to check palindrome number in Java

Filed under: Java on 2023-08-18 06:57:33
// check given number is palindrom or notpublic class PalindromeNumber {   public static void main(String[] args) {       int n = 1215;       int sum = 0;       int m = n;       while (n > 0) {    

Count number of digits in any given number in Java

Filed under: Java on 2023-08-18 06:55:39
// 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 on 2023-08-18 06:54:55
// 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 on 2023-08-18 06:54:25
// 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 on 2023-08-18 06:53:53
// 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 on 2023-08-18 06:53:12
// 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 on 2023-08-18 06:52:19
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 on 2023-08-18 06:51:38
 // 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 Prime Number using for loop in java

Filed under: Java on 2023-08-18 06:50:30
// Program to Check the Given Number is PRIME or NOT.class  PrimeTest{public static void main( String args[ ] ){ int i, n; boolean  flag = true;  n = 29;   for( i=2 ; i<=n/2 ; i++ ) {  if( n % i == 0 )  {   flag = false;   

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

Filed under: Java on 2023-08-18 06:49:47
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 on 2023-08-18 06:46:47
// 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 on 2023-08-18 06:46:16
//  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++ )&

Program for getting Factorial of any number in Java

Filed under: Java on 2023-08-18 06:45:28
//Program to Calculate the Factorial of the Given Number.class  FactorialTest{public static void main( String args[ ] ){ int i, n;  n = 5; int f = 1; for( i=n ; i>=1 ; i-- ) {  f = f * i ; } System.out.println( "\n The Factorial of " + n + " is = 

Continue statement example in Java

Filed under: Java on 2023-08-18 06:44:47
// continue staement examplepublic class ContinueStatement{   public static void main(String[] args) {       for (int i = 0; i < 10; i++) {                       if (i % 2 == 0) {        

Label block and break example in Java

Filed under: Java on 2023-08-18 06:44:16
//  Label block and breakpublic class BreakAsGoto{   public static void main(String[] args) {       aBlock:       {           bBlock:           {           

Break statement example in Java

Filed under: Java on 2023-08-18 06:43:35
// 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 on 2023-08-18 06:42:50
//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 on 2023-08-18 06:42:09
// 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 on 2023-08-18 06:38:27
// 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 on 2023-08-18 06:37:55
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 on 2023-08-18 06:36:56
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 on 2023-08-18 06:35:54
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 on 2023-08-12 20:54:23
//  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 on 2023-08-12 20:53:15
// 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 on 2023-08-12 20:52:05
// 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 + " -

Find Day by day number using switch statement in Java

Filed under: Java on 2023-08-12 20:51:13
// Find day using switch caseclass  SwitchCaseDays {public static void main(String args[ ]){ int day; day = 6; switch( day ) {  case 1:   System.out.println( " Monday." );   break;  case 2:   System.out.println( " Tuesday." );&nbs

Simple Switch case example in Java

Filed under: Java on 2023-08-12 20:50:25
// 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;&

Simple program to check day by day number using if elsein Java

Filed under: Java on 2023-08-12 20:48:24
// Program to show Day Name according to Day Number ( 1 - 7 ) using else-if ladder statement.class  ElseIfDays{public static void main(String args[ ]){ int day; day = 7; if( day == 1 )  System.out.println( " Monday." ); else if( day == 2 )  System.out.println( " Tu

Program to find leap year in Java

Filed under: Java on 2023-08-12 20:46:26
// 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 on 2023-08-12 20:44:38
// 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 on 2023-08-12 20:43:55
//  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 on 2023-08-12 20:42:38
// 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 on 2023-08-12 20:42:01
// 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 on 2023-08-12 20:41:06
//  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 on 2023-08-12 20:40:31
// 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 on 2023-08-12 20:39:45
// 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 on 2023-08-11 19:33:38
// 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 on 2023-08-11 19:32:57
//  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

Program to use Short-Hand Assignment Operators in Java

Filed under: Java on 2023-08-11 19:32:24
//  Program to use Short-Hand Assignment Operators ( +=, -=, *=, /=, %= )class ShortHandAssign {public static void main(String args[ ]) { int a = 1; int b = 2; int c = 3; a += 5; b *= 4; c += a * b; c %= 6; System.out.println("a = " + a); S

Conditional Operators Examples 2 in Java

Filed under: Java on 2023-08-11 19:28:21
// 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 on 2023-08-11 19:27:39
//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 on 2023-08-11 19:26:51
//  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 on 2023-08-11 19:26:14
// 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 on 2023-08-11 19:25:39
// 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 on 2023-08-11 19:25:04
// 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 on 2023-08-11 19:24:32
//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 on 2023-08-11 19:23:40
// 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 on 2023-08-11 19:23:00
// 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 on 2023-08-11 19:21:52
// 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 on 2023-08-11 19:21:20
// 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 on 2023-08-11 19:20:37
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 on 2023-08-11 19:19:25
// 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 on 2023-08-11 19:18:43
// 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 on 2023-08-11 19:17:44
// 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

Swapping of Variables without using Third Variable in Java

Filed under: Java on 2023-08-11 19:16:47
// Swapping example without third variableclass SwapWithoutThirdVariable{public static void main( String args[ ] ){ int   a, b; a = 10; b = 20; System.out.print("\nBefore Swapping : " ); System.out.print( a + "   " + b ); a = a + b; b = a - b; a = a 

Swaping of Variables using third Variable in Java

Filed under: Java on 2023-08-11 19:16:00
// 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 on 2023-08-11 19:15:13
// 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 on 2023-08-11 19:14:15
// 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 on 2023-08-11 19:12:59
//  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 on 2023-08-11 19:12:08
// 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 on 2023-08-11 19:11:40
// 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 on 2023-08-11 19:09:55
// 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 on 2023-08-11 19:09:03
// 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 on 2023-08-11 19:08:22
// 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 on 2023-08-11 19:07:39
// 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 Converting Rupees into Paisa

Filed under: Java on 2023-08-11 19:06:31
// Program to convert ruppes to paisapublic class SimpleConversion{   public static void main(String args[])   {                      double n=56.50;           int a=(int) n;    &n

Java Program for Area Of Triangle

Filed under: Java on 2023-08-11 19:05:40
// 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 on 2023-08-11 19:05:05
// 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 on 2023-08-11 19:02:38
// Hello World Exampleclass  FirstProgram    {         public static void main( String args[ ] )         {         System.out.println("Hello Java World..!" );         }    }Ou

Arithmetic Operators in SQL

Filed under: SQL on 2023-08-10 06:48:49
Different number-crunching administrators are utilized in SQL to be specific Addition (+), Subtraction (-), Multiplication (*), Division (/), Modulus (%).For the further examples we will be referring to the following base table:Table: BOOKSBookNoNameCostDiscount9871Nancy Drew2005%9560Goosebump25010%

Types of SQL Data Types

Filed under: SQL on 2023-08-10 06:43:40
Types of SQL Data TypesNumeric data type:It includes datatypes like int, tinyint, bigint, float, real, etc.Date and Time data type:It includes datatypes like Date, Time, Datetime, etc.Character and String datatype:It includes data types like char, varchar, text, etc.Unicode character/string datatype

Arrow Function in JavaScript

Filed under: JavaScript on 2023-08-07 19:00:15
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

How to Iterate an array elements using For Loop in JavaScript

Filed under: JavaScript on 2023-08-06 23:04:29
In this post, you will see how you can iterate elements of an array in javascript.Note: here we have an array of numbers.We can find the number of elements in this array by using array.length i.e 6. Now we will run for loop six times to print all the elements.All of you know that array starts w

For Loop Iteration In JavaScript

Filed under: JavaScript on 2023-08-06 22:39:18
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 on 2023-08-06 22:03:24
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 on 2023-08-06 21:08:07
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) 

Write a code to find Maximum Edge of a Triangle in JavaScript

Filed under: JavaScript on 2023-08-06 21:00:59
Create a function that finds the maximum range of a triangle's third edge, where the side lengths are all integers. Examples:nextEdge(8, 10) ➞ 17nextEdge(5, 7) ➞ 11nextEdge(9, 2) ➞ 10 Notes:We will use this algorithm to find the maximum range of a triangle's third edge(side1 + side2)

Convert Hours into Seconds in JavaScript

Filed under: JavaScript on 2023-08-06 20:57:35
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 on 2023-08-06 20:54:31
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 on 2023-08-06 20:50:56
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 on 2023-08-06 20:43:43
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

Write a program in JavaScript to find the Area of Triangle

Filed under: JavaScript on 2023-08-06 20:41:33
Write a function that takes the base and height of a triangle and return its area.Examples:triArea(3, 2) ➞ 3

triArea(7, 4) ➞ 14

triArea(10, 10) ➞ 50 We will make a function triArea(base, height) which will take two values as parametersNotes:The area of a triangle is: (base * height)

Convert Minutes into Seconds in JavaScript

Filed under: JavaScript on 2023-08-06 20:35:41
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 on 2023-08-06 20:33:00
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); 

How to sort an associative array by value in PHP

Filed under: PHP on 2023-07-02 21:56:04
The PHP functions asort() and arsort() can be used to sort an array by value. Sort an associative array by value in ascending order You can use the asort() function to sort an associative array alphabetically by value in ascending order, while maintaining the relationship between key and v

How to remove a specific element from an array in PHP

Filed under: PHP on 2023-07-02 21:26:17
If you want to remove an element from an array, you can just use the PHP unset() method. The following example shows you how to remove an element from an array. Example 1: How to remove a specific element from an associative array by key in PHP<?php $languages = array("p"=>"PHP", "j"

How to get a value from an array in PHP

Filed under: PHP on 2023-07-02 21:24:17
If you want to access a value in an indexed, associative, or multidimensional array, you can do it by using the index or the key. Example 1: How to get a value from an array <?php $numbers = array(1, 2, 3, 4, 5); echo $numbers[0];?>Output:1Example 2: How to get a value from

How to get all the keys of an associative array in PHP

Filed under: PHP on 2023-07-02 21:21:53
You can use the PHP array_keys() function to extract all the keys from an associative array. How to get all the keys of an associative array in PHP <?php $languages = array("p"=>"PHP", "j"=>"Java", "a"=>"Ada", "h"=>"HTML"); print_r(array_keys($languages));?>&nbs

How to Populate Dropdown List using Array in PHP

Filed under: PHP on 2023-07-02 21:20:14
In this tutorial, we are going to see how to populate dropdown list using array in PHP. You can simply use the foreach loop to create a <select> list or any drop-down menu that forms the values of an array. How to Populate Dropdown List using Array in PHP <!DOCTYPE html><htm

How to remove null or empty values from an array in PHP

Filed under: PHP on 2023-07-02 21:17:47
You can use the PHP array_filter() function to remove or filter empty values from an array. This function usually filters the values of an array using a callback function. However, if no callback is specified, all values in the array equal to FALSE will be removed, such as an empty string or a NULL 

How to calculate sum of an array in PHP

Filed under: PHP on 2023-07-02 21:16:20
You can use the PHP array_sum() function to calculate the sum of all numeric values in an array. As shown in the following example: How to calculate sum of an array in PHP <?php $arr1 = array(1, 2, 3); $arr2 = array("a" => 1, "b" => 2, "c" => 3); echo array_sum($

How to get random value from an array in PHP

Filed under: PHP on 2023-07-02 21:14:59
In this tutorial, we are going to see how to get random value from an array in PHP. You can use the PHP shuffle() function to randomly shuffle the order of elements or values in an array. The shuffle() function returns FALSE on failure. How to get random value from an array in PHP <?php

How to remove an array element based on key in PHP

Filed under: PHP on 2023-07-02 21:13:13
The unset() function is used to remove an element from an array. The unset() function is used to destroy any other variable and similarly to remove an element from an array. This function takes the array key as input and removes that element from the array. After removal, the associated key and valu

How to download a file in PHP using Curl

Filed under: PHP on 2023-07-02 21:09:16
Here you will find how to download a file using PHP by Using PHP Curl: <?php  $url = 'https://www.mcqbuddy.com/img/user.jpg';     // Initialize the cURL session $session = curl_init($url);     // Initialize the directory name where the f

How to Download file from URL using PHP

Filed under: PHP on 2023-07-02 21:07:35
There are several approaches to download a file from a URL. Some of them are described below: Using file_get_contents() function:file_get_contents() function is used to read a file into a string. This feature uses memory mapping techniques supported by the server and thus improves performance, 

How to open a PDF file in browser with PHP

Filed under: PHP on 2023-07-02 21:05:19
PHP uses standard code to display the pdf file in the web browser. The process of viewing the PDF file involves locating the PDF file on the server. It uses various types of headers to define the composition of the content in the form of Type, Layout, Transfer-Encode, etc. PHP transmits the PDF file

How to compare two dates in PHP

Filed under: PHP on 2023-06-30 06:38:36
Given two dates (date1 and date2) and the task is to compare the given dates. Comparing two dates in PHP is simple when the two dates are in the same format, but the problem arises when the two dates are in a different format. Method 1: How to compare two dates in PHPIf the given dates have the

How to Change Max Size of File Upload in PHP

Filed under: PHP on 2023-06-30 06:33:43
The maximum size of any file that can be uploaded to a website written in PHP is determined by the max_size values, mentioned in the server’s php.ini file. In case of a hosted server, you should contact the hosting server administrator. It is useful to create a local HTTP server for developers.Pro

How to get first day of week in PHP

Filed under: PHP on 2023-06-30 06:32:31
You can use strtotime() function to get the first day of the week using PHP. This function returns the timestamp of the default time variable, then uses date() function to convert the date from the timestamp to a meaningful date.In PHP the week starts with Monday, so if the time string is given as 

How to refresh a page with PHP

Filed under: PHP on 2023-06-30 06:30:12
Here you will find how to refresh a page with PHPYou can use header() function to refresh a web page in PHP. HTTP functions are the functions that manipulate the information sent to the client or browser by the web server before sending any other output.header() function in PHP sends an HTTP header 

How to declare a global variable in PHP

Filed under: PHP on 2023-06-30 06:28:16
Global variables refer to any variable defined outside the function. Global variables are accessible from any part of the script, i.e. inside and outside the function.There are two ways to access a global variable inside a function:Using the global keywordUsing the array GLOBALS[var_name]: It stores

How to Get IP Address of Server in PHP

Filed under: PHP on 2023-06-30 06:26:52
Use the following code if you want to display the IP address of the server. Simply copy the code to a text file and save it as a .php file on the server.For Linux with Apache, use the following code: <?php echo $_SERVER['SERVER_ADDR'];?>For Windows 2008 R2 with IIS 7.5 Server, use:&l

How to get the client IP address in PHP

Filed under: PHP on 2023-06-30 06:24:56
In this tutorial, we are going to see how to get the client IP address in PHP. We often need to collect the client’s IP address to track activity and for security reasons. It is very easy to get the IP address of the visitor in PHP. The PHP variable $_SERVER makes it easy to get the IP address of