Posts

Build a Simple Android App to Display Student Details

Image
Build a Simple Android App to Display Student Details (Student Details App) In this tutorial, we’ll walk through the steps to create a basic Android application that displays a student’s details such as name, and marks. This is a great starting project for Android development using Java . 🛠 What You’ll Learn Creating a new Android Studio project Designing a layout with TextViews Writing Java code to display student data Running the app on an emulator or physical device 📦 Step 1: Create a New Project Open Android Studio Click on “New Project” Choose Empty Activity Name it: StudentDetailsApp Language: Java Click Finish 🖼  Step 2: Design the Layout (XML) Go to  res/layout/activity_main.xml  and replace the default content with the following: activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.andro...

Develop an Android application to display “Hello World!” on screen

Image
Develop an android application to display “Hello World!” on screen Introduction In this tutorial, you learn how to start android development with the very first android project. You also create and run your first Android app Hello World, on emulator or physical device. Before you start writing your first program using Android Studio, you have to make sure that you have set-up your Android development environment properly. Also it is assumed that you have a little bit of working knowledge with Android studio. What you should already know Basic understanding of object-oriented programming Basic understanding of Java programming language What you'll need A computer running Windows or Linux, or a Mac running macOS. Android Studio should be installed, if it’s not ready, please download it from the Official Website. ...

Program to display Digits in 7-Segment Style Using Java

Image
Display Digits in 7-Segment Style Using Java Ever wondered how digital clocks or calculators display numbers? They often use seven-segment displays —a simple arrangement of 7 LEDs to represent numbers from 0 to 9. In this post, we'll create a Java program that simulates the same effect on your console screen! 💡 What is a 7-Segment Display? A 7-segment display is made up of seven LEDs (labeled a through g ) that can be turned on or off to create numerical digits. Here's a visual representation: Each digit is formed by turning on a combination of these segments.

Program to create text file, write some data and read the same using single character method without using string functions

 In this tutorial, you'll learn how to create TEXT file, write some data to file and read the data from text file. Before going to start you should aware of the following concepts: Java File IO FileWriter class FileReader class

Program to split the words in sentence of string without using split in Java

 In this program, you'll learn how to split the words in sentence of string without using split() function. Hello Guys, if you know about split( ) method of String class, it can be used to split the sentence into words. Here in this program we will split the using without using this split() method. So let us start.

Program to design an applet which draws a circle (having color BLUE) inside a triangle (having color YELLOW)

Image
Given program will draw a circle inside a triangle. The color of circle is "blue" and triangle having color "yellow". To fill circle with respective colours first we have to set the colour using  setColor(Color c)  method of  Graphics  class and then use the fillPolygon() and fillOval( )  method. The  fillPolygon( )  method Fills a closed polygon defined by arrays of x and y coordinates.

Program to create a Popup Menu using Java AWT

Image
This tutorial shows you how to create a simple popup menu in Java. Popup menu is a menu which appears when you right click on mouse. For example, to copy, paste something in computer you right click and it will show the popup menu like:

Program to create a simple Calculator using Java AWT components

Image
This tutorial explains you how to create a simple Calculator using Java AWT components. The output of the program is given below. 

Program to create a simple mini paint application

Image
In this program, we will create a simple mini paint application using Frame class. We have to implement two types of events here: Mouse event and Key event. To use this program you have to use numpad keys on keyboard. The following keys are used for specific purpose:

Program to demonstrate the Mouse events using Applet

Image
In this program, we have to implement Mouse events. An event which indicates that a mouse action is occurred in a component. This event is used both for mouse events (enter, click, press, release, exit) and mouse motion events (moves, drags). 

Pascal triangle 5

Image
This program will display the pascal triangle or print star pattern as shown below: * *A* *A*A* *A*A*A* *A*A*A*A*

Program to use MouseListener interface and its methods.

Image

Program for dynamically creating and adding JLabels

Image
In this Java Swing tutorial, we will learn how to create JLabel components dynamically inside a JPanel based on the value entered in a JTextField . Whenever the user types a number, the application automatically creates that many labels and displays them in the panel without restarting the program. For example: If the user enters 3 , three labels will be displayed. If the user enters 5 , five labels will be displayed. If the text field is cleared, all labels are removed.

Program to demonstrate "HashMap" class in Java's Collection Framework

The  Map  interface maps unique keys to values. A key is an object that you use to retrieve a value at a later date. Given a key and a value, you can store the value in a Map object. After the value is stored, you can retrieve it by using its key. It stores value in pairs i.e key and value we can store data using put( ) method and fetch specific data using get( ) method we can print all data using entrySet( ) method. It has following methods: void clear( ) :  Removes all key/value pairs from the invoking map. boolean containsKey(Object k) :  Returns true if the invoking map contains k as a key. Otherwise, returns false. boolean containsValue(Object v) :  Returns true if the map contains v as a value. Otherwise, returns false.

Program to demonstrate "LinkedList" class in Java's Collection Framework

The  LinkedList  class extends  AbstractSequentialList  and implements the  List  interface. It provides a linked-list data structure. Following are the constructors supported by the LinkedList class. LinkedList( ) This constructor builds an empty linked list. LinkedList(Collection c) This constructor builds a linked list that is initialized with the elements of the collection c. LinkedList defines following methods: void add(int index, Object element) :  Inserts the specified element at the specified position index in the list. boolean add(Object o) :  Appends the specified element to the end of the list.

Program to demonstrate "Queue" class in Java's Collection Framework

The  Queue  interface order elements in a FIFO (first-in-first-out) manner. The  PriorityQueue  class has following methods: boolean add(E e) :  Inserts the specified element into the priority queue. void clear() :  Removes all of the elements from the priority queue. boolean contains(Object o) :  Returns true if the queue contains the specified element. boolean remove(Object o) :  Removes a single instance of the specified element from the queue, if it is present. int size() :  Returns the number of elements in the collection. PROGRAM import java.util.PriorityQueue; import java.util.Queue; class QueueDemo { public static void main(String[] args) { Queue<String> p=new PriorityQueue<String>(); p.add("Apple"); p.add("PineApple"); p.add("Orange"); p.add("Banana"); p.add("Raddish");

Program to demonstrate "Stack" class in Java's Collection Framework

The  Stack  class implements a LIFO (Last In First Out) stack of elements. For example, stack of coins. When you add a new element, it gets stacked on top of the others. When you pull an element off the stack, it removes the element at top. Hence it is called as LIFO (Last In First Out) or FILO (First In Last Out). Stack  is a subclass of Vector that implements a standard last-in, first-out stack. Stack only defines the default constructor, which creates an empty stack. Stack includes all the methods defined by Vector and adds several of its own. Stack class has following methods: boolean empty( ) :  Tests if this stack is empty. Returns true if the stack is empty, and returns false if the stack contains elements. Object peek( ) :  Returns the element on the top of the stack, but does not remove it.

Program to read records from file "stud.dat" and calculate total and percentage

Here, we read the details of students from file and display the total marks and percentage of each student on console. The  DataInputStream  class is used in the context of DataOutputStream and can be used to read primitives. Following is the constructor to create an InputStream: DataInputStream in = DataInputStream (InputStream in); PROGRAM import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; class ReadRecordFromFile { public static void main(String[] args) { try { File f=new File("stud.dat"); FileInputStream fos=new FileInputStream(f); DataInputStream dos=new DataInputStream(fos); int roll_no,m1,m2,tot; float per; String name;

Program to store the entered details (records) in a file named "stud.dat"

In this program, we have read the details of students like roll no, name, marks1, marks2 and store them in a file using  DataOutputStream  class. The  DataOutputStream  stream lets you write the primitives to an output source. Following is the constructor to create a DataOutputStream. DataOutputStream out = DataOutputStream( OutputStream out); PROGRAM import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.util.Scanner; class StoreRecordInFile { public static void main(String[] args) { try { File f=new File("stud.dat"); FileOutputStream fos=new FileOutputStream(f); DataOutputStream dos=new DataOutputStream(fos);

Program to copy contents of one file into other file

This program copied the contents of one file into other file suing  FileInputStream  and  FileOutputStream  classes. The name of files for reading and writing are passed through command line arguments. PROGRAM import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; class CopyFileContentsInOtherFile { public static void main(String[] args) { try { File f1=new File(args[0]); File f2=new File(args[1]);