StackTips
 9 minutes

Basic Java Language Constructs

By Editorial @stacktips, On Sep 17, 2023 Java 2.33K Views

Java keywords

There are over 50 reserved keywords in Java programming language. Keywords are the language construct has predefined meaning in the Java. As they are reserved, we cannot use keywords as names for variables, methods, classes, or as any other identifier.

Following are some of the java keywords are listed below

abstractcontinuefornewswitch
assert***defaultgoto*packagesynchronized
booleandoifprivatethis
breakdoubleimplementsprotectedthrow
byteelseimportpublicthrows
caseenum****instanceofreturntransient
catchextendsintshorttry
charfinalinterfacestaticvoid
classfinallylongstrictfp**volatile
const*floatnativesuperwhile

Java Comments

While writing code, you must write set of comments for your own understanding or for others to understand your code. Such blocks are called comments. Comments can appear anywhere in the source code where whitespaces are allowed. Java Comments are not gets compiled or makes any sense to JVM. Java supports various type of comments such single line or multi line comments.

A singleline comment is represented by slash-shash (//). Example of single line comment

// This is a single line comment

Multiline comments are represented as follows

/**
* This is a multiline comment
**/

Java Data Types

There are eight Java data types – byte, short, int, long, float, double, char and boolean. We will discuss more in details on the upcoming chapters.

Java Development Kit

The Java Developer’s Kit is distributed by Sun Microsystems. The JDK contains documentation, examples, installation instructions, class libraries and packages, and tools.

Java Literals

Literals are any number, text, or other information that represents a value. Literals are the values assigned to variables.

int num = 100;

Here 100 is a integer literal.

Class, Objects and Methods in Java

Java Class is nothing but a template for object you are going to create or it’s a blue print by using this we create an object. Whatever we can see in this world all the things are a object. And all the objects are categorized in a special group. That group is termed as a class. Methods are how we communicate with objects. When we invoke or call a method we are asking the object to carry out a task

Interface in Java

An interface is a collection of methods that have no implementation – they are just created, but have no functionality. An interface is a bit like a class, except you can only declare methods and variables in the interface. You cannot actually implement the methods.

Arrays

An array is a set of variables that are referenced using a single variable name combined with an index number. Each item of an array is called an element. All the elements in an array must be of the same type. Thus the array itself has a type that specifies what kind of elements it can contain.

stacktips avtar

Editorial

StackTips provides programming tutorials, how-to guides and code snippets on different programming languages.