Friday, 28 October 2016

wa.p to print the following pattern

6543210
543210
43210
3210
210
10
0

ans:-


  class abc
{
public static void main(String[] args)
{
int k;

for(int i=1;i<=7;i++)
{
    int m=8-i;
k=m;


for(int j=1;j<=7;j++)
{


if(j<=m)
{
    int  max=(j<=7)?k--:k++;
System.out.print(k);//1
}
else
{

System.out.print(" ");
}
}
System.out.println("\n");

}



}
}

Friday, 2 September 2016

Q-12:-can we develop java application without any taking any userdefined class defination?

ANS-
possible  by taking user defined enum
FOR EX:-
public enum myenum
{
  a;
public static void main(String[] args)
{
   System.out.println("welcome");
}
}

Sunday, 28 August 2016

Q-10 find the output of the following program code.


class demo
{
   public static void main(String[] args)
{
  System.out.println(null);
}
}
1) NULL 2) C.T.E 3) NULL POINTER EXCEPTION 4) RUN TIME ERROR

ANS:-C.T.E 

REASON:-REFERENCED TO println METHOD IS AMBIGUOS BOTH METHOD println (char a[]) in printstream & method println(String) in printstream match.

Thursday, 18 August 2016

q-8:-how to create the jar file in java

ans:
      1) Jar stands for java archive file

      2)Jar file  contains collection of packages.

      3)Packages contains collection of classes. 
      
      4)All  predefined classes .class files are coming in the form of rt.jar file

     5)Location of rt.jar file
       C:\Program Files\Java\jdk1.7.0_79\jre\lib \rt.jar

      The following way to  create the jar file
     
        1)First create the hello.java file in C:\abc folder
      
package com.hellos;
public class hello 
{
public void hellos() 
{
System.out.println("Hello classs");
}
}
                                                  compile the program
2)create the maniss.java file in D:\java
package com.mainss.main;
import com.hellos.hello;
class maniss 
{
public static void main(String[] args) 
{
hello h=new hello();
h.hellos();
}
}


2) Create the jar file using jar command in C:\abc \myfile.jar
   


3)to compile and execute  mainss class first we can set the class path enviornment variable to myfile.jar


compile the mainss.java file

run the mainss.java file:-

    


Friday, 12 August 2016

q-7 )is it possible to maintain local variable and static variable with same name?

ans:yes it is possible to maintain local and static variable with same name.
to access static variable we can use class name.


q-8)is it possible to maintain local variable and non static variable with same name?

yes,it is possible to maintain local variable and non static variable with same name.
to access the non static variable we cvan use object references.


for ex:-

class test
{
   static int a=10;
public static void main(String[] args)
{
     System.out.println(a);//10
    int a=50;
   System.out.println(a);//50
   System.out.println(test.a);//10
 }
}

output:-

   







Tuesday, 9 August 2016

Q-6:-is it possible to create the java file without name?

ans:yes,it is possible to create the .java file
for ex;-
.java
class Test
{
    public static void main(String args[])
   {
                System.out.println("test classs");
    }
}
compile and run program:-

Q-5 is it possible to call the main method explicitly just like a normal java method?

ans : yes,it is possible to call main method explicitly just like normal java method but to call the main() we can use some other class method;

for ex:test.java
class test
{
public  static void main(String[] args)
{
  
  System.out.println("main method test clsss");
     }
}
class demo
{
public static void main(String[] args)
{
           String[] s={"c","java","c++","linux"};
  test.main(s);
  System.out.println("demo  class main methid");
}
}

compile and run test.java file:





run demo class:





Monday, 8 August 2016

Q-3:-is it possible to write main() in multiple class of  .java file?

Ans:yes,it is possible to write the main() in multiple class.

FOR EX:-

                                                          demo.java

class hello

{

      public static void main(String[]args)

{
      System.out.println("hii hello");
}
}
class test
{

   public static void main(String[]args)

{
      System.out.println("hii test");
}
}
output:
1)compile the program
javac demo.java
2)To run the program
java hello
hii hello
2)to run the program using test class
java test
hiii test

  

Sunday, 7 August 2016

Q-2:is it possible to run program without main method?


Ans:

class abc
{
 static
{
System.out.println("HelloWorld");
}
}

Note: this code working upto jV 6 version below this version display the error 

please define the main method public static void main(String [] args).

Q-2:is it possible to run program without main method?


Ans:

class abc
{
 static
{
System.out.println("HelloWorld");
}
}

Note: this code working upto jV 6 version below this version display the error 

please define the main method public static void main(String [] args).

Saturday, 6 August 2016

HOW TO CREATE THE PATTERN IN JAVA 

Q-1:Write a java program to create the star tringle.
class Triangle
{
public static void main(String[] args) 
{
int i,j,k;
for(i=1; i<=5; i++)
{
for(j=4; j>=i; j--)
{
System.out.print(" ");
}
for(k=1; k<=(2*i-1); k++)
{
System.out.print("*");
}
System.out.println("");
}
}
}