Order of Precedence for Java Operators

Similar to Mathematics' PEMDAS or MDAS, Java also has its own Order of Precedence which is to be followed when understanding, creating or reading Java programs. It is a way for Java to determine which operator should it evaluate first before the others.

Below is the Order of Precedence displayed from the highest to the lowest precedence:


Priority  Operator  Use
1[ ]index of arrays

( )calling methods

.access members
2++increment

--decrement

+, -unary add, subtract

~NOT (bitwise)

!NOT (boolean / logical)

(type)new type cast

(new)new object
3*, /, %multiplication, division, modulo (remainder)
4+, - addition, subtraction 

+concatination
5<<signed bit shift left

>>signed bit shift right

>>>unsigned bit shift right
6<, <=less than, less than or equal to

>, >=greater than, greater than or equal to

instanceofcalling/testing references
7= =is equal to

! =is not equal to
8&AND (bitwise and logical)
9^XOR (bitwise and logical)
10|OR (bitwise and logical)
11&&Boolean AND
12||Boolean OR
13?, , , :conditional statements
14=assignment

*=, /=, +=, -=combinated assignment

%=combinated assignment

<<=, >>=combinated assignment

&=,^=, |=combinated assignment


Reminder:
  • Expressions within the parenthesis are first to be evaluated
  • Nested Parenthesis are evaluated from the inner to the outer parenthesis.
  • Higher precedence are done first before the lower precedence.

Stacks and Queues in Java

The stack and the queue is defined by two basic operations: insert a new item, and remove an item.



Representing stacks and queues with arrays is a natural idea. The rule used for a queue is to always remove the item that has been in the collection the most amount of time. This policy is known as first-in-first-out or FIFO. The rule used for a stack is to always remove the item that has been in the collection the least amount of time. This policy is known as last-in first-out or LIFO.

In stacking, we name the stack insert method push() and the stack remove operation pop(). When we queue, we name the insert method enqueue() and the remove dequeue().

Here's an exercise we just did in school today though it's quite complicated, i just wanna share the codes. It's about push(inserting) and pop(deleting) for the stack; as well as enqueue(inserting) and dequeue(deleting). Download the codes below:







It's important to download all three files.

VB6 Listbox

I'm posting an exercise of Visual Basic Properties for the List Box tool. Check this out.

Given this two listboxes where the first listbox lists the different states of the United States, and the second listbox with an empty list.

Image by VBExplorer

Let's rename the lists of the first listbox. Instead of a list of the different states, try to list down different dishes and put a little label below the listbox with the caption, Menu. Name the first listbox as lstMenu. Under the second listbox with an empty list, put another label below it with the caption of Orders. Name the second list box as lstOrders.

So what's the catch? Once you select a dish from lstMenu and press the >>>> button, that dish will be copied to lstOrders.

Solution:

Double click on the >>>> button and type the following:

Private Sub cmdLeft_Click()
listOrders.RemoveItem listOrders.ListIndex
End Sub

Next, double click on the second button (with the caption of <<<<) and type the code:

Private Sub cmdRight_Click()
listOrders.AddItem (listMenu)
End Sub

Once you get it right, you are now free to play with menu-order system by clicking on the >>>> and <<<< buttons. See how the texts appear and disappear in the empty listbox.

What is the use of Compiling in Java?


 Here's a diagram of Computer Languages.

Machine language is all it starts since our computer can only read numbers 1 and 0. Then there goes Low-level languages, where a very good example is Assembly language and the C programming (language. Then there is High-level language, where you can find Visual Basic and Java.


So what's the use of Compiling in Java? Why can't you not run the program right away without compiling?

Because Java is one of the High-level languages, it translates it to a low level language and finally, machine language since as said earlier that our computer can only read binary digits.



So that means that the codes we type and the variables we create are translated to a language which the computer can only understand.

We cannot understand Machine Language immediately. It takes time to understand each line of Machine Language since each 1 and 0 has its own designated meaning depending on how we code it.

For Next Loops in Visual Basic 6.0

A For Next Loop lets you execute a specific group of program statements a  set of number times in an event procedure. This is useful if you are performing several related calculations, working with elements on screen ot processing several pieces for user inputs.

A For Next Loop is just a shortcut of writing a long list of statements. Because each group of statements in such a list would do essentially the same thing, VB lets you define just one group of statements and request that it would be executed as many times as you want.

In a For Next Loop, start and end determine how long the loop runs

Check the syntax below:


for your_variable = start To end
     code block
     or
     statements to be repeated
Next your_variable

Example:
The following For Next Loop sounds four beeps in rapid succession from the computer's speakers:

For x =  1 To 4
     Beep
Next x

so the output of that would be:

Beep
Beep
Beep
Beep



Based from the book Step by Step Microsoft Visual Basic

Until Keyword in Do [While] Loops

Visual Basic lets you try the Until keyword in Do [While] Loops until a certain condition is true. The Until keyword can be used at the top or the bottom of a Do [While] Loop to test a condition (similar to the While Loop).

Check this example below
Do
     InputName = InputBox("Enter item or type Finish to quit.")
     If InputName <> "Finish" Then Print InputName
Loop Until InputName = "Finish"


Based from the book Step by Step Microsoft Visual Basic

Do Loops on Visual Basic

A Do Loop executes a line, or lines of code until a specific condition is met. It is sometimes referred as Do While Loops to some.

For example, you want to let the user enter names in a database until the user types the word Finish in an input box, or maybe until the user clicks the Done button. In that case, you can use a Do [While] Loop cycle until the next string Finish is entered or until the user clicks the Done button.

A Do [While] Loop has several formats, depending on where and how the loop condition is evaluated. The most common syntax used is:

Do While (condition)
       code block
       or
       block of statements
       to be executed
Loop




More examples will be posted soon.




Based on the book, Step by Step Microsoft Visual Basic 6.0

Extended Search

Custom Search