Friday, 20 May 2016

Why Class name and file name of java should be same?

For JVM search purpose both names are should be the same. after compilation every java class create .class files with class name not with file name. based on class name we will execute java application.

Thursday, 19 May 2016

Static methods access only static members and methods

check below class1 & class2 as follows.

public class Class1 {

public int myNumber = 799;

private void method(){
System.out.println("Hi i am private method");
}

public void method1(){
System.out.println("Hi i am public method1");
}
}

public class Class2 extends Class1{

public static void main(String args[]) {
Class2 obj = new Class2();
obj.method2();
}


public void method2() {
method1();
System.out.println("my num : "+myNumber);
}

}

Here class1 is super class and class2 is sub class. if you want to call method1 of class1 in main of class2, the method of class1 is must be a static. otherwise it shows the error. without using static, i create object of given class and call method2. in method2 contains methods of class1. in this way we will call methods in static mehods without using static.

Monday, 16 May 2016

What is the default scope of a method in Java?

package com.vamsi.java;

public class Class1 {

int myNumber = 799;

}


package com.vamsi.java;

public class Practice {

public static void main(String args[]) {
Class1 obj = new Class1();
System.out.println("Hai vamsi"+obj.myNumber);
}
}


these two classes are in same package.

package com.vamsi.package2;

import com.vamsi.java.Class1;

public class Class2 {
public static void main(String args[]) {
Class1 obj = new Class1();
System.out.println("Hai vamsi"+obj.myNumber);
}

}

class2 is some other package.

so, the variable scope only with in the package. out of the scope it will not accessible. it is accessible when it is in public.

Tuesday, 10 May 2016

What is the difference between J2SE, J2EE and J2ME

Java SE (formerly J2SE) is the basic Java environment. In Java SE, you make all the "standards" programs with Java. You only need a JVM to use Java SE.

Java EE (formerly J2EE) is the enterprise edition of Java. With it, you make websites, Java Beans, and more powerful server applications. Besides the JVM, you need an application server Java EE-compatible, like GlassfishJBoss, and others.

Java ME stands for Java micro edition for applications which run on resource constrained devices (small scale devices) like cell phones, for example games.

References:

http://www.geeksforgeeks.org/j2se-vs-j2me-vs-j2ee-whats-the-difference/