You are on page 1of 2

Can we create empty java file, can we compile and execute it?

Yes, but after compilation we do not have .class. so we cannot execute. Can we create empty class; can we compile and execute it? Yes we can create and compile empty class. Compiler generates .class file with that class name. we cannot execute this class because this class does not have main method. It leads to exception. When should be the java file name and class name be the same? If class is declared as public, file name should be the same as the public class name, else its name can be user defined. If a java file has multiple classes what is the java file name? Public class name. If there no public class than java file name can be user defined. In java file we can define only one public class and multiple non- public class names. If we compile multiple classes java file, how many .class files are generated by compiler? Compiler generates .class files as many class definitions as we have in that java file. Compiler generates .class file separately for every class with that class name. User Defined method and Predefined method: Developer defined method is called user defined or custom method. Java software developers given method is called predefined method. It means already implemented methods are called predefined methods. Ex: println () method. User Defined and Predefined classes: Developer defined class is called user defined or custom class. Java Software developers given class is called predefined class. It means already implemented classes are called predefined classes. Ex: System, String If a class does not have main method, how can we execute that class user defined methods? We should use another class main method. We should call this method with its class name. In projects, we do not write main method in every class. Instead we write main method in one class, and we will call all other classes methods from this classs main method for testing. Basically main method is given to start class logic execution but not for developing logic directly. We can define user defined methods with same name in multiple classes. While calling those methods we must use that methods class name. We can call main method explicitly with this syntax: main(new String [0]);

Println () method places the cursor in the next line after printing current output. So that the next coming output will be printed in next line. But whereas print () method places the cursor in the same line after printing current output. So that next coming output will be printed in same line. Naming Conventions: Naming a class: class name should be Noun, and should be in title case every word first letter should be capital Naming a Variable: Variable name should be Noun, and should be in case every word first letter should be small after that every word first letter should be capital In final variables all its letters should be capital and words must be connected with _. MIN_BALANCE Naming a Method: Method name should be Verb, because it represents action, and should be in case every word first letter should be small after that every word first letter should be capital and should follow () Ex: getUserName() Naming Package: all letters are small, and its length should be a short as possible. Why pointers are eliminated from Java? Pointers lead to confusion for a programmer. Pointers may crash a program easily, for example, when we add two pointers, the program crashes immediately. The same thing could also happen when we forgot to free the memory allotted to a variable and reallot it to some other variable. Pointers break security. Using pointers, harmful programs like virus and other hacking programs can be developed. Because of the above reasons, pointers have been eliminated from java.

You might also like