Java Technologies Articles

Page 2 of 4

Different Ways to Print First K Characters of the String in Java

Shriansh Kumar
Shriansh Kumar
Updated on 20-Jul-2023 301 Views

A string is a class in Java that stores a series of characters enclosed within double quotes.Those characters are actually String-type objects. The string class is available in the‘java.lang’ package. Suppose we have given a string and a positive integer ‘k’. Now, thejob is to print that string's first 'k' characters in Java. Also, check whether the length ofgiven string is less than or not, if so print the original string. Java Program to Print First K Characters of the String Let’s understand the given problem with a few examples − Instance String st1 = “TutorialsPoint”; String st2 = “Tutorial”; ...

Read More

What are the key features of Java?

Debarpito Sarkar
Debarpito Sarkar
Updated on 05-Sep-2022 5K+ Views

This article will help you understand what the key features of Java Programming language are. The Key features of Java Programming Language are − Java is Easy to Understand Java’s base is similar to that of C and C++ languages and it includes many important features of these languages. It removes many drawbacks and complexities of C or C++. So if one has good understanding of either C or C++, then Java language will be very familiar and easily understandable. Java is an object oriented programming language Object Oriented Programming (OOP) is an approach to standardize the programs by creating ...

Read More

Match all occurrences of a regex in Java

Arnab Chakraborty
Arnab Chakraborty
Updated on 23-Jun-2020 314 Views

public class RegexOccur {    public static void main(String args[]) {       String str = "java is fun so learn java";       String findStr = "java";       int lastIndex = 0;       int count = 0;       while(lastIndex != -1) {          lastIndex = str.indexOf(findStr,lastIndex);          if(lastIndex != -1) {             count ++;             lastIndex += findStr.length();          }       }       System.out.println(count);    } }Output2

Read More

Java labelled for loop

Vikyath Ram
Vikyath Ram
Updated on 15-Jun-2020 2K+ Views

Following program is using labeled for loops. Example public class Tester {     public static void main(String args[]) {                first:            for (int i = 0; i 

Read More

Java labelled statement

Kumar Varma
Kumar Varma
Updated on 15-Jun-2020 4K+ Views

Yes. Java supports labeled statements. You can put a label before a for statement and use the break/continue controls to jump to that label. Example See the example below. public class Tester {    public static void main(String args[]) {      first:          for (int i = 0; i 

Read More

Java Conversions and Promotions

Paul Richard
Paul Richard
Updated on 15-Jun-2020 210 Views

We can convert one data types into another data type using casting. Narrowing ConversionNarrowing refers to passing a higher size data type like int to a lower size data type like short. It may lead to data loss. Following program output will be 44.public class MyFirstJavaProgram {    public static void main(String []args) {       int a = 300;       byte b = (byte)a; // narrowing       System.out.println(b);    } }Widening/Promotion ConversionWidening refers to passing a lower size data type like int to a higher size data type like long. public class MyFirstJavaProgram {    public ...

Read More

Java overflow and underflow

Arjun Thakur
Arjun Thakur
Updated on 15-Jun-2020 4K+ Views

OverflowOverflow occurs when we assign such a value to a variable which is more than the maximum permissible value.UnderflowUnderflow occurs when we assign such a value to a variable which is less than the minimum permissible value.JVM does not throw any exception in case Overflow or underflow occurs, it simply changes the value. Its programmer responsibility to check the possibility of an overflow/underflow condition and act accordingly. Example (Overflow)Consider the case of int variable, it is of 32 bit and any value which is more than Integer.MAX_VALUE (2147483647) is rolled over. For example, Integer.MAX_VALUE + 1 returns -2147483648 (Integer.MIN_VALUE).As int data ...

Read More

Java variable declaration best practices

Fendadis John
Fendadis John
Updated on 15-Jun-2020 2K+ Views

Following are the best practices while declaring a variable.Variables names should be short or long enough as per the scope. For example, loop counter variable, i is fine whereas employee as a loop variable.Specific words should not be used as equals, compare, data.Use meaningful names which can explain the purpose of the variable. For example cnt Vs counter.Don't use _ to declare a variable name, Use camel casing. For example, employeeName is better than employee_name.Each organization has its own syntax specific standards. Follow those rules to maintain consistency and readability.

Read More

Why is Java slower than C++ programs?

Akshaya Akki
Akshaya Akki
Updated on 13-Jun-2020 1K+ Views

Modern Java is quite fast and is comparable to C++ code base but it still takes lot of memory. Slowness of Java programs is primarily because of bad programming practices. But following areas are where Java can be improved.Java libraries are written keeping readability and correctness in mind, not performance.Slow String based operations as Strings are UTF-16 encoded objects and are immutable. So more String are used, more memory is required.Boundary checks on arrays also make its operations bit slow.I/O Stream operations are slow considering synchronization checks on each access.Lacking low level functionality like C also attributes to slowness in ...

Read More

Troubleshooting tips

Rishi Raj
Rishi Raj
Updated on 13-Jun-2020 973 Views

Following steps are mostly required to Troubleshoot any problem that occurred in production.As the first step, get the time frame from the user when a particular issue occurred. Get the logs for that particular time period.If logs are very large in size, use grep command to filter out errors.$ grep -o "\w*Exception" error.log | sort -r | uniq -cIt will help to get all the exceptions in error.log sorted in reversed order and give the unique result and with counts.

Read More
Showing 11–20 of 40 articles
Advertisements