Sunday, July 16, 2023

Main Event Classes in java.awt.event

 

Event ClassDescription
ActionEventGenerated when a button is pressed, a list item is double-clicked, or a menu item is selected.
AdjustmentEventGenerated when a scroll bar is manipulated.
ComponentEventGenerated when a component is hidden, moved, resized, or becomes visible.
ContainerEventGenerated when a component is added to or removed from a container.
FocusEventGenerated when a component gains or loses keyboard focus.
InputEvent Abstract superclass for all component input event classes.
ItemEventGenerated when a check box or list item is clicked; also occurs when a choice selection is made or a checkable menu item is selected or deselected.
KeyEventGenerated when input is received from the keyboard.
MouseEventGenerated when the mouse is dragged, moved, clicked, pressed, or released; also generated when the mouse enters or exits a component.
MouseWheelEventGenerated when the mouse wheel is moved
TextEventGenerated when the value of a text area or text field is changed.
WindowEventGenerated when a window is activated, closed, deactivated, deiconified, iconified, opened, or quit.

Events

 Events

an event is an object that describes a state change in a source. It can be generated as a consequence of a person interacting with the elements in a graphical user interface. Some of the activities that cause events to be generated are pressing a button, entering a character via the keyboard, selecting an item in a list, and clicking the mouse.

Events may also occur that are not directly caused by interactions with a user interface. For example, an event may be generated when a timer expires, a counter exceeds a value, software or hardware failure occurs, or an operation is completed.

 

Event Sources

A source is an object that generates an event. This occurs when the internal state of that object changes in some way. Sources may generate more than one type of event.

A source must register listeners in order for the listeners to receive notifications about a specific type of event. Each type of event has its own registration method. Here is the general form:

public void addTypeListener(TypeListener el)

Here, Type is the name of the event, and el is a reference to the event listener.

For example, the method that registers a keyboard event listener is called addKeyListener( ).

The method that registers a mouse motion listener is called addMouseMotionListener( ).

When an event occurs, all registered listeners are notified and receive a copy of the event object. This is known as multicasting the event. In all cases, notifications are sent only to listeners that register to receive them.

 

Event Listeners

A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications. The methods that receive and process events are defined in a set of interfaces found in java.awt.event.

For example, the MouseMotionListener interface defines two methods to receive notifications when the mouse is dragged or moved. Any object may receive and process one or both of these events if it provides an implementation of this interface.

Event Handling

 

1. Events,Event Sources,Event Listeners--  LINK

2. Main Event Classes in java.awt.event--LINK

3.The AdjustmentEvent Class--LINK

4.The ComponentEvent Class--LINK

5.The MouseEvent ClassLINK

6.The TextEvent Class LINK

7.Sources of Events link

8.Event Listener Interfaces LINK

9.AWT Classes LINK

10.Container class  LINK

Friday, July 14, 2023

FOL


Every child loves Santa.

∀ x (CHILD(x) → LOVES(x,Santa))

Everyone who loves Santa loves any reindeer.

∀ x (LOVES(x,Santa) → ∀ y (REINDEER(y) → LOVES(x,y)))

Rudolph is a reindeer, and Rudolph has a red nose.

REINDEER(Rudolph) ∧ REDNOSE(Rudolph)

Anything which has a red nose is weird or is a clown.

∀ x (REDNOSE(x) → WEIRD(x) ∨ CLOWN(x))

No reindeer is a clown.

¬ ∃ x (REINDEER(x) ∧ CLOWN(x))

Scrooge does not love anything which is weird.

∀ x (WEIRD(x) → ¬ LOVES(Scrooge,x))

(Conclusion) Scrooge is not a child.

¬ CHILD(Scrooge)


Anyone who buys carrots by the bushel owns either a rabbit or a grocery store.

∀ x (BUY(x) → ∃ y (OWNS(x,y) ∧ (RABBIT(y) ∨ GROCERY(y))))

Every dog chases some rabbit.

∀ x (DOG(x) → ∃ y (RABBIT(y) ∧ CHASE(x,y)))

Mary buys carrots by the bushel.

BUY(Mary)

Anyone who owns a rabbit hates anything that chases any rabbit.

∀ x ∀ y (OWNS(x,y) ∧ RABBIT(y) → ∀ z ∀ w (RABBIT(w) ∧ CHASE(z,w) → HATES(x,z)))

John owns a dog.

∃ x (DOG(x) ∧ OWNS(John,x))

Someone who hates something owned by another person will not date that person.

∀ x ∀ y ∀ z (OWNS(y,z) ∧ HATES(x,z) → ¬ DATE(x,y))

(Conclusion) If Mary does not own a grocery store, she will not date John.

(( ¬ ∃ x (GROCERY(x) ∧ OWN(Mary,x))) → ¬ DATE(Mary,John))



Every Austinite who is not conservative loves some armadillo.

∀ x (AUSTINITE(x) ∧ ¬ CONSERVATIVE(x) → ∃ y (ARMADILLO(y) ∧ LOVES(x,y)))

Anyone who wears maroon-and-white shirts is an Aggie.

∀ x (WEARS(x) → AGGIE(x))

Every Aggie loves every dog.

∀ x (AGGIE(x) → ∀ y (DOG(y) → LOVES(x,y)))

Nobody who loves every dog loves any armadillo.

¬ ∃ x ((∀ y (DOG(y) → LOVES(x,y))) ∧ ∃ z (ARMADILLO(z) ∧ LOVES(x,z)))

Clem is an Austinite, and Clem wears maroon-and-white shirts.

AUSTINITE(Clem) ∧ WEARS(Clem)

(Conclusion) Is there a conservative Austinite?

∃ x (AUSTINITE(x) ∧ CONSERVATIVE(x)).




Anyone whom Mary loves is a football star.

∀ x (LOVES(Mary,x) → STAR(x))

Any student who does not pass does not play.

∀ x (STUDENT(x) ∧ ¬ PASS(x) → ¬ PLAY(x))

John is a student.

STUDENT(John)

Any student who does not study does not pass.

∀ x (STUDENT(x) ∧ ¬ STUDY(x) → ¬ PASS(x))

Anyone who does not play is not a football star.

∀ x (¬ PLAY(x) → ¬ STAR(x))

(Conclusion) If John does not study, then Mary does not love John.

¬ STUDY(John) → ¬ LOVES(Mary,John)



Every coyote chases some roadrunner.

∀ x (COYOTE(x) → ∃ y (RR(y) ∧ CHASE(x,y)))

Every roadrunner who says ``beep-beep'' is smart.

∀ x (RR(x) ∧ BEEP(x) → SMART(x))

No coyote catches any smart roadrunner.

¬ ∃ x ∃ y (COYOTE(x) ∧ RR(y) ∧ SMART(y) ∧ CATCH(x,y))

Any coyote who chases some roadrunner but does not catch it is frustrated.

∀ x (COYOTE(x) ∧ ∃ y (RR(y) ∧ CHASE(x,y) ∧ ¬ CATCH(x,y)) → FRUSTRATED(x))

(Conclusion) If all roadrunners say ``beep-beep'', then all coyotes are frustrated.

(∀ x (RR(x) → BEEP(x)) → (∀ y (COYOTE(y) → FRUSTRATED(y)))


Anyone who rides any Harley is a rough character.

∀ x ((∃ y (HARLEY(y) ∧ RIDES(x,y))) → ROUGH(x))

Every biker rides [something that is] either a Harley or a BMW.

∀ x (BIKER(x) → ∃ y ((HARLEY(y) ∨ BMW(y)) ∧ RIDES(x,y)))

Anyone who rides any BMW is a yuppie.

∀ x ∀ y (RIDES(x,y) ∧ BMW(y) → YUPPIE(x))

Every yuppie is a lawyer.

∀ x (YUPPIE(x) → LAWYER(x))

Any nice girl does not date anyone who is a rough character.

∀ x ∀ y (NICE(x) ∧ ROUGH(y) → ¬ DATE(x,y))

Mary is a nice girl, and John is a biker.

NICE(Mary) ∧ BIKER(John)

(Conclusion) If John is not a lawyer, then Mary does not date John.

¬ LAWYER(John) → ¬ DATE(Mary,John)



Every child loves anyone who gives the child any present.

∀ x ∀ y ∀ z (CHILD(x) ∧ PRESENT(y) ∧ GIVE(z,y,x) → LOVES(x,z)

Every child will be given some present by Santa if Santa can travel on Christmas eve.

TRAVEL(Santa,Christmas) → ∀ x (CHILD(x) → ∃ y (PRESENT(y) ∧ GIVE(Santa,y,x)))

It is foggy on Christmas eve.

FOGGY(Christmas)

Anytime it is foggy, anyone can travel if he has some source of light.

∀ x ∀ t (FOGGY(t) → ( ∃ y (LIGHT(y) ∧ HAS(x,y)) → TRAVEL(x,t)))

Any reindeer with a red nose is a source of light.

∀ x (RNR(x) → LIGHT(x))

(Conclusion) If Santa has some reindeer with a red nose, then every child loves Santa.

( ∃ x (RNR(x) ∧ HAS(Santa,x))) → ∀ y (CHILD(y) → LOVES(y,Santa))



Every investor bought [something that is] stocks or bonds.

∀ x (INVESTOR(x) → ∃ y ((STOCK(y) ∨ BOND(y)) ∧ BUY(x,y)))

If the Dow-Jones Average crashes, then all stocks that are not gold stocks fall.

DJCRASH → ∀ x ((STOCK(x) ∧ ¬ GOLD(x)) → FALL(x))

If the T-Bill interest rate rises, then all bonds fall.

TBRISE → ∀ x (BOND(x) → FALL(x))

Every investor who bought something that falls is not happy.

∀ x ∀ y (INVESTOR(x) ∧ BUY(x,y) ∧ FALL(y) &rarrm; ¬ HAPPY(x))

(Conclusion) If the Dow-Jones Average crashes and the T-Bill interest rate rises, then any investor who is happy bought some gold stock.

( DJCRASH ∧ TBRISE ) → ∀ x (INVESTOR(x) ∧ HAPPY(x) → ∃ y (GOLD(y) ∧ BUY(x,y)))



Every child loves every candy.

∀ x ∀ y (CHILD(x) ∧ CANDY(y) → LOVES(x,y))

Anyone who loves some candy is not a nutrition fanatic.

∀ x ( (∃ y (CANDY(y) ∧ LOVES(x,y))) → ¬ FANATIC(x))

Anyone who eats any pumpkin is a nutrition fanatic.

∀ x ((∃ y (PUMPKIN(y) ∧ EAT(x,y))) → FANATIC(x))

Anyone who buys any pumpkin either carves it or eats it.

∀ x ∀ y (PUMPKIN(y) ∧ BUY(x,y) → CARVE(x,y) ∨ EAT(x,y))

John buys a pumpkin.

∃ x (PUMPKIN(x) ∧ BUY(John,x))

Lifesavers is a candy.

CANDY(Lifesavers)

(Conclusion) If John is a child, then John carves some pumpkin.

CHILD(John) → ∃ x (PUMPKIN(x) ∧ CARVE(John,x))



REF:::https://www.cs.utexas.edu/

AI THEORY

1. What is AI ?

2. Turing Test  

3. Strong AI,Weak AI,Applied AI,Cognitive AI

4. Agents,Intelligent Agents,Rational Agent - JAVAPOINT LINK

5. ideal agent,autonomous agent

5. Agent Faculties



1.syntax of a language

2.The semantics

3.Sound,complete 

4. tautologies,satisfiable

5.Modus Ponens or Implication-Elimination,Modus tollens

 Resolution,



1.Atomic sentences,Complex sentences,Universal quantification (V),Existential quantification

2.Forward-chaining algorithm,Backward-chaining algorithm

3.Skolemization
4.A Horn clause is a clause with at most one positive literal




1.Semantic Nets
2.Inferential Knowledge
3.Simple relational knowledge 
4.Inferential Knowledge
5.Procedural knowledge





Frames, scriptLINK

Sunday, July 9, 2023

WRAPPER CLASS-CHARACTER

 Constructor

Character(char c)


Methods: 

1. isLetter (): This method returns a boolean value, i.e true or false. It returns true if the argument passed in the method is a letter i.e any character in between a-z and A-Z. Otherwise it returns false.

2.isDigit(): The isDigit method as the name suggests checks whether the parameter passed to it is a digit or not. It returns true if the argument passed is a digit. Else it returns false.

3.sWhitespace(): It checks whether the value of the argument passed is a white space or not. However this method also returns true if the argument is a tab or new line.

4.isUppercase(): This method is primarily used for checking whether the character passed in the argument is an UpperCase character or not. It returns true if the character is in Uppercase. If not, it returns false.

5.isLowercase(): This method is primarily used for checking whether the character passed in the argument is a LowerCase character or not. It returns true if the character is in LowerCase. If not, it returns false.

6.toUpperCase(): This method is a character returning method. This takes the argument and converts it into an uppercase alphabet. It returns an uppercase alphabet.

7.toLowerCase (): Java toLowerCase method converts the arguments passed to it into lowercase. However, if a numeric value i.e ASCII value of an UpperCase letter is passed through it returns the ASCII value of the corresponding lowercase alphabet.

8.toString (): This method has the responsibility of converting the character arguments passed through it, to String objects for manipulation as and when required by the programmer. ASCII values cannot be passed as arguments here.



Escape Sequences in Java

There are some particular characters, which when preceded with a backslash(\), holds special meaning to the compiler. Some of the escape sequences are:


\n- creates a new line

\t- creates a tab space

\b- inserts a single backspace

\r-inserts carriage return

\\- inserts a backslash character

\’- inserts single quote character

\” – inserts double-quote character



REF:https://data-flair.training/

Wrapper Classes-INTRODUCTION

 Wrapper Classes

A Wrapper class in Java is a class whose object wraps or contains primitive data types. When we create an object to a wrapper class, it contains a field and in this field, we can store primitive data types. In other words, we can wrap a primitive value into a wrapper class object. Let’s check on the wrapper classes in Java with examples:


Need of Wrapper Classes

There are certain needs for using the Wrapper class in Java as mentioned below:


They convert primitive data types into objects. Objects are needed if we wish to modify the arguments passed into a method (because primitive types are passed by value).

The classes in java.util package handles only objects and hence wrapper classes help in this case also.

Data structures in the Collection framework, such as ArrayList and Vector, store only objects (reference types) and not primitive types.

An object is needed to support synchronization in multithreading.

Advantages of Wrapper Classes

Collections allowed only object data.

On object data we can call multiple methods compareTo(), equals(), toString()

Cloning process only objects

Object data allowed null values.

Serialization can allow only object data.





REF:https://www.geeksforgeeks.org/wrapper-classes-java/

WRAPPER CLASS-INTEGER

 Constructors: 

1.public Integer(int b)

2.public Integer(String s) throws NumberFormatException


Methods: 

1. toString() : Returns the string corresponding to the int value. 

2.toHexString() : Returns the string corresponding to the int value in hexadecimal form, that is it returns a string representing the int value in hex characters-[0-9][a-f] 

3.toOctalString() : Returns the string corresponding to the int value in octal form, that is it returns a string representing the int value in octal characters-[0-7] 

4. toBinaryString() : Returns the string corresponding to the int value in binary digits, that is it returns a string representing the int value in hex characters-[0/1] 

5.valueOf() : returns the Integer object initialised with the value provided. 

6.valueOf(String val,int radix): Another overloaded function which provides function similar to new Integer(Integer.parseInteger(val,radix))

7.parseInt() : returns int value by parsing the string in radix provided. Differs from valueOf() as it returns a primitive int value and valueOf() return Integer object. 

8.rotateLeft() : Returns a primitive int by rotating the bits left by given distance in two’s complement form of the value given. When rotating left, the most significant bit is moved to the right-hand side, or least significant position i.e. cyclic movement of bits takes place. Negative distance signifies right rotation.

9.rotateRight() : Returns a primitive int by rotating the bits right by given distance in the twos complement form of the value given. When rotating right, the least significant bit is moved to the left hand side, or most significant position i.e. cyclic movement of bits takes place. Negative distance signifies left rotation. 

10.bitcount() : Returns number of set bits in twos complement of the integer given. 

11. numberOfTrailingZeroes() : Returns number of 0 bits following the last 1 bit in twos complement form of the value, i.e. if the number in twos complement form is 0000 1010 0000 0000, then this function would return 9. 

12.equals() : Used to compare the equality of two Integer objects. This method returns true if both the objects contain the same int value. Should be used only if checking for equality. In all other cases, the compareTo method should be preferred. 

13.compareTo() : Used to compare two Integer objects for numerical equality. This should be used when comparing two Integer values for numerical equality as it would differentiate between less and greater values. Returns a value less than 0,0, a value greater than 0 for less than, equal to and greater than. 

14.static int max(int a, int b): This method returns the greater of two int values as if by calling Math.max.

15.static int min(int a, int b): This method returns the smaller of two int values as if by calling Math.min.

16.static int sum(int a, int b): This method adds two integers together as per the + operator.

17.

WRAPPER CLASS-AUTOBOX UNBOX

 wrapper class:

Primitive Type Wrapper class

boolean                    Boolean

char                    Character

byte                            Byte

short                    Short

int                            Integer

long                            Long

float                    Float

double                    Double



Autoboxing

The automatic conversion of primitive data type into its corresponding wrapper class is known as autoboxing, for example, byte to Byte, char to Character, int to Integer, long to Long, float to Float, boolean to Boolean, double to Double, and short to Short.


class BoxingExample1{  

  public static void main(String args[]){  

    int a=50;  

        Integer a2=new Integer(a);//Boxing    

        Integer a3=5;//Boxing            

        System.out.println(a2+" "+a3);  

 }   

}  

The automatic conversion of wrapper class type into corresponding primitive type, is known as Unboxing.

Unboxing

class UnboxingExample1{  

  public static void main(String args[]){  

    Integer i=new Integer(50);  

        int a=i;            

        System.out.println(a);  

 }   

}