Keywords in Java

Samual Sam
Updated on 26-Jun-2020 07:04:17

1K+ Views

Keywords in Java are reserved words that represent predefined actions, internal processes etc. Because of this, keywords cannot be used as names of variables, functions, objects etc.The main difference between keywords and identifiers is that keywords are reserved words that represent predefined actions while identifiers are the names of variables, functions, objects etc.Some of the keywords in the Java are given as follows −abstractassertbooleanbreakbytecasecatchcharclassconstcontinuedefaultdodoubleelseenumextendsfinalfinallyfloatforgotoifimplementsimportinstanceofintinterfacelongnativenewpackageprivateprotectedpublicreturnshortstaticstrictfpsuperswitchsynchronizedthisthrowthrowstransienttryvoidvolatilewhileA program that demonstrates keywords is given as follows −Example Live Demopublic class Example { public static void main(String[] args) { int i = 5; char c = 'A'; System.out.println("i = " + i); System.out.println("c = " + ... Read More

Different Methods to Find Prime Number in Java

Samual Sam
Updated on 26-Jun-2020 07:03:02

2K+ Views

A prime number is a number that is only divisible by one or itself. Some of the prime numbers are 2, 3, 5, 7, 11, 13 etc.Some of the different methods to find a prime number in Java are given as follows −Method 1 - Find if a number is prime without using a functionA program that finds if the given number is prime without using a function is given as follow −Example Live Demopublic class Example {    public static void main(String args[]) {       int num = 11, flag=0;       if(num == 0||num == 1) {          System.out.println( num + " is not a prime number");       } else {          for(int i = 2; i

Read and Write TAR Archive Files Using Python tarfile

George John
Updated on 26-Jun-2020 07:01:45

3K+ Views

The ‘tar’ utility was originally introduced for UNIX operating system. Its purpose is to collect multiple files in a single archive file often called tarball which makes it easy to distribute the files. Functions in tarfile module of Python’s standard library help in creating tar archives and extracting from the tarball as required. The archives can be constructed with gzip, bz2 and lzma compressions or without any compression at all.Main function defined in this module is main() using which writing to tar file or reading from it is accomplished.Open()This function returns a TarFile object corresponding to file name which is ... Read More

Compare Two Objects of Character Type in Java

karthikeya Boyini
Updated on 26-Jun-2020 06:59:37

775 Views

To compare two objects of Character type in Java, use the compareTo() method.Firstly, we have created two Character type.Character one = new Character('m'); Character two = new Character('k');Now, to compare them, we have used the compareTo() method.int res = one.compareTo(two);The following is the example that compares character objects.Example Live Demopublic class Demo {    public static void main(String []args) {       Character one = new Character('m');       Character two = new Character('k');       System.out.println("Character object 1: "+one);       System.out.println("Character object 2: "+two);       int res = one.compareTo(two);       if ... Read More

Display Thread's Information in Java

Krantik Chavan
Updated on 26-Jun-2020 06:55:04

4K+ Views

In order to get the name of the Thread, we use the getName() method in Java. This method returns the name of the thread.Declaration − The java.lang.Thread.getName() method is declared as follows −public String getName()In order to get the identity of the Thread, we use the getId() method in Java. This method returns the identifier of the thread. The thread ID is a positive long number produced during the creation of the thread.Declaration − The java.lang.Thread.getId() method is declared as follows −public long getId()In order to get the state of the Thread, we use the getState() method in Java. This ... Read More

Assertions in Java

Nancy Den
Updated on 26-Jun-2020 06:51:31

6K+ Views

An assertion is a statement in Java which ensures the correctness of any assumptions which have been done in the program. When an assertion is executed, it is assumed to be true. If the assertion is false, the JVM will throw an Assertion error. It finds it application primarily in the testing purposes. Assertion statements are used along with boolean expressions.Assertions in Java can be done with the help of the assert keyword. There are two ways in which an assert statement can be used.First Way −assert expression;Second Way −assert expression1 : expression2By default, assertions are disabled in Java. In ... Read More

Consumer Rights and Responsibilities

Shanmukh Pasumarthy
Updated on 26-Jun-2020 06:51:01

257 Views

Shopper rights are presently a vital part of our lives. They have been well framed and tremendously discussed. We have all made utilization of them eventually in our day to day activities. Market assets and impacts are developing every day and so is the familiarity with consumer rights. These rights are well characterized and there are agencies like the consumer courts and government offices that work towards shielding them.Keeping in mind the goal to protect consumer interest, six rights were put forth by consumer rights activists of the West, which are:Right to InformationRight to SafetyRight to ChoiceRight to be HeardThe ... Read More

Compile Assert in Java

Smita Kapse
Updated on 26-Jun-2020 06:50:33

676 Views

In order to compile assert in Java, we simply set the boolean expression as false.Let us see an example program −Example Live Demopublic class Example {    public static void main(String[] args) {       assert false;       System.out.println("Compiled and executed successfully!!!");    } }OutputCompiled and executed successfully!!!

Enable Assertions from the Command Line in Java

Anvi Jain
Updated on 26-Jun-2020 06:46:07

502 Views

By default, assertions are disabled in Java. In order to enable them we use the following command −java -ea Example (or) java -enableassertions ExampleHere, Example is the name of the Java file.Let us see an example for generation of an assertion error by the JVM −Example Live Demopublic class Example {    public static void main(String[] args) {       int age = 14;       assert age >= 18 : "Cannot Vote";       System.out.println("The voter's age is " + age);    } }OutputThe voter's age is 14

JSON Encoder and Decoder Package in Python

Chandu yadav
Updated on 26-Jun-2020 06:42:28

3K+ Views

JSON stands for JavaScript Object Notation. It is a lightweight data interchange format. It is similar to pickle. However, pickle serialization is Python specific whereas JSON format is implemented by many languages. The json module in Python’s standard library implements object serialization functionality that is similar to pickle and marshal modules.Just as in pickle module, the json module also provides dumps() and loads() function for serialization of Python object into JSON encoded string, and dump() and load() functions write and read serialized Python objects to/from file.dumps()This function converts the object into JSON format.loads()This function converts a JSON string back to ... Read More

Advertisements