Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
J

java-basics

> 设计协作
Open source

Java Basics ( Java-25 )

1.9K stars0 likes0 views
WebsiteGitHub

About

Java Basics ( Java-25 )

Java Basics

Click ★ if you like the project. Your contributions are heartily ♡ welcome.


Related Topics

  • Multithreading
  • Collections
  • Java Database Connectivity (JDBC)
  • Java Programs
  • Java String Methods
  • Jakarta Server Pages (JSP)
  • Servlets
  • Java Multiple Choice Questions
  • Java Design Pattern
  • Hibernate
  • Spring Framework Basics

Table of Contents

  • Introduction
  • Java Architecture
  • Java Data Types
  • Java Methods
  • Java Functional programming
  • Java Lambda expressions
  • Java Classes
  • Java Constructors
  • Java Array
  • Java Strings
  • Java Reflection
  • Java Streams
  • Java Regular Expressions
  • Java File Handling
  • Java Exceptions
  • Java Inheritance
  • Java Method Overriding
  • Java Polymorphism
  • Java Abstraction
  • Java Interfaces
  • Java Encapsulation
  • Java Generics
  • Miscellaneous

# 1. INTRODUCTION


Q. What are the important features of Java 8 release?

  • Interface methods by default;
  • Lambda expressions;
  • Functional interfaces;
  • References to methods and constructors;
  • Repeatable annotations
  • Annotations on data types;
  • Reflection for method parameters;
  • Stream API for working with collections;
  • Parallel sorting of arrays;
  • New API for working with dates and times;
  • New JavaScript Nashorn Engine ;
  • Added several new classes for thread safe operation;
  • Added a new API for Calendarand Locale;
  • Added support for Unicode 6.2.0 ;
  • Added a standard class for working with Base64 ;
  • Added support for unsigned arithmetic;
  • Improved constructor java.lang.String(byte[], *) and method performance java.lang.String.getBytes();
  • A new implementation AccessController.doPrivileged that allows you to set a subset of privileges without having to check all * other access levels;
  • Password-based algorithms have become more robust;
  • Added support for SSL / TLS Server Name Indication (NSI) in JSSE Server ;
  • Improved keystore (KeyStore);
  • Added SHA-224 algorithm;
  • Removed JDBC Bridge - ODBC;
  • PermGen is removed , the method for storing meta-data of classes is changed;
  • Ability to create profiles for the Java SE platform, which include not the entire platform, but some part of it;
  • Tools
    • Added utility jjs for using JavaScript Nashorn;
    • The command java can run JavaFX applications;
    • Added utility jdeps for analyzing .class files.

Q. What is Nashorn?

Nashorn is a JavaScript engine developed in Java by Oracle. Designed to provide the ability to embed JavaScript code in Java applications. Compared to Rhino , which is supported by the Mozilla Foundation, Nashorn provides 2 to 10 times better performance, as it compiles code and transfers bytecode to the Java virtual machine directly in memory. Nashorn can compile JavaScript code and generate Java classes that are loaded with a special loader. It is also possible to call Java code directly from JavaScript.

Q. What is jjs?

jjs - This is a command line utility that allows you to execute JavaScript programs directly in the console.

Q. In Java, How many ways you can take input from the console?

In Java, there are three different ways for reading input from the user in the command line environment ( console ).

1. Using Buffered Reader Class:

This method is used by wrapping the System.in ( standard input stream ) in an InputStreamReader which is wrapped in a BufferedReader, we can read input from the user in the command line.

java
/**
 * Buffered Reader Class
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Test {
    public static void main(String[] args) throws IOException {
        // Enter data using BufferReader
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        // Reading data using readLine
        String name = reader.readLine();

        // Printing the read line
        System.out.println(name);
    }
}

2. Using Scanner Class:

The main purpose of the Scanner class is to parse primitive types and strings using regular expressions, however it is also can be used to read input from the user in the command line.

java
/**
 * Scanner Class
 */
import java.util.Scanner;

class GetInputFromUser {
    public static void main(String args[]) {
        // Using Scanner for Getting Input from User
        Scanner in = new Scanner(System.in);

        String s = in.nextLine();
        System.out.println("You entered string " + s);

        int a = in.nextInt();
        System.out.println("You entered integer " + a);

        float b = in.nextFloat();
        System.out.println("You entered float " + b);
    }
}

3. Using Console Class:

It has been becoming a preferred way for reading user's input from the command line. In addition, it can be used for reading password-like input without echoing the characters entered by the user; the format string syntax can also be used ( like System.out.printf() ).

java
/**
 * Console Class
 */
public class Sample {
    public static void main(String[] args) {
        // Using Console to input data from user
        String name = System.console().readLine();
        System.out.println(name);
    }
}

Q. What is the purpose of using javap?

The javap command displays information about the fields, constructors and methods present in a class file. The javap command ( also known as the Java Disassembler ) disassembles one or more class files.

java
/**
 * Java Disassembler
 */
class Simple {
   public static void main(String args[]) {
       System.out.println("Hello World");
   }
}
cmd
cmd> javap Simple.class  

Output

java
Compiled from ".java"  
class Simple {  
  Simple();  
  public static void main(java.lang.String[]);  
}  

Q. Explain the expression System.out::println?

The specified expression illustrates passing a reference to a static method of a println()class System.out.

Q. Tell us about parallel processing in Java 8?

Streams can be sequential and parallel. Operations on sequential streams are performed in one processor thread, on parallel streams - using several processor threads. Parallel streams use the shared stream ForkJoinPoolthrough the static ForkJoinPool.commonPool()method. In this case, if the environment is not multi-core, then the stream will be executed as sequential. In fact, the use of parallel streams is reduced to the fact that the data in the streams will be divided into parts, each part is processed on a separate processor core, and in the end these parts are connected, and final operations are performed on them.

You can also use the parallelStream()interface method to create a parallel stream from the collection Collection.

To make a regular sequential stream parallel, you must call the Streammethod on the object parallel(). The method isParallel()allows you to find out if the stream is parallel.

Using, methods parallel()and sequential()it is possible to determine which operations can be parallel, and which only sequential. You can also make a parallel stream from any sequential stream and vice versa:

java
collection
  .stream ()
  .peek ( ... ) // operation is sequential
  .parallel ()
  .map ( ... ) // the operation can be performed in parallel,
  .sequential ()
  .reduce ( ... ) // operation is sequential again

As a rule, elements are transferred to the stream in the same order in which they are defined in the data source. When working with parallel streams, the system preserves the sequence of elements. An exception is a method forEach()that can output elements in random order. And in order to maintain the order, it is necessary to apply the method forEachOrdered().

  • Criteria that may affect performance in parallel streams:
  • Data size - the more data, the more difficult it is to separate the data first, and then combine them.
  • The number of processor cores. Theoretically, the more cores in a computer, the faster the program will work. If the machine has one core, it makes no sense to use parallel threads.
  • The simpler the data structure the stream works with, the faster operations will occur. For example, data from is ArrayListeasy to use, since the structure of this collection assumes a sequence of unrelated data. But a type collection LinkedListis not the best option, since in a sequential list all the elements are connected with previous / next. And such data is difficult to parallelize.
  • Operations with primitive types will be faster than with class objects.
  • It is highly recommended that you do not use parallel streams for any long operations (for example, network connections), since all parallel streams work with one ForkJoinPool, such long operations can stop all parallel streams in the JVM due to the lack of available threads in the pool, etc. e. parallel streams should be used only for short operations where the count goes for milliseconds, but not for those where the count can go for seconds and minutes;
  • Saving order in parallel streams increases execution costs, and if order is not important, it is possible to disable its saving and thereby increase productivity by using an intermediate operation unordered():
java
collection.parallelStream ()
    .sorted ()
    .unordered ()
    .collect ( Collectors . toList ());

# 2. JAVA ARCHITECTURE


Q. What is JVM and is it platform independent?

Java Virtual Machine (JVM) is a specification that provides runtime environment in which java bytecode(.class files) can be executed. The JVM is the platform. The JVM acts as a "virtual" machine or processor. Java's platform independence consists mostly of its Java Virtual Machine (JVM). JVM makes this possible because it is aware of the specific instruction lengths and other particularities of the platform (Operating System).

The JVM is not platform independent. Java Virtual Machine (JVM) provides the environment to execute the java file(. Class file). So at the end it's depends on kernel and kernel is differ from OS (Operating System) to OS. The JVM is used to both translate the bytecode into the machine language for a particular computer and actually execute the corresponding machine-language instructions as well.

Q. What is JIT compiler in Java?

The Just-In-Time (JIT) compiler is a component of the runtime environment that improves the performance of Java applications by compiling bytecodes to native machine code at run time.

Java programs consists of classes, which contain platform-neutral bytecodes that can be interpreted by a JVM on many different computer architectures. At run time, the JVM loads the class files, determines the semantics of each individual bytecode, and performs the appropriate computation. The additional processor and memory usage during interpretation means that a Java application performs more slowly than a native application. The JIT compiler helps improve the performance of Java programs by compiling

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javacollectionsdesign-patternhibernatejava

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category设计协作
PricingOpen source

> Related tools

F
Figma
协作式界面设计工具
S
sketch-wakatime
Sketch plugin for automatic time tracking and metrics generated from your Sketch usage.
Q
QuickColor
Quickly apply fills from the global or document color palettes to selected elements - 🎨