Search

Showing posts with label CORE JAVA. Show all posts
Showing posts with label CORE JAVA. Show all posts

What is the % operator?



It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.

Can a Byte object be cast to a double value?



No, an object cannot be cast to a primitive value.

How to convert an object into string ?



We can use “toString” method to convert an object to string. For example
Java
Object O = new Object();
System.out.println(O.toString());

How to create Executable Jar Archive (JAR) File ?

Let us say, we have 2 compiled classes Employee and Person inside the folder “SRC” which resides inside the folder “WORK”. Employee class contains static void main method.
Before creating a Jar file, first create a mainclass file in the WORK folder. Specify the name of the class in which main methods resides. Here (“Main-Class: SRC.Employee”) and press enter.
From terminal change directory to WORK Folder. Enter the following command in the command prompt “jar -cmf mainclass jarfilename.jar SRC/*.class” and press enter. Executable jar will created. To test the newly created jar, use following command “java -jar jarfilename.jar”

How to create a simple Jar File from the list of class files in a directory?



We can use below command. Don’t miss the space between / and . at the end

$ jar -cvf jarfilename.jar -C <classfiles folder>/ .

What is a local, member and a class variable?



Variables declared within a method are “local” variables.
Variables declared within the class i.e not within any methods are “member” variables (global variables).
Variables declared within the class i.e not within any methods and are defined as “static” are class variables.