static final int[] a = { 100,200 }; static final int[] a; static { a=new int[2]; a[0]=100; a[1]=200; }
Author Archives: admin
Looping through Arguments in Function
How to Loop Through Arguments Passed to function
package com.apryll.package2; public class sample2 { public static void main(String args[]) { sample2 objsample2 = new sample2(); objsample2.argCount(1, 2, 3, 4); } public void argCount(int... args) { System.out.println(args.length); } }
Importing Classes and Methods
Sample1.java
package com.apryll.package1; //import static com.apryll.package2.sample2.Funct3; public class Sample1 { public static void main(String[] args) { Sample1 objSample1 = new Sample1(); //sample2 objSample2 = new sample2(); System.out.println(com.apryll.package2.sample2.City); objSample1.Funct2(); //objSample2.Funct4(); //Sample1.Funct1(); } static void Funct1() { System.out.println("I am Static Function 1"); } void Funct2() { System.out.println(Funct3()); System.out.println(City); } }
Sample2.java
package com.apryll.package2; public class sample2 { public static int City = 555; public static String Funct3() { return "Hi there"; } public void Funct4() { System.out.println("Hello There"); } }
1
package com.apryll.package1; import com.apryll.package2.sample2.*; public class Sample1 { public static void main(String[] args) { sample2 objSample2 = new sample2(); } }
The Above Code Does not Work when creating a object for sample2 since in the import statements is sample2.* is given.It should be
import com.apryll.package2.sample2; . . . .
2
While Importing class methods and variables the static will not get imported unless you specify static
import in the import statement
You can Import the Static Methods and Variables in class as below
To Import static methods and Variables
import static com.apryll.package2.sample2.*;
To Import static methods and Variables
import static com.apryll.package2.sample2.*;
To Import static Variable City
import static com.apryll.package2.sample2.City;
To Import static Function getCityName
import static com.apryll.package2.sample2.getCityName;
3
You can directly access static method and Variable declared in some other package in static void main() method as follows
System.out.println(com.apryll.package2.sample2.City); System.out.println(com.apryll.package2.sample2.Funct3());
Retreive records from Procedure which returns different Resultsets
$objConn = setDbConn(); $strSQL = "CALL mp_proc_getHomePageProjNews('Chennai')"; if($objConn->multi_query($strSQL)) { do { $l = 0; /* store first result set */ if ($result = $objConn->use_result()) { while($row = $result->fetch_row()) { $arrTempResult[] = $row; } $arrResult[] = $arrTempResult; unset($arrTempResult); $result->close(); } if($objConn->more_results()) { } } while ($objConn->next_result()); }
Mysql Procedure Taking parameter
DROP PROCEDURE IF EXISTS proc_sample1; CREATE PROCEDURE proc_sample1(IN pFruitId VARCHAR(255)) BEGIN SET @strSQL = 'SELECT fruit_name FROM fruits WHERE fruit_id = ?'; SET @pFruitId = pFruitId; PREPARE stmt FROM @strSQL; EXECUTE stmt USING @pFruitId; DEALLOCATE PREPARE stmt; END
Alternate to Inner Join which prevents repetation of Records
create table fruits(fruit_id int, fruit_name VARCHAR(255)); create table type(fruit_id int, status VARCHAR(255)); INSERT INTO fruits(fruit_id, fruit_name) values(101, 'Apple'), (102, 'Mango'), (103, 'Lemon'), (104, 'Grape'), (105, 'Orange'); INSERT INTO type(fruit_id, status) values(101, 'Edible'), (101, 'Sweet'), (102, 'Edible'), (103, 'Edible'), (103, 'Salty'), (103, 'Sour'), (104, 'Sour');
When i Use Inner Join as Below the Output would be
To prevent the repetition of fruit name the queries are as follows
SELECT f.fruit_id, f.fruit_name FROM fruits f WHERE f.fruit_id in(SELECT DISTINCT fruit_id FROM type); SELECT DISTINCT t.Fruit_id, fruit_name FROM fruits f RIGHT OUTER JOIN type t ON F.Fruit_id = t.Fruit_id; SELECT fruits.* FROM fruits inner join type on type.fruit_id = fruits.fruit_id GROUP BY type.fruit_id;
How to add Compression to php file using Gzip
There are two ways of adding compression to php file
Method 1
Simple add the below line in the php file at the beginning
ob_start( 'ob_gzhandler' );
CentOS Misc Terminal Commands
How to Find Host and Domain Name
Terminal Command
hostname
How to create a Virtual Host in CentOS 6.3
After installing apache in CentOS it would go to Apache 2 Test Page.
To locate this directory you need to go to /var/www/
In this directory you can create your file which you needs to run.
To set up Virtual Host navigate to /etc/httpd/conf/httpd.conf file
Open the file in gedit or editor of your preference.
Add the lines below
<VirtualHost *:80> DocumentRoot /var/www/sample/ ServerName virtualhost1 </VirtualHost>
The document root points out to sample older in www directory
The server name is virtual host name you type in URL
You should also add the code in /etc/hosts file
127.0.0.1 virtualhost1
Once this is done dont forget to restart apache server in terminal by typing service httpd.restart
Now you are ready to go now.Open the browser and type http://virtualhost1/
Cheers!!!