Java AWT :

Java AWT for Abstract windows toolkit. The AWT is part of the Java Foundation Classes (JFC) the standers API for providing Graphical user Interfaces(GULs)for java programs. 

The AWT contains numerous classes and methods that allow you to create and mange windows. Although the main Purpose of the AWT is to support applet windows, it can also be used to create stand-alone windows that run in a GUI environment, such as windows. 


Java AWT Hierarchy :


Container :

The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. The classes that extends Container class are known as container such as Frame, Dialog and Panel.

Methods :
  • void Add(Component c)
  • void remove(Component c)
  • void setLayout(LayoutManager m)
  • void validate()
  • int getComponentCount()
  • component getComponentAt(int x,int y)


Window :

The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window.

Methods :
  • Windows(Frame owner)
  • Windows(Windows owner)


Panel :

The Panel is the container that doesn't contain title bar and menu bars. It can have other components like button, textfield etc.

Frame :

The Frame is the container that contain title bar and can have menu bars. It can have other components like button, textfield etc.

Useful Methods of Component class :

MethodDescription
public void add(Component c)inserts a component on this component.
public void setSize(int width,int height)sets the size (width and height) of the component.
public void setLayout(LayoutManager m)defines the layout manager for the component.
public void setVisible(boolean status)changes the visibility of the component, by default false.

Java AWT Example :

To create simple awt example, you need a frame. There are two ways to create a frame in AWT.
  • By extending Frame class (inheritance)
  • By creating the object of Frame class (association)

Simple example of AWT by inheritance :

  1. import java.awt.*;  
  2. class First extends Frame{  
  3. First(){  
  4. Button b=new Button("click me");  
  5. b.setBounds(30,100,80,30);// setting button position  
  6.   
  7. add(b);//adding button into frame  
  8. setSize(300,300);//frame size 300 width and 300 height  
  9. setLayout(null);//no layout manager  
  10. setVisible(true);//now frame will be visible, by default not visible  
  11. }  
  12. public static void main(String args[]){  
  13. First f=new First();  
  14. }}  




Java AWT :

Java AWT for Abstract windows toolkit. The AWT is part of the Java Foundation Classes (JFC) the standers API for providing Graphical user Interfaces(GULs)for java programs. 

The AWT contains numerous classes and methods that allow you to create and mange windows. Although the main Purpose of the AWT is to support applet windows, it can also be used to create stand-alone windows that run in a GUI environment, such as windows. 


Java AWT Hierarchy :


Container :

The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. The classes that extends Container class are known as container such as Frame, Dialog and Panel.

Methods :
  • void Add(Component c)
  • void remove(Component c)
  • void setLayout(LayoutManager m)
  • void validate()
  • int getComponentCount()
  • component getComponentAt(int x,int y)


Window :

The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window.

Methods :
  • Windows(Frame owner)
  • Windows(Windows owner)


Panel :

The Panel is the container that doesn't contain title bar and menu bars. It can have other components like button, textfield etc.

Frame :

The Frame is the container that contain title bar and can have menu bars. It can have other components like button, textfield etc.

Useful Methods of Component class :

MethodDescription
public void add(Component c)inserts a component on this component.
public void setSize(int width,int height)sets the size (width and height) of the component.
public void setLayout(LayoutManager m)defines the layout manager for the component.
public void setVisible(boolean status)changes the visibility of the component, by default false.

Java AWT Example :

To create simple awt example, you need a frame. There are two ways to create a frame in AWT.
  • By extending Frame class (inheritance)
  • By creating the object of Frame class (association)

Simple example of AWT by inheritance :

  1. import java.awt.*;  
  2. class First extends Frame{  
  3. First(){  
  4. Button b=new Button("click me");  
  5. b.setBounds(30,100,80,30);// setting button position  
  6.   
  7. add(b);//adding button into frame  
  8. setSize(300,300);//frame size 300 width and 300 height  
  9. setLayout(null);//no layout manager  
  10. setVisible(true);//now frame will be visible, by default not visible  
  11. }  
  12. public static void main(String args[]){  
  13. First f=new First();  
  14. }}  




DataBinding with GridView Control :

Step 1: Create and Add a new SQL Server Database to your project by right-clicking on the App_Data Folder in the solution Explorer > Choose Add New Item > Choose SQL Server Database.



Step 2 : Create a database in the App_Data folder called Employee.mdf. Columns : empif, empname, empphone, empemail, empcity.


Step 3: Then right-click on the employee table- Opt show data  and add some records to this table.


Step 4: Access the database in ASP.NET page.
            Start by adding a SqlDataSource control to your emp.aspx page From the Design view, the SqlDataSource control contains a "smart tag" that lists its common functionality.


Step 5 : Choose a Data Connection - This screen has a drop-down list of those database in the App_Data folder. There's also a New Connection button that you can click if you want to connect to a new database. Choose the employee.mdf option from the drop=down list.


Step 6 : Configure the SELECT Statement


Step 7: Test Query


Step 8: Display the data from the database on the web page's grid view.
             Add a data control - Let's use the GridView control, which is also found in the "Data" section of the Toolbox. Drag a Gridview control onto your ASP.NET page's.


Step 9: Run the .aspx file to see the below output





Let’s say someone wants to give you their SQL Server database. Maybe they want you to manage it, troubleshoot it, or learn from it. So they hand you a .MDF file and  .LDF file and tell you that you need SQL server 2008 R2 to open them. So you install SQL Server 2008 R2 Express (which, to your relief, is free). You open SQL Server Management Studio(SSMS), and you try to open the .MDF file. You get the following error:

The Solution:

.MDF files are SQL Server database files and .LDF files are the associated log files. But you can’t really “open” them. Instead, you have to “attach” to them. Once you attach, you’ll see the database in the object explorer of SSMS.

How to Attach in a Perfect World:

There’s a couple of different methods. I’ll give you the “easy” way through SQL Server Management Studio (SSMS) and then point you to other methods using T-SQL queries.

  1. Launch SSMS.
  2. Connect to your SQL Server Instance.
  3. Right-click on Databases in the Object Explorer.
  4. Click Attach.
  5. In the Attach Databases window, click the Add button.
  6. Navigate to the directory containing the .MDF and .LDF files.
  7. Select the .MDF file, and press OK.
  8. Press OK again to attach the database.
You should see the database appear in the Databases node (press F5 if you don’t). You can now explore the data using SSMS. These same steps are documented in the MSDN here. I’m just summarizing to make it easier for you.

There are two ways to accomplish the same thing in a T-SQL script. First, you can use the sp_attach_db stored procedure. This is shown here. Or you can use the CREATE DATABASE command with the FOR ATTACH argument.

the World isn’t Perfect:

If your database is successfully attached, then stop reading and go use it. But if you see any errors or unexpected behaviors, I’ll try to share some troubleshooting suggestions.

First, you may get a generic error like the following..

You might be asking, “Where’s the hyperlink?” I’ll show you in the next screenshot (circled in red), and it will also be our first example.

1. Access Denied:


This access denied error could have a few different causes. Basically, you don’t have the required access to the .MDF or .LDF files. This can happen if you get the file from someone else. When they detach the database file, the file permissions are changed to give only that user full control. Also, even if you see that the file has full control for the Administrators group, it may not be enough. Remember in Windows 7/Vista, those permissions are often only realized when you’re running an application as an Administrator.

So here are several choices to fix it:

  1. The easiest solution is to close SSMS and then run it as an Administrator. Perform the attach as an Administrator, and it’s likely going to work.
  2. Another solution is to explicitly grant full control to the .MDF and .LDF files to your user account. This can be done by right-clicking the files, selecting Properties, and modifying the Security tab.
  3. A final solution is to copy the files to the default directory for your other database files. To find out what that is, you can use the sp_helpfile procedure in SSMS. On my machine it is: C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA. By copying the files to this directory, they automatically get permissions applied that will allow the attach to succeed.

2. Access Denied Variation 2 :

There is another variation of the Access Denied message that has a simple solution:


This error means that the file is already opened exclusively by another application. The most likely cause is that this database file is already attached to an instance of SQL Server. Double-check your list of databases to see whether it is already in the list. It’s also possible for applications to use .MDF files directly with a feature called User Instances. If an application is using a .MDF file in this way, then it would have to close before you could attach the to that database file.

3. Database is Read-only :

This is not so much an error as an undesired result. When you load the database, it is in a read-only state. You can tell by the gray shading of the databasee icon (not to mention the “Read-Only” label next to it).


The most probable cause is that the .MDF file you attached to is read-only. Just right-click on the .MDF and .LDF files, select properties, and then uncheck the Read-only check box.


4. Unable to Downgrade :

The next error happens when you try to attach a database of a higher version of SQL Server (like SQL Server 2008 R2) to a SQL Server Instance of a lower version (like SQL Server 2005).


his has never been supported. You can attach a database of an older version of SQL Server to a newer version, but you can’t go the other direction. If you want to verify the version of SQL Server you’re running, see this post




If you work with Network Interface cards (NIC) or manage systems, you will want to become familiar with the new Windows Server 2012 PowerShell Cmdlets that simplify many common NIC and Network configuration tasks. These Cmdlets make it easy to automate the configuration management multiple NICs on multiple servers.
In subsequent installments of this series, we'll be looking at Network latency and adjusting NIC parameters quite a bit, so becoming familiar with the basics is time well spent.
In this article I will demonstrate how to use PowerShell to perform NIC configuration tasks, including:
    • Naming your NIC
    • Getting and setting advanced NIC parameter settings
    • Determining valid NIC parameters
    • Resetting Parameters to Factory Default Values
    • Using the -NoRestart flag to 'batch' changes
    • Determining the NIC Driver Version
The reference documentation for these Cmdlets is available on-line at
These commands can be used on your local machine, remote machines, or to configure an arbitrary number of NIC adapters on an arbitrary number of machines.
There are a large number of CmdLets covering virtually all aspects of network configuration, but I’m going to limit myself to performing some common NIC configuration tasks.

Naming Your NIC


If you have multiple NICs, remembering which is which can be difficult. The Consistent Device Naming (CDN) feature added in Windows 8 and Windows Server 2012 makes it easier for those who are concerned with network cabling to determine which physical network interface is which.
And with PowerShell, you can also give your NICs descriptive names which you can use for subsequent configuration tasks. This is particularly useful if you have multiple NICs or if you manage multiple servers.
Let's get a list of all the NICs on my machine. (abbreviated to fit on the page). The names below don't tell us very much about which NIC interface is used for:
PS > Get-NetAdapter
NameInterfaceDescriptionifIndexStatus ...
WiredEthernetConnec...6Intel(R) Gigabit ET Dual Port Serv...#417Up
WiredEthernetConnec...5Intel(R) Gigabit ET Dual Port Serv...#315Up
WiredEthernetConnec...4Realtek PCIe GBE Family Controller15Disconnected
WiredEthernetConnec...3NetEffect(TM) Ethernet Server Cluste...14Up
WiredEthernetConnec...2Intel(R) Gigabit ET Dual Port Serv...#213Up
WiredEthernetConnectionIntel(R) Gigabit ET Dual Port Server...12Disabled

Let's rename the NICs to something easier to understand. In this example, I'll name the NICs to reflect their function.
PS> Rename-NetAdapter -Name "Wired Ethernet Connection 4" PublicInternet1

After a few more of these commands, we arrive at a much easier to understand display. Notice each NIC now has a descriptive name:
PS > Get-NetAdapter
NameInterfaceDescriptionifIndexStatus ...
PublicInternet16Intel(R) Gigabit ET Dual Port Serv...#417Up
PublicInternet25Intel(R) Gigabit ET Dual Port Serv...#315Up
ManagementNetwork4Realtek PCIe GBE Family Controller15Up
DatabaseLink3NetEffect(TM) Ethernet Server Cluste...14Disconnected
ClusterNetwork2Intel(R) Gigabit ET Dual Port Serv...#213Up
BackupLink1Intel(R) Gigabit ET Dual Port Server...12Disabled

Looking at this table, you can answer questions like "Why can't I reach the database?" It's disconnected. And you can fix this admittedly contrived example problem by enabling the back-up link - by name.
PS> Enable-NetAdapter BackupLink
Now that we have an easier way to refer to specific NIC interfaces, let’s move on to NIC configuration parameters.

Viewing and Setting Advanced NIC Parameters


With Windows Server 2012, PowerShell makes it easy to set and check the network parameters that previously had to be set using the Network Control Panel application. You can still use the control panel application of course, but PowerShell makes it possible to automate the process.
Let's try some practical examples. First well look at some NIC parameters, then see how to change them from PowerShell. To examine the NIC parameters for the PublicInternet1 NIC we can use.
To save a little typing, I'm going to abbreviate the NIC Name PublicIntenet1 as P*1. PowerShell will expand the wild-card for me.
PS C> Get-NetAdapterAdvancedProperty P*1
NameDisplayNameDisplayValueRegistryKeywordRegistrValue
PublicInternet1Flow ControlTx Enabled*FlowControl{1}
PublicInternet1Interrupt ModerationEnabled*InterruptMo...{1}
PublicInternet1IPv4 Checksum OffloadRx & Tx Enabled*IPChecksumO...{3}
PublicInternet1IPsec OffloadAuth Header & ESP Enabled*IPsecOffloadV2{3}
PublicInternet1Jumbo PacketDisabled*JumboPacket{1514}
PublicInternet1Large Send Offload V2 (IPv4)Enabled*LsoV2IPv4{1}
PublicInternet1Large Send Offload V2 (IPv6)Enabled*LsoV2IPv6{1}
PublicInternet1Max number of RSS Processors8*MaxRssProce...{8}
PublicInternet1Preferred NUMA nodeSystem Default *NumaNodeId{65535}
PublicInternet1Maximum Number of RSS Queues2 Queues*NumRssQueues{2}
PublicInternet1Priority & VLANPriority & VLAN Enabled*PriorityVLA...{3}
PublicInternet1Receive Buffers512*ReceiveBuffers{512}
PublicInternet1Receive Side ScalingDisabled*RSS{0}
PublicInternet1Speed & DuplexAuto Negotiation*SpeedDuplex{0}
PublicInternet1SR-IOVDisabled*Sriov{0}
PublicInternet1TCP Checksum Offload (IPv4)Rx & Tx Enabled*TCPChecksum...{3}
PublicInternet1TCP Checksum Offload (IPv6)Rx & Tx Enabled*TCPChecksum...{3}
PublicInternet1Transmit Buffers2048*TransmitBuf...{2048}
PublicInternet1UDP Checksum Offload (IPv4)Rx & Tx Enabled*UDPChecksum...{3}
PublicInternet1UDP Checksum Offload (IPv6)Rx & Tx Enabled*UDPChecksum...{3}
PublicInternet1Virtual Machine QueuesDisabled*VMQ{0}
PublicInternet1Interrupt Moderation RateAdaptiveITR{65535}
PublicInternet1Log Link State EventEnabledLogLinkState...{51}
PublicInternet1Gigabit Master Slave ModeAuto DetectMasterSlave{0}
PublicInternet1Locally Administered Address--NetworkAddress{--}
PublicInternet1Wait for LinkAuto DetectWaitAutoNegC...{2}

Let's increase the number of Receive Buffers to 2048. (Increasing the number of Receive Buffers (aka receive descriptors) increases the size of the buffering area used to hold arriving Ethernet frames. This buffering area resides in an area of system memory and is allocated from non-paged pool. On busy servers with lots of network traffic, increasing the number of buffers reduces the probability that an arriving frame will need to be discarded because there was no buffering available. The numeric value refers to the maximum number of Ethernet frames that can be buffered.)
PS> Set-NetAdapaterAdvancedProperty P*1 -DisplayName "Receive Buffers" -DisplayValue 2048.

Now let's check it.
PS> Get-NetAdapterAdvancedProperty P*1 -DisplayName "Receive Buffers"
NameDisplayNameDisplayValueRegistryKeywordRegistryValue
PublicInternet1Receive Buffers2048*ReceiveBuffers{2048}

This small example illustrates that by using the -DisplayName and -DisplayValue switches, we can set the NIC Advanced Configuration parameters from PowerShell.
This means it is also easy to automate the checking and setting of NIC parameters. For large installations, the parameters can be saved in a SQL-Server database, or in an XML file, or furnished by a Web Service, or simply in a comma separated variable (csv) file. Powershell makes it easy to access any of these.

Determining Valid NIC Parameter Values

Different kinds of NICs may have different parameter settings. How do you know what parameters values are valid for your NIC? You can use PowerShell to determine which values are valid for a particular parameter on a particular NIC. The values are supplied by the NIC Driver supplier and will reflect NIC specific capabilities.
Let's see all the parameters and their permissible values for the PublicInternet1 NIC and format the display as a table using 'ft' (format table).
PS> Get-NetAdapterAdvancedProperty P*1 | ft DisplayName, DisplayValue, ValidDisplayValues
DisplayNameDisplayValueValidDisplayValues
-----------------------------------------
Flow ControlTx Enabled{Disabled, Tx Enabled, Rx Enabled...
Interrupt ModerationEnabled{Disabled, Enabled}
IPv4 Checksum OffloadRx & Tx Enabled{Disabled, Tx Enabled, Rx Enabled,..
IPsec OffloadAuth Header & ESP Enabled{Disabled, Auth Header Enabled, ...
Jumbo PacketDisabled{Disabled, 4088 Bytes, 9014 Bytes}
Large Send Offload V2 (IPv4)Enabled{Disabled, Enabled}
Large Send Offload V2 (IPv6)Enabled{Disabled, Enabled}
Max number of RSS Processors8{1, 2, 4, 8}
Preferred NUMA nodeSystem Default{System Default, Node 0, Node 1, N..
Maximum Number of RSS Queues2 Queues{1 Queue, 2 Queues, 4 Queues, 8...
Priority & VLANPriority & VLAN Enabled{Priority & VLAN Disabled, Priority
Receive Buffers2048
Receive Side ScalingDisabled{Disabled, Enabled}
Speed & DuplexAuto Negotiation{Auto Negotiation, 10 Mbps Half Dup.
SR-IOVDisabled{Disabled, Enabled}
TCP Checksum Offload (IPv4)Rx & Tx Enabled{Disabled, Tx Enabled, Rx Enabled..
TCP Checksum Offload (IPv6)Rx & Tx Enabled{Disabled, Tx Enabled, Rx Enabled,
Transmit Buffers2048
UDP Checksum Offload (IPv4)Rx & Tx Enabled{Disabled, Tx Enabled, Rx Enabled,
UDP Checksum Offload (IPv6)Rx & Tx Enabled{Disabled, Tx Enabled, Rx Enabled,
Virtual Machine QueuesDisabled{Disabled, Enabled}
Interrupt Moderation RateAdaptive{Adaptive, Extreme, High, Medium...}
Log Link State EventEnabled{Enabled, Disabled}
Gigabit Master Slave ModeAuto Detect{Auto Detect, Force Master Mode, ..
Locally Administered Address
Wait for LinkAuto Detect{Off, On, Auto Detect}

For example, let’s see what values are possible for Flow Control:
PS> Get-NetAdapterAdvancedProperty P*1 -DisplayName *flow* | fl DisplayName, ValidDisplayValues

DisplayName :Flow Control
ValidDisplayValues :{Disabled, Tx Enabled, Rx Enabled, Rx & Tx Enabled}
'
Here we see the only permissible values for the "Flow Control" parameter are:
{Disabled, Tx Enabled, Rx Enabled, Rx & Tx Enabled}

and we could use those to set the flow control to "Rx & Tx" Enabled as follows:
PS> Set-NetAdapterAdvancedProperty P*1 -DisplayName "Flow Control"-DisplayValue "Rx & Tx Enabled"

Determining Valid Numeric Parameters

Some parameters accept range of numeric values. For these values, you can determine the valid values by examining the NumericaParameterBaseValue, NumericParameterMaxValue, NumericParameterMinValue, and NumericParametersStepValue.
As an example, let's see the permissible settings for Transmit Buffers and Receive Buffers on this particular NIC.
PS> Get-NetAdapterAdvancedProperty P*1 -DisplayName *Buffers | fl DisplayName, NumericP*

DisplayName :Receive Buffers
NumericParameterBaseValue :10
NumericParameterMaxValue :2048
NumericParameterMinValue :80
NumericParameterStepValue :8
DisplayName :Transmit Buffers
NumericParameterBaseValue :10
NumericParameterMaxValue :2048
NumericParameterMinValue :80
NumericParameterStepValue :8

As another example, we can check the Receive Side Scaling (RSS) Maximum RSS Processor Number and
RSS Base Processor Number. (notice that by specifying the first and last letter of these names and an asterisk, (i.e. M*r and R*r) PowerShell will expand the property names automatically)
PS > Get-NetAdapterAdvancedProperty P*1 -DisplayName M*r | fl DisplayName, NumericP*
DisplayName: Maximum RSS Processor Number
NumericParameterBaseValue: 10
NumericParameterMaxValue: 63
NumericParameterMinValue: 0
NumericParameterStepValue: 1

PS > Get-NetAdapterAdvancedProperty P*1 -DisplayName R*r | fl DisplayName, NumericP*
DisplayName: RSS Base Processor Number
NumericParameterBaseValue: 10
NumericParameterMaxValue: 63
NumericParameterMinValue: 0
NumericParameterStepValue: 1




Resetting a Parameter to the Default Value

If you want to reset an advanced parameter back to the factory default value, you can use the Reset-NetAdapterAdvancedProperty CmdLet. In the following example, we set the Interrupt Moderation parameter to the factory default:
PS> Reset-NetAdapterAdvancedProperty P*1 –DisplayName “Interrupt Moderation”

If you want to reset all the advanced parameters back to default value, you can use a wild card
PS> Reset-NetAdapterAdvancedProperty P*1 –DisplayName *

 Batching Commands

PowerShell provides a neat new feature which can batch multiple parameter changes into a single operation. This reduces the number of Network link 'bounces' during configuration and speeds up the configuration dramatically.
When you change a NIC parameter, the NIC driver needs to be restarted for the change to be applied. If you are used to using control panel, you may have noticed that when you make a change the affected network interface goes down briefly while the driver is restarted. This is especially noticeable if you are using a remote terminal session and reset the NIC you are using for the connection. This will temporarily interrupt your remote terminal session. Although the link will be restored, this is annoying, particularly if you need to do this repeatedly when using the network control panel to change NIC setting. But not with PowerShell.
If you are making multiple changes, PowerShell allows you to batch multiple changes and have them all applied with a single restart by using the -NoRestart flag.
For example, suppose I have four parameters I want to set. I append -NoRestart to all the CmdLet invocations except the last.
Set-NetAdapterAdvancedProperty $eth -DisplayName name1 -DisplayValue val1 -NoRestart
Set-NetAdapterAdvancedProperty $eth -DisplayName name2 -DisplayValue val2 -NoRestart
Set-NetAdapterAdvancedProperty $eth -DisplayName name3 -DisplayValue val3 -NoRestart
Set-NetAdapterAdvancedProperty $eth -DisplayName name4 -DisplayValue val4
The NIC will be restarted on when the last CmdLet runs, and will apply all the previous settings at one time. There will be only one link bounce.
Alternatively, you can explicitly restart the NIC by invoking
Restart-NetAdapter (NIC Name)
That's useful if your configuration script is a loop. Each CmdLet in the loop would include -NoRestart. Finally, when the loop completes, issue an explicit restart to apply all the changes. Restarting the NIC disables and re-enables the NIC, applying pending parameter changes in the process.

Determining the NIC Driver VersionA common operations task is checking the version of all the NICs and drivers on a server. This is easy to do with PowerShell by examining the NetAdapter properties. In the following example, we use a wild card to display all the driver related properties in a list format:
PS> Get-NetAdapter P*1 | fl Dri*
DriverVersion: 12.1.77.0
DriverInformation: Driver Date 2012-07-10 Version 12.1.77.0 NDIS 6.30
DriverFileName: e1q63x64.sys
DriverDate: 2012-07-10
DriverDateData: 129863520000000000
DriverDescription: Intel(R) Gigabit ET Dual Port Server Adapter
DriverMajorNdisVersion: 6
DriverMinorNdisVersion: 30
DriverName: \SystemRoot\system32\DRIVERS\e1q63x64.sys
DriverProvider: Intel