3 ways to fix "illegal start of expression" error in java

"illegal start of expression" error is one of the most common errors, java beginners face. This error arises during compile time i.e running javac command. Usually , java compiler compiles from top to bottom and left to right in a source code file. There are 3 ways in which we can get "illegal start of expression" error.

1. Missing curly braces
2. Method inside method
3. public, protected or private access modifier inside method

Read Also :  Guide to the Java Constructor


Let's check them out one by one.

1. Missing curly braces

"illegal start of expression" arises if you forgot to add curly braces. In the below example, I do not add the closing curly  brace }  of the main method.


public class JavaHungry {
    public static void main(String args[])
    {
        int x=10;
        int y=25;
        int z=x+y;

        System.out.println("Sum of x+y = " + z);
        
    public void anotherMethod()
    {
        System.out.println("another Method");
    }
}
 

What is serialVersionUID and Why do we need it

If you have done coding in tech industry then you may have gone through the serialVersionUID listed in the java class. Today, I will uncover what is serialVersionUID and why do we need it?

Read Also :   Java Collections Interview Questions 
 
But first we need to understand

What is Serialization?


Serialization is used to save the state of an object. Real world example is video-game. While playing video-games, if you press the pause button and again click on the play button , the game continue from the paused state. So pausing the game is serialization as we are saving the state of the game. Continue playing from the paused state is deserialization.

What is Serializable class



Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Serializable interface has no fields and methods.It is a marker interface.
Classes that do not implement this interface will not have any of their state serialized or deserialized.

Now, back to our main question 

What is serialVersionUID?


Java 8 Most Frequently Asked Interview Questions and Answers

I have already shared core java interview questions and answers. Java 8 was released in 2014. Now it  has been 4 years since the release of java8. Job market is filled with java8 interview questions.  Today I will be sharing 15 most frequently asked  java8 interview questions and answers. I have already share the java 8 features. Please bookmark this page as I keep adding more question to this post.

Java 8 Interview Questions and Answers


Q1. What are java 8 new features ?

This is the most asked interview question on Java 8. Many of the java developers do not work on java 8. Below are the java 8 features:

1. Functional Interface : Each functional interface has a single abstract method, called the functional method, implementation can be provided using the lambda expressions.
2. Lambda Expressions : It is a feature derived from the functional programming. It is a function that does not belong to any class.
3. Optional : Instead of using null values Optional class is used for representing Optional values.
4. Stream api
5. Spliterator 
6. Method References
7. New Date and Time API.

You can find the important java 8 features here.

Q2 What is the difference between Collection API and Stream API?

Top 50 Java String Interview Questions and Answers

String class needs no introduction. String class is one of the most used and very important class in java. Every java application is using String class. In this article I will be sharing 50 most frequently asked java string interview questions and answers. We will divide this post into three categories:

Beginner level (0-1 year experience) Freshers

Intermediate level(1-7 years experienced)

Advanced level (7+ years experienced) java string interview questions and answers.

Note : Please go through all the questions. Interviewer may choose to ask any question.


Beginner Level (0-1 yr): Java String Interview Questions and Answers

Q1.  What is String?

String is a class in java which is present in java.lang package. According to Oracle docs,
The String class represents character strings. Strings are constant, their values can not be changed after they are created.

Q2  Is String immutable in java?

Top 65 Java Programming Interview Questions and Answers

This post is dedicated to all the java programming interview questions and answers that are getting asked in the internship interview or full time entry level graduate interview (freshers). 

Q1. How to reverse a String in java? [Solution]

Write a java program to reverse the String. There are 6 ways to reverse a String in java. You should know at least how to reverse a String without using reverse() method in java.

Q2. How to find the first non repeated character in the String? [Solution]

This is the starting question for the product companies, so make sure you go through it. Write a java program to find the first non repeated character in the String.

Q3. How to find intersection of two arrays in java? [Solution]

Write a java program to find common elements between the two given arrays.
 Suppose given two arrays array1= {1,4,7, 9, 2} arrray2 = {1,7,3,4,5} the answer should be {1,4}
[Solution]

Q4 Find out if String has all Unique Characters? [Solution]

Write a java program to find out if the given String has all Unique Characters. There are 5 ways to determine String has all Unique Characters.

Q5 How to Count number of words in the String? [Solution]

This is an important phone interview coding question. Write a java program to count number of words in the String.