Found 4348 Articles for Java 8

How do I write method names in Java?

varma
Updated on 30-Jul-2019 22:30:20

3K+ Views

While writing a method name we should follow the camel case i.e. first letter of the first word should be small and the first letters of the remaining (later) words should be capital. Example public class Test { public void sampleMethod() { System.out.println("This is sample method"); } public void demoMethod() { System.out.println("This is demo method"); } public static void main(String args[]) { Test obj = new Test(); obj.sample(); obj.demo(); } } Output This is sample method This is demo method

How do I write class names in Java?

usharani
Updated on 30-Jul-2019 22:30:20

4K+ Views

While writing class names you need to keep the following points in mind. You shouldn’t use predefined or existing class names as the name of the current class. You shouldn’t use any Java keywords as class name (with the same case). The First letter of the class name should be capital and remaining letters should be small (mixed case). class Sample Likewise, first letter of each word in the name should be capital an remaining letters should be small. class Test Keeping interface names simple and descriptive is suggestable. Better not ... Read More

Are identifiers hello and Hello same in Java?

varun
Updated on 30-Jul-2019 22:30:20

172 Views

Identifiers in Java are case-sensitive, therefore, hello and Hello are considered as two different identifiers.

What is the difference between keywords and reserved words in Java?

Prabhas
Updated on 18-Feb-2020 11:11:37

515 Views

KeywordsKeywords in Java convey a special meaning to the compiler therefore, these cannot be used as identifiers. Java provides a set of 50 keywords.abstractcontinuefornewswitchassertdefaultgotopackagesynchronizedbooleandoifprivatethisbreakdoubleimplementsprotectedthrowbyteelseimportpublicthrowscaseenuminstanceofreturntransientcatchextendsintshorttrycharfinallongstrictfpvolatileconstfloatnativesuperwhileReserved wordsAmong the list of key words list mentioned above the key words goto and const are currently not in use. They are reserved words (for the future use).

What are valid identifiers in Java?

seetha
Updated on 30-Jul-2019 22:30:20

636 Views

A valid identifier in java – Must begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). Can have any combination of characters after the first character. Cannot be a keyword. Example Following example shows various possible identifiers used to declare a variable in Java. Live Demo public class VariableTest { public static void main(String args[]) { // Declaring a variable named num int num = 1; ... Read More

What is the difference between /* */ and /** */ comments in Java?

vanithasree
Updated on 30-Jul-2019 22:30:20

512 Views

Multiline comments (/* */) are used to comment multiple lines in the source code. Example Live Demo public class CommentsExample { /* Following is the main method here, We create a variable named num. And, print its value * */ public static void main(String args[]) { //Declaring a variable named num int num = 1; ... Read More

How to write single line comment in Java?

mkotla
Updated on 30-Jul-2019 22:30:20

424 Views

To comment a particular line just place ‘double back slash (//)’ before the line as shown below. // Hello this line is commented Example Following example demonstrates the usage of single line comments in Java. Live Demo public class CommentsExample { public static void main(String args[]) { //Declaring a variable named num int num = 1; //Printing the value of the variable num System.out.println("value if the variable num: "+num); } } Output value if the variable num: 1

Is there a need to import Java.lang package while running Java programs?

Sreemaha
Updated on 30-Jul-2019 22:30:20

484 Views

The java.lang package is the default package in Java, by default, it will be imported. Therefore, there is no need to import this package explicitly. i.e. without importing you can access the classes of this package. Example If you observe the following example here we haven’t imported the lang package explicitly but, still, we are able to calculate the square root of a number using the sqrt() method of the java.lang.Math class. Live Demo public class LangTest { public static void main(String args[]) { int num = 100; ... Read More

What environment variables do I need to set up before I start running Java programs on my machine?

varma
Updated on 18-Feb-2020 11:03:23

649 Views

Before running Java programs on your machine you need to set two environment variables namely, PATH − The path environment variable is used to specify the set of directories which contains execution programs.When you try to execute a program from command line, the operating system searches for the specified program in the current directly, if available, executes it.In case the programs are not available in the current directory, operating system verifies in the set of directories specified in the ‘PATH’ environment variable.CLASSPATH − The classpath environment variable is used to specify the location of the classes and packages.When we try ... Read More

How to use labels in Java code?

usharani
Updated on 16-Jun-2020 06:29:04

9K+ Views

Java provides two types of branching/control statements namely, break and continue.The break statementThis statement terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.ExampleFollowing is the example of the break statement. Here we are trying to print elements up to 10 and, using break statement we are terminating the loop when the value in the loop reaches 8.Live Demopublic class BreakExample {    public static void main(String args[]){       for(int i=0; i

Advertisements