Friday, March 20, 2009

New Line Character in Java for Windows and Linux.

As we all know, Java is a platform independent. But there may be some cases, when we will have to consider the platform. The new line character for Windows is CR + LF that mean Carriage Return and Line Feed. Its ASCII value is 13. But for Linux, it is '\n' and its ASCII value is 10. It might be different for MAC. So, we cannot be sure what to use for New Line in Java.

One alternative might be use System.out.println(""). But it increases code.

Another alternative might be defining a static variable as shown below.

private static final String NEWLINE = System.getProperty("line.separator");

Here, NEWLINE stores the actual String value of line separator character of the system. So, use of NEWLINE removes the platform dependency in this case. It can be used like this.

System.out.printf(NEWLINE + "  Total Department Salary: %.2f" + NEWLINE, salary);


Tuesday, January 27, 2009

DLL Memory Management

I have been a good Visual Basic Programmer during my early days in undergraduate course. VB6 is used extensively to develop desktop (windows) based applications. DLLs here mean Dynamic Link Libraries. DLLs generally store function definitions. So, when called by an application by passing input parameters, it executes function stored in.


So, what is the benefit of DLLS? A normal programmer would say that it helps in modularization (i.e. it helps to separate business logics). Yes, that is absolutely true. I also remember developing DLLs for printing, reporting and handling common functions. That is not enough. I have noticed that applications using DLLs are more efficient that those not using it. They consume less time and memory. May be windows itself helps in memory management of applications using DLLs.


One major benefit of DLL becomes that the running application (EXE) can be less in size. It is because most of its functionalities are stored in DLLs. And DLLs can be called upon requirement basis and similarly freed after use. Thus, it helps to reduce memory consumption by the Application EXE.


Wednesday, January 7, 2009

How to block built in windows administrators from using your SQL database?

The problem is terrible. You are not the windows administrator. But you have to create a database in the machine without allowing built in administrator of windows to access. Either you install the SQL Server in Mixed Mode or Windows Authentication mode, by default, built-in administrators becomes SQL Server Administrator. So, they will have access to each and every SQL database in that machine.

If you really want to block, then in my opinion, only two options are remained.

  1. To remove, built-in administrator login from SQL Server Administrator role. Yes, it woks fine. But, it will block the administrator from creating new databases as well and also from other rights. That may be problematic.
  2. By completing denying access to built-in administrator to SQL Server. This may also be problematic as the administrator will not even able to login to SQL.

 Both the things can be done from SQL Server Login Properties of SQL Server Enterprise Manager.


Wednesday, December 31, 2008

Default user of login mapped to role SQL Server Administrator

The post I m writing is slightly confusing. If a SQL server login is assigned to System Administrator Server role of SQL Server 2000, then it will have rights to perform any activity in SQL Server Installation. That is what, SQL Server says. This may be problematic some times.


Now, Lets say there is a login stcsa with mapped to role System Administrator. First, you login to ISQLW with login stcsa and create a table with name tbl_test as below.


create table tbl_test (t varchar(10))


Now, check the owner of tbl_test, it will be dbo not stcsa. Suprising Not? This is because stcsa is System Adminitrator. But, you can call the table as simply tbl_test without "dbo." in front of the object name. The following select query works.


select    * from            tbl_test


Now, lets say, you again created a table with same name but like below.


create table stcsa.tbl_test ( t varchar(200))


Then, there will be two tables with name tbl_test and owners as dbo and stcsa. Now, if you use simply tbl_test, which one object do you think will it call? No not, it will call dbo.tbl_test not stcsa.tbl_test despite you are logged in as stcsa. This is where problem comes. In normal case, if you are logged in with a sql login and that login is mapped with user of same name, then if you call sql objects without prefix username, then it will search for username.objectname.


I am not sure that whether this can be called a bug in SQL Server or not. I just want to specify that, it's always useful to call sql objects by using username.objectname. It becomes more useful, when the login used is mapped to the role like SQL Server Administrator.