Posts

Showing posts with the label Java

How use file chooser in Java eclipses windows builder

Image
There is no  JFileChooser  present by default. But you can add it. Follow the steps: Go to system and click on  Choose Component 2.. Now search for your component and add it. For further details see this post JFileChooser and eclipse

Method Overloading Vs Method Overriding

Following concepts demonstrate different types of polymorphism in java; 1)  Method Overloading 2)  Method Overriding 1) Method Overloading: In Java, it is possible to define two or more methods of same name in a class, provided that there argument list or parameters are different. This concept is known as Method Overloading. Rules for Method Overloading Overloading can take place in the same class or in its sub-class. Overloaded methods must have a different argument list. The parameters may differ in their type or number, or in both. They may have the same or different return types. It is also known as compile time polymorphism. 2) Method Overriding Child class has the same method as of base class. In such cases child class overrides the parent class method without even touching the source code of the base class. This feature is known as method overriding. Rules for Method Overriding: Applies only to inherited methods object type determines which overri...

Multi-threading in Java (source code example)

Image
Multi-threading in java is a process of executing multiple threads simultaneously. Thread is basically a lightweight sub-process, a smallest unit of processing. Multiprocessing and multi-threading, both are used to achieve multitasking. But we use multi-threading than multiprocessing because threads share a common memory area. They don't allocate separate memory area so saves memory, and context-switching between the threads takes less time than process. Java Multi-threading is mostly used in games, animation etc. Advantages: 1) It doesn't block the user because threads are independent and you can perform multiple operations at same time. 2) You  can perform many operations together so it saves time. 3) Threads are independent so it doesn't affect other threads if exception occur in a single thread. Source Code: package multiThreading; //Class no: 1 class Thread1 extends Thread {     ...

Playing card Game : bhabhi Thulla

Image
To get complete java project file click here: Playing card game Class No:1 package PlayingCard; public class Card { // fields for class public String face; // card number ace, deuce.... public String suit;// signs of card hearts diamond .... public int cardId;// for card ID which is get from user public int cardValue;// // constructor for the class public Card(String faceOfcard, String suitOfcard, int id, int cV ) { face= faceOfcard; suit = suitOfcard; cardId=id; cardValue=cV; } // only for get details of the class public String toString() { return  cardId +":- "+face + " of " + suit;// for get this kind of output "Ace of Heart" }// toString ends here }// class ends here Class No:2  package PlayingCard; import java.util.Random; public class deckOfcard { public Card[] deck; // declare a array of Card data type (Card...