Computer Notes, Programming codes, Hardware and Networking Tip, Entertainment, Biography, Internet Tip, Tech News, Latest Technology, YouTube,

Latest Post
About RAM Advantages of multiprocessing system Associative memory Binary Number System CA CA Notes Change drive icon change pendrive icon Computer Abbreviation Computer Architecture Computer fundamental MCQ Computer Generation Computer generation computer notes Computer MCQ Computer Network MCQ Computer Operator MCQ Critical Section Critical section in OS Database connectivity in java Deadlock avoidance Deadlock detection algorithm Deadlock Detection and Recovery Deadlock detection method Deadlock Handling Deadlock in OS Deadlock Prevention Deadlock Recovery define object and class Define system cell Descrete Structure Device Driver Device driver in computer device driver in os DFA DFA contains with DFA ends with dfa examples dijkstra's algorithm Discrete Structure Discrete Structure graph theory Download JDBC Driver Download MySql Download PUBG DS DS Notes FCFS Job Scheduling Algorithm Finding shortest path Finite Sate Automata Flynn's Classifications fragmentation in computer fragmentation in harddisk fragmentation in os fragmented memory Full form related to computer Generations of operations Generations of OS Graph theory ICT 1st semester notes Instruction Address Modes Java java array declaration java class and object example Java Database connectivity example java event handling example program Java JDBC Java JMenuBar Java JSP program example java notes java program methods example Java program to create class and object java program to create methods java program to print even number between any two numbers Java programming java programming notes Java programs Java question answer java swing example java swing program to calculate simple interest Java Tutorials JSP program learn qbasic Lekh MCQ MCQ Computer MCQ Operating System memory fragmentation MICT 1st semester notes mict 1st semester operating system notes MICT first semester notes Multiprocessing mutex in os Necessary conditions for deadlock Number System Operating System Operating system notes OS OS Notes OS Numeric pattern printing program in qbasic patterns in qbasic Pipeline Hazards Pipelining Pipelining concept prime or composite in qbasic print patterns qbasic print series in qbasic Printing Series in qbasic PUBG PUBG Mobile PUBG PC PUBG Story qbasic qbasic code qbasic for class 10 qbasic for class 8 qbasic for class 9 qbasic for school QBASIC Pattern printing qbasic pattern printing program qbasic pattern printing programs qbasic pattern types qbasic patterns qbasic programming tutorials qbasic programs qbasic sequence printing programs qbasic tutorials Race Condition in Operating system reverse order in qbasic RISC and CISC RISC Pipeline Scheduling algorithm segmentation in operating system segmentation in os semaphore and mutex Semaphore concept in os Semaphore in os semaphore in os notes semaphore meaning sequential programs in qbasic series in qbasic series printing programs in qbasic shell in operating system shell in os shortest path shortest path algorithm simple interest program in java swing System Bus System Cell Teach Blog Tech Blog Tech School technical school The Shell in Operating system types of fragmentation Types of Multiprocessor types of operating system Types of pipeline hazards View Connected Wifi password Virtual Memory Virtual memory in OS Von Neumann's architecture What is associative memory? what is class? What is computer system? What is Fragmentation? What is jsp? what is object? What is process? What is segmentation What is System Cell What is Thread? what is virtual memory in computer What is virtual memory? पब्जी गेम



 

import java.util.Scanner; 
class Rectangle4{
	int l, b; 
	void getData(){
		Scanner in = new Scanner(System.in); 
		System.out.print("Enter length : "); 
		l=in.nextInt(); 

		System.out.print("Enter breadth : "); 
		b=in.nextInt(); 
	}

	void displayArea(){
		int a; 
		a = l*b; 
		System.out.println("Area = "+a); 
	}

	public static void main(String args[]){
		Rectangle4 obj = new Rectangle4();
		obj.getData(); 
		obj.displayArea();  
	}
}


Class is a blueprint to template of real world objects that specifies what data and what methods will be included in object of the class. Class is also called description group of object objects having similar properties. A class is also called user defined data type or programmers defined data type because we can define new data types according to our need by using classes.

Objects are instances of class. We can say that object is variable of class type. Memory for instance declaration rather at the time of class declaration rather than time of object creation. Thus we can say that objects have physical existence and classes are only concepts.


Declaring Classes
Syntax:
       [Access Modifier] className{
                 // body
       }

Creating Object
Syntax:
       [className] [objectName] = new [className]();

Program
 
class Demo{
 void display(){
  System.out.println("Class Example");
 }
 public static void main(String args[]){
  Demo obj = new Demo(); 
  obj.display(); 
 }
}


JSP is a Java Server side technology that does all the processing at server. It is used for creating dynamic web application using Java as programming language.

JSP Program to print "I Love Programming" 100 times.



Program
 
<!DOCTYPE html>
<html> 
<head> 
 <meta http-equiv="Content-Type" content="text/html" charset=UTF-8">
 <title> A simple JSP program </title> 
</head> 
<body> 
 <h1> Displaying "I love Programming 100 times !!" </h1> 
 <table> 
  <% for(int i=1; i<=100; i++){ %> 
   <tr> <td> I Love Programming </td> </tr> 
  <% } %>
 </table> 
</body> 
</html> 


Output of the given Java program

Program

 

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

class PTR extends JFrame implements ActionListener //implement listener interface
{
 JTextField t1, t2, t3, t4;
 JLabel l1,l2,l3, l4;
 JButton b1; 
 public PTR() 
 {
  super("Handling Action Event");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
        l1 = new JLabel("Enter P :");
  l2 = new JLabel("Enter T :");
  l3 = new JLabel("Enter R : ");
  l4 = new JLabel("Interest : ");
  t1 = new JTextField(10);
  t2 = new JTextField(10);
  t3 = new JTextField(10);
  t4 = new JTextField(10); 
  b1 = new JButton("Calculate");
  
  setLayout(new FlowLayout(FlowLayout.LEFT,150,10));
        add(l1);
  add(t1);
  add(l2);
  add(t2);
  add(l3);
  add(t3);
  add(l4);
  add(t4); 
  add(b1);

  b1.addActionListener(this);//Registering event

  setSize(400,300);
        setVisible(true);
 }
 
 public void actionPerformed(ActionEvent ae) //Handle Event
 {
  int p, t, r, si; 
  p = Integer.parseInt(t1.getText());   
  t = Integer.parseInt(t2.getText()); 
  r = Integer.parseInt(t3.getText());
  if(ae.getSource() == b1)
   si = (p*t*r)/100;
  else
   si = 0; 

  t4.setText(String.valueOf(si));
 }

 public static void main(String a [])
 {
  new PTR();
 }
}


Array is a data structure which contains of similar data type. We store only fixed set of elements in a java array. Array is used to store a collection of data, but it is often more useful to think of an array as a collection of variable of the same type.

To declare an array in a Java program, we must declare a variable to reference the array and we most specify the type of array the variable can reference.
Syntax:
                 dataType[] arrayRefVar;
                      or
                 dataType arrayRefVar[];


Program
 

import java.util.Scanner; 
class EvenArray{
     public static void main(String args[]){
 Scanner in = new Scanner(System.in); 
 int x, y; 
 System.out.print("Enter First Number : "); 
 x = in.nextInt(); 
 System.out.print("Enter Second Number : "); 
 y = in.nextInt(); 

 for(int i=x; i<=y; i++){
      if(i%2==0){
     System.out.println(i); 
      }
 }
     }
}


 The thread is a lightweight process that means one single program can be divided into small threads which will execute concurrently for fast execution of task. We can say that thread is a sub process of a process.

A thread is an independent path of execution within a program. Many thread can run concurrently within a program. Every threads in Java is created and controlled by the java.lang thread class. A java program can have many threads, and these threads can run currently, either synchronously or asynchronously.

 - Threads are lightweight compared to process.

Difference between thread and process

Process Thread
- A Process is an instance of a program. It contains a threads. - Threads are the parts of process. It cannot contain a process.
- Process run in its separate. - Thread run in shared memory spaces.
- Process is controlled by the operating system. - Threads a re controlled by programmer in a program.
- Processes are independent.  - Threads are dependent. 
- New processes require duplication of the parent process.  - New threads are easily created.
- Process require more time for context switching as they are more heavy. - Threads require less time for context switching as they are lighter then process. 
- Process require more resources then threads.  - Threads generally need less resources than process. 
- Process require more time for termination. - Threads require less time for termination.

 Life cycle of threads

 

New
The thread is in new state if you create an instance of thread class but before the invocation of start() method.

Runnable
A thread in the runnable state is executing the Java virtual machine but it may be waiting for other resources from the operating system such as processor.

Running
The thread is in running state if the thread scheduler has selected it.

Blocked (Non Runnable)
It is the state when the thread is still alive, but is currently not eligible to run.

Terminated
A thread is in terminated or dead state when its run() method exists.

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget